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