//timestamp will only show when first message
if(lastMessage=== undefined
//or when different day than last message
|| messageDate !== lastTimeStampDate
//or when today's message and more than 2 mins from last message
||(messageDate === today && messageTime >= (parseInt(lastTimeStampTime) + 2))){
if(messageDate === today){
return moment(time).format("HH:mm");
//yesterday's message
}else if((today - messageDate) === 1){
let clock = moment(time).format("HH:mm");
return "Yesterday " + clock;
//same year message
}else if(today.slice(0,5) === messageDate.slice(0,5)){
return moment(time).format("MMM DD, HH:mm");
//different year message
}else{
return moment(time).format("YYYY-MM-DD, HH:mm");
}
}else{
return "";
}