From e68ff8628749c1767f9744ce6a208da6a068a85a Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Thu, 2 May 2024 00:39:44 +0200 Subject: [PATCH] Implement contextual menu for chat entries. Double-click, because otherwise it interferes with selection. --- README | 4 ++++ static/galene.js | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/README b/README index 00f46fc5..f34f226b 100644 --- a/README +++ b/README @@ -50,6 +50,10 @@ There is a user list on the left. Clicking on a user opens a menu with actions that can be applied to that user. Clicking on ones own username opens a menu with actions that are global to the group. +### Chat pane + +Double-clicking on a message opens a contextual menu. + ### Text box Typing a string in the text box at the bottom of the chat pane sends diff --git a/static/galene.js b/static/galene.js index d8fdb414..8678c977 100644 --- a/static/galene.js +++ b/static/galene.js @@ -2952,6 +2952,19 @@ function addToChatbox(peerId, dest, nick, time, privileged, history, kind, messa if(dest) container.classList.add('message-private'); + if(peerId) { + container.dataset.peerId = peerId; + container.dataset.username = nick; + container.addEventListener('click', function(e) { + if(e.detail !== 2) + return; + let elt = e.currentTarget; + if(!elt || !(elt instanceof HTMLElement)) + throw new Error("Couldn't find chat message div"); + chatMessageMenu(elt); + }); + } + /** @type{HTMLElement} */ let body; if(message instanceof HTMLElement) { @@ -3027,6 +3040,34 @@ function addToChatbox(peerId, dest, nick, time, privileged, history, kind, messa return message; } +/** + * @param {HTMLElement} elt + */ +function chatMessageMenu(elt) { + if(!(serverConnection && serverConnection.permissions && + serverConnection.permissions.indexOf('op') >= 0)) + return; + + let peerId = elt.dataset.peerId; + if(!peerId) + return; + let username = elt.dataset.username; + let u = username ? ' ' + username : ''; + + let items = []; + items.push({label: 'Identify user' + u, onClick: () => { + serverConnection.userAction('identify', peerId); + }}); + items.push({label: 'Kick out user' + u, onClick: () => { + serverConnection.userAction('kick', peerId); + }}); + + /** @ts-ignore */ + new Contextual({ + items: items, + }); +} + /** * @param {string|HTMLElement} message */