@ -3,7 +3,6 @@ import htm from '/js/web_modules/htm.js';
@@ -3,7 +3,6 @@ import htm from '/js/web_modules/htm.js';
const html = htm . bind ( h ) ;
import { messageBubbleColorForString } from '../../utils/user-colors.js' ;
import { generateAvatar } from '../../utils/helpers.js' ;
import { convertToText } from '../../utils/chat.js' ;
import { SOCKET _MESSAGE _TYPES } from '../../utils/websocket.js' ;
@ -12,23 +11,15 @@ export default class Message extends Component {
@@ -12,23 +11,15 @@ export default class Message extends Component {
const { message , username } = props ;
const { type } = message ;
if ( type === SOCKET _MESSAGE _TYPES . CHAT ) {
const { image , author , body , timestamp } = message ;
const { author , body , timestamp } = message ;
const formattedMessage = formatMessageText ( body , username ) ;
const avatar = image || generateAvatar ( author ) ;
const formattedTimestamp = formatTimestamp ( timestamp ) ;
const authorColor = messageBubbleColorForString ( author ) ;
const avatarBgColor = { backgroundColor : authorColor } ;
const authorTextColor = { color : authorColor } ;
return (
html `
< div class = "message flex flex-row items-start p-3" >
< div
class = "message-avatar rounded-full flex items-center justify-center mr-3"
style = $ { avatarBgColor }
>
< img src = $ { avatar } class = "p-1" / >
< / d i v >
< div class = "message-content text-sm break-words w-full" >
< div class = "message-author text-white font-bold" style = $ { authorTextColor } >
$ { author }
@ -44,17 +35,11 @@ export default class Message extends Component {
@@ -44,17 +35,11 @@ export default class Message extends Component {
< / d i v >
` );
} else if ( type === SOCKET _MESSAGE _TYPES . NAME _CHANGE ) {
const { oldName , newName , image } = message ;
const { oldName , newName } = message ;
return (
html `
< div class = "message message-name-change flex items-center justify-start p-3" >
< div class = "message-content flex flex-row items-center justify-center text-sm w-full" >
< div
class = "message-avatar rounded-full mr-3 bg-gray-900"
>
< img class = "mr-2 p-1" src = $ { image } / >
< / d i v >
< div class = "text-white text-center opacity-50" >
< span class = "font-bold" > $ { oldName } < / s p a n > i s n o w k n o w n a s < s p a n c l a s s = " f o n t - b o l d " > $ { n e w N a m e } < / s p a n > .
< / d i v >