Skip to content

Commit

Permalink
Implement contextual menu for chat entries.
Browse files Browse the repository at this point in the history
Double-click, because otherwise it interferes with selection.
  • Loading branch information
jech committed May 1, 2024
1 parent c2260c5 commit e68ff86
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions static/galene.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit e68ff86

Please sign in to comment.