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

Include username and id in group and user actions.

This commit is contained in:
Juliusz Chroboczek 2020-11-30 15:36:59 +01:00
parent 74b3683cf1
commit aa71205fa2
2 changed files with 18 additions and 11 deletions

View file

@ -451,15 +451,17 @@ ServerConnection.prototype.chat = function(username, kind, dest, value) {
/** /**
* userAction sends a request to act on a user. * userAction sends a request to act on a user.
* *
* @param {string} username - The sender's username.
* @param {string} kind - One of "op", "unop", "kick", "present", "unpresent". * @param {string} kind - One of "op", "unop", "kick", "present", "unpresent".
* @param {string} dest - The id of the user to act upon. * @param {string} dest - The id of the user to act upon.
* @param {string} [value] - An optional user-readable message. * @param {string} [value] - An optional user-readable message.
*/ */
ServerConnection.prototype.userAction = function(kind, dest, value) { ServerConnection.prototype.userAction = function(username, kind, dest, value) {
this.send({ this.send({
type: 'useraction', type: 'useraction',
id: this.id, id: this.id,
dest: dest, dest: dest,
username: username,
kind: kind, kind: kind,
value: value, value: value,
}); });
@ -468,15 +470,17 @@ ServerConnection.prototype.userAction = function(kind, dest, value) {
/** /**
* userMessage sends an application-specific message to a user. * userMessage sends an application-specific message to a user.
* *
* @param {string} username - The sender's username.
* @param {string} kind - The kind of application-specific message. * @param {string} kind - The kind of application-specific message.
* @param {string} dest - The id of the user to send the message to. * @param {string} dest - The id of the user to send the message to.
* @param {string} [value] - An optional parameter. * @param {string} [value] - An optional parameter.
*/ */
ServerConnection.prototype.userMessage = function(kind, dest, value) { ServerConnection.prototype.userMessage = function(username, kind, dest, value) {
this.send({ this.send({
type: 'usermessage', type: 'usermessage',
id: this.id, id: this.id,
dest: dest, dest: dest,
username: username,
kind: kind, kind: kind,
value: value, value: value,
}); });
@ -485,14 +489,17 @@ ServerConnection.prototype.userMessage = function(kind, dest, value) {
/** /**
* groupAction sends a request to act on the current group. * groupAction sends a request to act on the current group.
* *
* @param {string} username - The sender's username.
* @param {string} kind - One of "clearchat", "lock", "unlock", "record or * @param {string} kind - One of "clearchat", "lock", "unlock", "record or
* "unrecord". * "unrecord".
* @param {string} [message] - An optional user-readable message. * @param {string} [message] - An optional user-readable message.
*/ */
ServerConnection.prototype.groupAction = function(kind, message) { ServerConnection.prototype.groupAction = function(username, kind, message) {
this.send({ this.send({
type: 'groupaction', type: 'groupaction',
id: this.id,
kind: kind, kind: kind,
username: username,
value: message, value: message,
}); });
}; };

View file

@ -1660,7 +1660,7 @@ commands.clear = {
predicate: operatorPredicate, predicate: operatorPredicate,
description: 'clear the chat history', description: 'clear the chat history',
f: (c, r) => { f: (c, r) => {
serverConnection.groupAction('clearchat'); serverConnection.groupAction(getUsername(), 'clearchat');
} }
}; };
@ -1669,7 +1669,7 @@ commands.lock = {
description: 'lock this group', description: 'lock this group',
parameters: '[message]', parameters: '[message]',
f: (c, r) => { f: (c, r) => {
serverConnection.groupAction('lock', r); serverConnection.groupAction(getUsername(), 'lock', r);
} }
}; };
@ -1677,7 +1677,7 @@ commands.unlock = {
predicate: operatorPredicate, predicate: operatorPredicate,
description: 'unlock this group, revert the effect of /lock', description: 'unlock this group, revert the effect of /lock',
f: (c, r) => { f: (c, r) => {
serverConnection.groupAction('unlock'); serverConnection.groupAction(getUsername(), 'unlock');
} }
}; };
@ -1685,7 +1685,7 @@ commands.record = {
predicate: recordingPredicate, predicate: recordingPredicate,
description: 'start recording', description: 'start recording',
f: (c, r) => { f: (c, r) => {
serverConnection.groupAction('record'); serverConnection.groupAction(getUsername(), 'record');
} }
}; };
@ -1693,7 +1693,7 @@ commands.unrecord = {
predicate: recordingPredicate, predicate: recordingPredicate,
description: 'stop recording', description: 'stop recording',
f: (c, r) => { f: (c, r) => {
serverConnection.groupAction('unrecord'); serverConnection.groupAction(getUsername(), 'unrecord');
} }
}; };
@ -1773,7 +1773,7 @@ function userCommand(c, r) {
let id = findUserId(p[0]); let id = findUserId(p[0]);
if(!id) if(!id)
throw new Error(`Unknown user ${p[0]}`); throw new Error(`Unknown user ${p[0]}`);
serverConnection.userAction(c, id, p[1]); serverConnection.userAction(getUsername(), c, id, p[1]);
} }
function userMessage(c, r) { function userMessage(c, r) {
@ -1783,7 +1783,7 @@ function userMessage(c, r) {
let id = findUserId(p[0]); let id = findUserId(p[0]);
if(!id) if(!id)
throw new Error(`Unknown user ${p[0]}`); throw new Error(`Unknown user ${p[0]}`);
serverConnection.userMessage(c, id, p[1]); serverConnection.userMessage(getUsername(), c, id, p[1]);
} }
commands.kick = { commands.kick = {
@ -2108,11 +2108,11 @@ async function serverConnect() {
serverConnection.onchat = addToChatbox; serverConnection.onchat = addToChatbox;
serverConnection.onclearchat = clearChat; serverConnection.onclearchat = clearChat;
serverConnection.onusermessage = function(id, dest, username, time, priviledged, kind, message) { serverConnection.onusermessage = function(id, dest, username, time, priviledged, kind, message) {
let from = id ? (username || 'Anonymous') : 'The Server';
switch(kind) { switch(kind) {
case 'error': case 'error':
case 'warning': case 'warning':
case 'info': case 'info':
let from = id ? (username || 'Anonymous') : 'The Server';
if(priviledged) if(priviledged)
displayError(`${from} said: ${message}`, kind); displayError(`${from} said: ${message}`, kind);
else else