Commit 27a2e455 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement /subgroups.

parent 43047fc0
......@@ -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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment