mirror of
https://github.com/jech/galene.git
synced 2024-12-22 15:25:48 +01:00
Implement /subgroups.
This commit is contained in:
parent
43047fc00e
commit
27a2e45500
3 changed files with 53 additions and 0 deletions
|
@ -259,6 +259,30 @@ func GetNames() []string {
|
|||
return names
|
||||
}
|
||||
|
||||
type SubGroup struct {
|
||||
Name string
|
||||
Clients int
|
||||
}
|
||||
|
||||
func GetSubGroups(parent string) []SubGroup {
|
||||
prefix := parent + "/"
|
||||
subgroups := make([]SubGroup, 0)
|
||||
|
||||
Range(func(g *Group) bool {
|
||||
if strings.HasPrefix(g.name, prefix) {
|
||||
g.mu.Lock()
|
||||
count := len(g.clients)
|
||||
g.mu.Unlock()
|
||||
if count > 0 {
|
||||
subgroups = append(subgroups,
|
||||
SubGroup{g.name, count})
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
return subgroups
|
||||
}
|
||||
|
||||
func Get(name string) *Group {
|
||||
groups.mu.Lock()
|
||||
defer groups.mu.Unlock()
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
"fmt"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/pion/webrtc/v3"
|
||||
|
@ -1218,6 +1219,26 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
|||
group.DelClient(disk)
|
||||
}
|
||||
}
|
||||
case "subgroups":
|
||||
if !c.permissions.Op {
|
||||
return c.error(group.UserError("not authorised"))
|
||||
}
|
||||
s := ""
|
||||
for _, sg := range group.GetSubGroups(g.Name()) {
|
||||
plural := ""
|
||||
if sg.Clients > 1 {
|
||||
plural = "s"
|
||||
}
|
||||
s = s + fmt.Sprintf("%v (%v client%v)",
|
||||
sg.Name, sg.Clients, plural)
|
||||
}
|
||||
c.write(clientMessage{
|
||||
Type: "chat",
|
||||
Dest: c.id,
|
||||
Username: "Server",
|
||||
Time: group.ToJSTime(time.Now()),
|
||||
Value: &s,
|
||||
})
|
||||
default:
|
||||
return group.ProtocolError("unknown group action")
|
||||
}
|
||||
|
|
|
@ -1759,6 +1759,14 @@ commands.unrecord = {
|
|||
}
|
||||
};
|
||||
|
||||
commands.subgroups = {
|
||||
predicate: operatorPredicate,
|
||||
description: 'list subgroups',
|
||||
f: (c, r) => {
|
||||
serverConnection.groupAction(getUsername(), 'subgroups');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* parseCommand splits a string into two space-separated parts. The first
|
||||
* part may be quoted and may include backslash escapes.
|
||||
|
|
Loading…
Reference in a new issue