@ -153,19 +153,6 @@ setInterval(() => {
} ) ;
} ) ;
} , 10000 ) ;
} , 10000 ) ;
const elemCanvas = ( text ) => {
const canvas = elem ( 'canvas' , { height : 80 , width : 80 } ) ;
const context = canvas . getContext ( '2d' ) ;
context . fillStyle = ` # ${ text . slice ( 0 , 6 ) } ` ;
context . fillRect ( 0 , 0 , 80 , 80 ) ;
context . fillStyle = '#111' ;
context . fillRect ( 0 , 50 , 80 , 32 ) ;
context . font = 'bold 18px monospace' ;
context . fillText ( text , 2 , 46 ) ;
return canvas ;
}
function createTextNote ( evt , relay ) {
function createTextNote ( evt , relay ) {
const { host , img , isReply , name , replies , time , userName } = getMetadata ( evt , relay ) ;
const { host , img , isReply , name , replies , time , userName } = getMetadata ( evt , relay ) ;
const isLongContent = evt . content . trimRight ( ) . length > 280 ;
const isLongContent = evt . content . trimRight ( ) . length > 280 ;
@ -210,7 +197,7 @@ function createTextNote(evt, relay) {
requestAnimationFrame ( ( ) => updateElemHeight ( writeInput ) ) ;
requestAnimationFrame ( ( ) => updateElemHeight ( writeInput ) ) ;
}
}
return rendernArticle ( [
return rendernArticle ( [
elem ( 'div' , { className : 'mbox-img' } , [ ( name && img ) ? img : elemCanvas ( userName ) ] ) , body ,
elem ( 'div' , { className : 'mbox-img' } , [ img ] ) , body ,
replies [ 0 ] ? elem ( 'div' , { className : 'mobx-replies' } , replyFeed . reverse ( ) ) : '' ,
replies [ 0 ] ? elem ( 'div' , { className : 'mobx-replies' } , replyFeed . reverse ( ) ) : '' ,
] ) ;
] ) ;
}
}
@ -310,8 +297,8 @@ function renderRecommendServer(evt, relay) {
] ) ,
] ) ,
` recommends server: ${ evt . content } ` ,
` recommends server: ${ evt . content } ` ,
] ) ;
] ) ;
return rendernArticle ( [ elem ( 'div' , { className : 'mbox-img' } , [
return rendernArticle ( [
( name && img ) ? img : elemCanvas ( userName ) ] ) , body
elem ( 'div' , { className : 'mbox-img' } , [ img ] ) , body
] , { className : 'mbox-recommend-server' , data : { relay : evt . content } } ) ;
] , { className : 'mbox-recommend-server' , data : { relay : evt . content } } ) ;
}
}
@ -387,6 +374,22 @@ const getHost = (url) => {
}
}
}
}
const elemCanvas = ( text ) => {
const canvas = elem ( 'canvas' , { height : 80 , width : 80 } ) ;
const context = canvas . getContext ( '2d' ) ;
const color = ` # ${ text . slice ( 0 , 6 ) } ` ;
context . fillStyle = color ;
context . fillRect ( 0 , 0 , 80 , 80 ) ;
context . fillStyle = '#111' ;
context . fillRect ( 0 , 50 , 80 , 32 ) ;
context . font = 'bold 18px monospace' ;
if ( color === '#000000' ) {
context . fillStyle = '#fff' ;
}
context . fillText ( text , 2 , 46 ) ;
return canvas ;
}
function getMetadata ( evt , relay ) {
function getMetadata ( evt , relay ) {
const host = getHost ( relay ) ;
const host = getHost ( relay ) ;
const user = userList . find ( user => user . pubkey === evt . pubkey ) ;
const user = userList . find ( user => user . pubkey === evt . pubkey ) ;
@ -394,11 +397,11 @@ function getMetadata(evt, relay) {
const name = user ? . metadata [ relay ] ? . name ;
const name = user ? . metadata [ relay ] ? . name ;
const userName = name || evt . pubkey . slice ( 0 , 8 ) ;
const userName = name || evt . pubkey . slice ( 0 , 8 ) ;
const userAbout = user ? . metadata [ relay ] ? . about || '' ;
const userAbout = user ? . metadata [ relay ] ? . about || '' ;
const img = elem( 'img' , {
const img = userImg ? elem( 'img' , {
src : userImg ,
src : userImg ,
alt : ` ${ userName } ${ host } ` ,
alt : ` ${ userName } ${ host } ` ,
title : ` ${ userName } on ${ host } ${ userAbout } ` ,
title : ` ${ userName } on ${ host } ${ userAbout } ` ,
} , '' ) ;
} ) : elemCanvas ( evt . pubkey ) ;
const isReply = evt . tags . some ( hasEventTag ) ;
const isReply = evt . tags . some ( hasEventTag ) ;
const replies = replyList . filter ( ( reply ) => reply . tags [ 0 ] [ 1 ] === evt . id ) ;
const replies = replyList . filter ( ( reply ) => reply . tags [ 0 ] [ 1 ] === evt . id ) ;
const time = new Date ( evt . created _at * 1000 ) ;
const time = new Date ( evt . created _at * 1000 ) ;