From b527c8757a2f0456afe886b4cc155acef80b99b7 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sat, 31 Jul 2021 14:42:26 +0200 Subject: [PATCH] Add chathistory message. --- README.PROTOCOL | 4 ++++ rtpconn/webclient.go | 2 +- static/galene.js | 7 +++++-- static/protocol.js | 7 ++++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.PROTOCOL b/README.PROTOCOL index 6a0c19e..a0475af 100644 --- a/README.PROTOCOL +++ b/README.PROTOCOL @@ -277,6 +277,10 @@ if the message was originated by a client with the `op` permission. The field `noecho` is set by the client if it doesn't wish to receive a copy of its own message. +The `chathistory` message is similar to the `chat` message, but carries +a message taken from the chat history. Most clients should treat +`chathistory` similarly to `chat`. + A user message is similar to a chat message, but is not conserved in the chat history, and is not expected to contain user-visible content. diff --git a/rtpconn/webclient.go b/rtpconn/webclient.go index e11ff2e..6dfd3d6 100644 --- a/rtpconn/webclient.go +++ b/rtpconn/webclient.go @@ -1351,7 +1351,7 @@ func handleClientMessage(c *webClient, m clientMessage) error { h := c.group.GetChatHistory() for _, m := range h { err := c.write(clientMessage{ - Type: "chat", + Type: "chathistory", Id: m.Id, Username: m.User, Time: m.Time, diff --git a/static/galene.js b/static/galene.js index 7f5b937..d2bc9a7 100644 --- a/static/galene.js +++ b/static/galene.js @@ -2301,12 +2301,15 @@ let lastMessage = {}; /** * @param {string} peerId + * @param {string} dest * @param {string} nick * @param {number} time + * @param {boolean} privileged + * @param {boolean} history * @param {string} kind * @param {unknown} message */ -function addToChatbox(peerId, dest, nick, time, privileged, kind, message) { +function addToChatbox(peerId, dest, nick, time, privileged, history, kind, message) { let userpass = getUserPass(); let row = document.createElement('div'); row.classList.add('message-row'); @@ -2633,7 +2636,7 @@ commands.msg = { throw new Error(`Unknown user ${p[0]}`); serverConnection.chat('', id, p[1]); addToChatbox(serverConnection.id, id, serverConnection.username, - Date.now(), false, '', p[1]); + Date.now(), false, false, '', p[1]); } }; diff --git a/static/protocol.js b/static/protocol.js index f4f5ac4..54ca3fe 100644 --- a/static/protocol.js +++ b/static/protocol.js @@ -178,7 +178,7 @@ function ServerConnection() { /** * onchat is called whenever a new chat message is received. * - * @type {(this: ServerConnection, id: string, dest: string, username: string, time: number, privileged: boolean, kind: string, message: unknown) => void} + * @type {(this: ServerConnection, id: string, dest: string, username: string, time: number, privileged: boolean, history: boolean, kind: string, message: unknown) => void} */ this.onchat = null; /** @@ -379,10 +379,11 @@ ServerConnection.prototype.connect = async function(url) { sc.onuser.call(sc, m.id, m.kind); break; case 'chat': + case 'chathistory': if(sc.onchat) sc.onchat.call( - sc, m.source, m.dest, m.username, m.time, - m.privileged, m.kind, m.value, + sc, m.source, m.dest, m.username, m.time, m.privileged, + m.type === 'chathistory', m.kind, m.value, ); break; case 'usermessage':