1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-14 04:35:57 +01:00

Implement contextual menu for chat entries.

Double-click, because otherwise it interferes with selection.
This commit is contained in:
Juliusz Chroboczek 2024-05-02 00:39:44 +02:00
parent c2260c50db
commit e68ff86287
2 changed files with 45 additions and 0 deletions

4
README
View file

@ -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 actions that can be applied to that user. Clicking on ones own username
opens a menu with actions that are global to the group. opens a menu with actions that are global to the group.
### Chat pane
Double-clicking on a message opens a contextual menu.
### Text box ### Text box
Typing a string in the text box at the bottom of the chat pane sends Typing a string in the text box at the bottom of the chat pane sends

View file

@ -2952,6 +2952,19 @@ function addToChatbox(peerId, dest, nick, time, privileged, history, kind, messa
if(dest) if(dest)
container.classList.add('message-private'); 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} */ /** @type{HTMLElement} */
let body; let body;
if(message instanceof HTMLElement) { if(message instanceof HTMLElement) {
@ -3027,6 +3040,34 @@ function addToChatbox(peerId, dest, nick, time, privileged, history, kind, messa
return message; 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 * @param {string|HTMLElement} message
*/ */