1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-23 00:55:58 +01:00

Restructure group and client management messages.

This commit is contained in:
Juliusz Chroboczek 2020-08-12 12:40:40 +02:00
parent 88d2a96819
commit 675035ab29
2 changed files with 78 additions and 64 deletions

View file

@ -1058,7 +1058,8 @@ function handleInput() {
return; return;
} }
send({ send({
type: 'clearchat', type: 'groupaction',
kind: 'clearchat',
}); });
return; return;
case '/lock': case '/lock':
@ -1068,7 +1069,8 @@ function handleInput() {
return; return;
} }
send({ send({
type: cmd.slice(1), type: 'groupaction',
kind: cmd.slice(1),
}); });
return; return;
case '/record': case '/record':
@ -1078,7 +1080,8 @@ function handleInput() {
return; return;
} }
send({ send({
type: cmd.slice(1), type: 'groupaction',
kind: cmd.slice(1),
}); });
return; return;
case '/op': case '/op':
@ -1106,7 +1109,8 @@ function handleInput() {
return; return;
} }
send({ send({
type: cmd.slice(1), type: 'useraction',
kind: cmd.slice(1),
id: id, id: id,
}); });
return; return;

View file

@ -1006,71 +1006,81 @@ func handleClientMessage(c *webClient, m clientMessage) error {
cc.write(m) cc.write(m)
} }
} }
case "clearchat": case "groupaction":
c.group.clearChatHistory() switch m.Kind {
m := clientMessage{Type: "clearchat"} case "clearchat":
clients := c.group.getClients(nil) c.group.clearChatHistory()
for _, cc := range clients { m := clientMessage{Type: "clearchat"}
cc, ok := cc.(*webClient) clients := c.group.getClients(nil)
if ok { for _, cc := range clients {
cc.write(m) cc, ok := cc.(*webClient)
if ok {
cc.write(m)
}
} }
} case "lock", "unlock":
case "op", "unop", "present", "unpresent": if !c.permissions.Op {
if !c.permissions.Op { return c.error(userError("not authorised"))
return c.error(userError("not authorised"))
}
err := setPermissions(c.group, m.Id, m.Type)
if err != nil {
return c.error(err)
}
case "lock", "unlock":
if !c.permissions.Op {
return c.error(userError("not authorised"))
}
var locked uint32
if m.Type == "lock" {
locked = 1
}
atomic.StoreUint32(&c.group.locked, locked)
case "record":
if !c.permissions.Record {
return c.error(userError("not authorised"))
}
for _, cc := range c.group.getClients(c) {
_, ok := cc.(*diskClient)
if ok {
return c.error(userError("already recording"))
} }
} var locked uint32
disk := &diskClient{ if m.Kind == "lock" {
group: c.group, locked = 1
id: "recording", }
} atomic.StoreUint32(&c.group.locked, locked)
_, err := addClient(c.group.name, disk) case "record":
if err != nil { if !c.permissions.Record {
disk.Close() return c.error(userError("not authorised"))
return c.error(err) }
} for _, cc := range c.group.getClients(c) {
go pushConns(disk) _, ok := cc.(*diskClient)
case "unrecord": if ok {
if !c.permissions.Record { return c.error(userError("already recording"))
return c.error(userError("not authorised")) }
} }
for _, cc := range c.group.getClients(c) { disk := &diskClient{
disk, ok := cc.(*diskClient) group: c.group,
if ok { id: "recording",
}
_, err := addClient(c.group.name, disk)
if err != nil {
disk.Close() disk.Close()
delClient(disk) return c.error(err)
} }
go pushConns(disk)
case "unrecord":
if !c.permissions.Record {
return c.error(userError("not authorised"))
}
for _, cc := range c.group.getClients(c) {
disk, ok := cc.(*diskClient)
if ok {
disk.Close()
delClient(disk)
}
}
default:
return protocolError("unknown group action")
} }
case "kick": case "useraction":
if !c.permissions.Op { switch m.Kind {
return c.error(userError("not authorised")) case "op", "unop", "present", "unpresent":
} if !c.permissions.Op {
err := kickClient(c.group, m.Id) return c.error(userError("not authorised"))
if err != nil { }
return c.error(err) err := setPermissions(c.group, m.Id, m.Kind)
if err != nil {
return c.error(err)
}
case "kick":
if !c.permissions.Op {
return c.error(userError("not authorised"))
}
err := kickClient(c.group, m.Id)
if err != nil {
return c.error(err)
}
default:
return protocolError("unknown user action")
} }
case "pong": case "pong":
// nothing // nothing