mirror of
https://github.com/jech/galene.git
synced 2024-12-22 23:35:46 +01:00
Implement user-readable message for kick.
This commit is contained in:
parent
5c97e739a6
commit
7707775cca
4 changed files with 30 additions and 13 deletions
4
group.go
4
group.go
|
@ -64,7 +64,9 @@ type connectionFailedAction struct {
|
|||
|
||||
type permissionsChangedAction struct{}
|
||||
|
||||
type kickAction struct{}
|
||||
type kickAction struct{
|
||||
message string
|
||||
}
|
||||
|
||||
var groups struct {
|
||||
mu sync.Mutex
|
||||
|
|
|
@ -437,12 +437,14 @@ ServerConnection.prototype.groupAction = function(kind) {
|
|||
*
|
||||
* @param {string} kind - One of "op", "unop", "kick", "present", "unpresent".
|
||||
* @param {string} id
|
||||
* @param {string} [message]
|
||||
*/
|
||||
ServerConnection.prototype.userAction = function(kind, id) {
|
||||
ServerConnection.prototype.userAction = function(kind, id, message) {
|
||||
this.send({
|
||||
type: 'useraction',
|
||||
kind: kind,
|
||||
id: id,
|
||||
value: message,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -955,14 +955,14 @@ function handleInput() {
|
|||
message = data.substring(1);
|
||||
me = false;
|
||||
} else {
|
||||
let space, cmd, rest;
|
||||
space = data.indexOf(' ');
|
||||
let cmd, rest;
|
||||
let space = data.indexOf(' ');
|
||||
if(space < 0) {
|
||||
cmd = data;
|
||||
rest = '';
|
||||
} else {
|
||||
cmd = data.slice(0, space);
|
||||
rest = data.slice(space + 1).trim();
|
||||
rest = data.slice(space + 1);
|
||||
}
|
||||
|
||||
switch(cmd) {
|
||||
|
@ -1005,22 +1005,31 @@ function handleInput() {
|
|||
displayError("You're not an operator");
|
||||
return;
|
||||
}
|
||||
let username, message;
|
||||
let space = rest.indexOf(' ');
|
||||
if(space < 0) {
|
||||
username = rest;
|
||||
message = null;
|
||||
} else {
|
||||
username = rest.slice(0, space);
|
||||
message = rest.slice(space + 1).trim();
|
||||
}
|
||||
let id;
|
||||
if(rest in users) {
|
||||
if(username in users) {
|
||||
id = rest;
|
||||
} else {
|
||||
for(let i in users) {
|
||||
if(users[i] === rest) {
|
||||
if(users[i] === username) {
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!id) {
|
||||
displayError('Unknown user ' + rest);
|
||||
displayError('Unknown user ' + username);
|
||||
return;
|
||||
}
|
||||
serverConnection.userAction(cmd.slice(1), id)
|
||||
serverConnection.userAction(cmd.slice(1), id, message);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
|
|
12
webclient.go
12
webclient.go
|
@ -870,7 +870,7 @@ func clientLoop(c *webClient, conn *websocket.Conn) error {
|
|||
}
|
||||
}
|
||||
case kickAction:
|
||||
return userError("you have been kicked")
|
||||
return userError(a.message)
|
||||
default:
|
||||
log.Printf("unexpected action %T", a)
|
||||
return errors.New("unexpected action")
|
||||
|
@ -943,7 +943,7 @@ func setPermissions(g *group, id string, perm string) error {
|
|||
return c.action(permissionsChangedAction{})
|
||||
}
|
||||
|
||||
func kickClient(g *group, id string) error {
|
||||
func kickClient(g *group, id string, message string) error {
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
|
||||
|
@ -957,7 +957,7 @@ func kickClient(g *group, id string) error {
|
|||
return userError("this is not a real user")
|
||||
}
|
||||
|
||||
return c.action(kickAction{})
|
||||
return c.action(kickAction{message})
|
||||
}
|
||||
|
||||
func handleClientMessage(c *webClient, m clientMessage) error {
|
||||
|
@ -1094,7 +1094,11 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
|||
if !c.permissions.Op {
|
||||
return c.error(userError("not authorised"))
|
||||
}
|
||||
err := kickClient(c.group, m.Id)
|
||||
message := m.Value
|
||||
if message == "" {
|
||||
message = "you have been kicked"
|
||||
}
|
||||
err := kickClient(c.group, m.Id, message)
|
||||
if err != nil {
|
||||
return c.error(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue