Change timestamps to only show on chat and action messages

closes #73
This commit is contained in:
joeyak 2019-04-11 21:50:20 -04:00
parent adcc81f192
commit 176aad5b3c
1 changed files with 9 additions and 5 deletions

View File

@ -71,7 +71,15 @@ func recieve(v []js.Value) {
// on join or leave, update list of possible user names
fallthrough
case common.DTChat:
appendMessage(chat.Data.HTML())
msg := chat.Data.HTML()
if d, ok := chat.Data.(common.DataMessage); ok {
if timestamp && (d.Type == common.MsgChat || d.Type == common.MsgAction) {
h, m, _ := time.Now().Clock()
msg = fmt.Sprintf(`<span class="time">%02d:%02d</span> %s`, h, m, msg)
}
}
appendMessage(msg)
case common.DTCommand:
d := chat.Data.(common.DataCommand)
@ -103,10 +111,6 @@ func recieve(v []js.Value) {
}
func appendMessage(msg string) {
if timestamp {
h, m, _ := time.Now().Clock()
msg = fmt.Sprintf(`<span class="time">%02d:%02d</span> %s`, h, m, msg)
}
js.Call("appendMessages", "<div>"+msg+"</div>")
}