diff --git a/client.go b/client.go index 7ba9822..c709efb 100644 --- a/client.go +++ b/client.go @@ -1061,6 +1061,13 @@ func handleClientMessage(c *client, m clientMessage) error { for _, cc := range clients { cc.write(m) } + case "clearchat": + c.group.clearChatHistory() + m := clientMessage{Type: "clearchat"} + clients := c.group.getClients(nil) + for _, cc := range clients { + cc.write(m) + } case "op", "unop", "present", "unpresent": if !c.permissions.Op { c.error(userError("not authorised")) diff --git a/group.go b/group.go index 343b827..dc1913d 100644 --- a/group.go +++ b/group.go @@ -361,6 +361,12 @@ func (g *group) Range(f func(c *client) bool) { const maxChatHistory = 20 +func (g *group) clearChatHistory() { + g.mu.Lock() + defer g.mu.Unlock() + g.history = nil +} + func (g *group) addToChatHistory(id, user, value string, me bool) { g.mu.Lock() defer g.mu.Unlock() diff --git a/static/sfu.js b/static/sfu.js index 7bf69b3..c585519 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -435,6 +435,9 @@ function serverConnect() { case 'chat': addToChatbox(m.id, m.username, m.value, m.me); break; + case 'clearchat': + resetChat(); + break; case 'ping': send({ type: 'pong', @@ -750,6 +753,15 @@ function handleInput() { case '/leave': socket.close(); return; + case '/clear': + if(!permissions.op) { + displayError("You're not an operator"); + return; + } + send({ + type: 'clearchat', + }); + return; case '/op': case '/unop': case '/kick':