mirror of
https://github.com/jech/galene.git
synced 2024-11-09 10:15:58 +01:00
Implement contextual menu for chat entries.
Double-click, because otherwise it interferes with selection.
This commit is contained in:
parent
c2260c50db
commit
e68ff86287
2 changed files with 45 additions and 0 deletions
4
README
4
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
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue