diff --git a/group/group.go b/group/group.go index ebcdcc5..c17e893 100644 --- a/group/group.go +++ b/group/group.go @@ -74,11 +74,12 @@ func (err ProtocolError) Error() string { } type ChatHistoryEntry struct { - Id string - User *string - Time time.Time - Kind string - Value interface{} + Id string + Source string + User *string + Time time.Time + Kind string + Value interface{} } const ( @@ -804,7 +805,7 @@ func (g *Group) ClearChatHistory() { g.history = nil } -func (g *Group) AddToChatHistory(id string, user *string, time time.Time, kind string, value interface{}) { +func (g *Group) AddToChatHistory(id, source string, user *string, time time.Time, kind string, value interface{}) { g.mu.Lock() defer g.mu.Unlock() @@ -813,7 +814,7 @@ func (g *Group) AddToChatHistory(id string, user *string, time time.Time, kind s g.history = g.history[:len(g.history)-1] } g.history = append(g.history, - ChatHistoryEntry{Id: id, User: user, Time: time, Kind: kind, Value: value}, + ChatHistoryEntry{Id: id, Source: source, User: user, Time: time, Kind: kind, Value: value}, ) } diff --git a/group/group_test.go b/group/group_test.go index 977fa19..0368d53 100644 --- a/group/group_test.go +++ b/group/group_test.go @@ -54,7 +54,7 @@ func TestChatHistory(t *testing.T) { } user := "user" for i := 0; i < 2*maxChatHistory; i++ { - g.AddToChatHistory("id", &user, time.Now(), "", + g.AddToChatHistory("id", "source", &user, time.Now(), "", fmt.Sprintf("%v", i), ) } diff --git a/rtpconn/webclient.go b/rtpconn/webclient.go index 67f5375..a606418 100644 --- a/rtpconn/webclient.go +++ b/rtpconn/webclient.go @@ -1197,7 +1197,8 @@ func handleAction(c *webClient, a any) error { for _, m := range h { err := c.write(clientMessage{ Type: "chathistory", - Source: m.Id, + Id: m.Id, + Source: m.Source, Username: m.User, Time: m.Time.Format(time.RFC3339), Value: m.Value, @@ -1575,17 +1576,25 @@ func handleClientMessage(c *webClient, m clientMessage) error { return c.error(group.UserError("not authorised")) } - now := time.Now() + id := m.Id + if m.Type == "chat" && m.Dest == "" && id == "" { + buf := make([]byte, 8) + crand.Read(buf) + id = base64.RawURLEncoding.EncodeToString(buf) + } + now := time.Now() if m.Type == "chat" { if m.Dest == "" { g.AddToChatHistory( - m.Source, m.Username, now, m.Kind, m.Value, + id, m.Source, m.Username, + now, m.Kind, m.Value, ) } } mm := clientMessage{ Type: m.Type, + Id: id, Source: m.Source, Dest: m.Dest, Username: m.Username, @@ -1891,15 +1900,15 @@ func handleClientMessage(c *webClient, m clientMessage) error { } w, ok := d.(warner) if ok { - w.Warn(false, "Your IP address has been " + - "communicated to user " + - c.Username() + ".") + w.Warn(false, "Your IP address has been "+ + "communicated to user "+ + c.Username()+".") } c.write(clientMessage{ - Type: "usermessage", - Kind: "userinfo", + Type: "usermessage", + Kind: "userinfo", Privileged: true, - Value: value, + Value: value, }) case "kick": if !member("op", c.permissions) { diff --git a/static/galene.js b/static/galene.js index 7c21c40..12d1d46 100644 --- a/static/galene.js +++ b/static/galene.js @@ -2958,7 +2958,7 @@ let lastMessage = {}; * @param {string} kind * @param {string|HTMLElement} message */ -function addToChatbox(peerId, dest, nick, time, privileged, history, kind, message) { +function addToChatbox(id, peerId, dest, nick, time, privileged, history, kind, message) { let row = document.createElement('div'); row.classList.add('message-row'); let container = document.createElement('div'); @@ -2973,6 +2973,8 @@ function addToChatbox(peerId, dest, nick, time, privileged, history, kind, messa if(dest) container.classList.add('message-private'); + if(id) + container.dataset.id = id; if(peerId) { container.dataset.peerId = peerId; container.dataset.username = nick; @@ -3093,7 +3095,7 @@ function chatMessageMenu(elt) { * @param {string|HTMLElement} message */ function localMessage(message) { - return addToChatbox(null, null, null, new Date(), false, false, '', message); + return addToChatbox(null, null, null, null, new Date(), false, false, '', message); } function clearChat() { @@ -3473,7 +3475,7 @@ commands.msg = { if(!id) throw new Error(`Unknown user ${p[0]}`); serverConnection.chat('', id, p[1]); - addToChatbox(serverConnection.id, id, serverConnection.username, + addToChatbox(serverConnection.id, null, id, serverConnection.username, new Date(), false, false, '', p[1]); } }; diff --git a/static/protocol.js b/static/protocol.js index 7f90e4e..67fb68e 100644 --- a/static/protocol.js +++ b/static/protocol.js @@ -212,7 +212,7 @@ function ServerConnection() { /** * onchat is called whenever a new chat message is received. * - * @type {(this: ServerConnection, id: string, dest: string, username: string, time: Date, privileged: boolean, history: boolean, kind: string, message: string) => void} + * @type {(this: ServerConnection, id: string, source: string, dest: string, username: string, time: Date, privileged: boolean, history: boolean, kind: string, message: string) => void} */ this.onchat = null; /** @@ -497,7 +497,7 @@ ServerConnection.prototype.connect = function(url) { case 'chathistory': if(sc.onchat) sc.onchat.call( - sc, m.source, m.dest, m.username, parseTime(m.time), + sc, m.id, m.source, m.dest, m.username, parseTime(m.time), m.privileged, m.type === 'chathistory', m.kind, '' + m.value, );