in chatApp class, the order of code should be:
class ChatApp {
constructor() {
let userStore = new UserStore(‘x-chattrbox/u’);
let username = userStore.get();
if(!username){
//username = promptForUsername();
userStore.set(username);
}
this.chatForm = new ChatForm(FORM_SELECTOR,INPUT_SELECTOR);
this.chatList = new ChatList(LIST_SELECTOR,username);
let messageStore = new MessageStore('x-chattrbox/m');
let messageListString = messageStore.get();
in class chatMessage:
class ChatMessage {
constructor({message:m,user:u=‘batman’,timestamp:t=(new Date()).getTime()}) {
this.message = m;
this.user = u;
this.timestamp = t;
}
the u cant change to username
in drawMessage,should add some code:
drawMessage({user:u,timestamp:t,message:m}){
let messageRow = (’
if(this.username === u){
$messageRow.removeClass();
$messageRow.addClass(‘me’);
}
let message = (’
’);
message.append((’’,{‘class’:‘message-username’,text:u}));
message.append((’’,{‘class’:‘timestamp’,‘data-time’:t,text:moment(t).fromNow()}));
message.append((’’,{‘class’:‘message-message’,text:m}));
let $img = $('<img>',{src:createGravatorUrl(u)});
if(this.username === u){
$messageRow.append($message);
$messageRow.append($img);
this.$list.append($messageRow);
}else{
$messageRow.append($img);
$messageRow.append($message);
this.$list.append($messageRow);
}