From 8a2357de213a8ff64f479470dc4e686f45117d77 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Fri, 7 Oct 2022 00:21:03 +0200 Subject: [PATCH] Only send chat history when joining. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we moved the chat history to the client goroutine back in 0.6, we started sending the history whenever the group configuration changed. Only send it when first joining the group. Thanks to Rémi Nollet. --- CHANGES | 1 + rtpconn/webclient.go | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/CHANGES b/CHANGES index 832deb9..bf601d9 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,7 @@ Galene 0.6.1 (unreleased): * Ensure that autolocked groups are locked on creation. Thanks to Michael Ströder. + * Don't send chat history multiple times. Thanks to Rémy Nollet. * Add a camera/microphone indicator in the users list. * Hide audio-only peers by default. diff --git a/rtpconn/webclient.go b/rtpconn/webclient.go index 36d1e2b..e5e1f3b 100644 --- a/rtpconn/webclient.go +++ b/rtpconn/webclient.go @@ -1168,8 +1168,9 @@ func handleAction(c *webClient, a interface{}) error { case joinedAction: var status *group.Status var data map[string]interface{} + var g *group.Group if a.group != "" { - g := group.Get(a.group) + g = group.Get(a.group) if g != nil { s := g.Status(true, "") status = &s @@ -1190,18 +1191,25 @@ func handleAction(c *webClient, a interface{}) error { if err != nil { return err } - h := c.group.GetChatHistory() - for _, m := range h { - err := c.write(clientMessage{ - Type: "chathistory", - Source: m.Id, - Username: m.User, - Time: m.Time, - Value: m.Value, - Kind: m.Kind, - }) - if err != nil { - return err + if a.kind == "join" { + if g == nil { + log.Println("g is null when joining" + + "this shouldn't happen") + return nil + } + h := g.GetChatHistory() + for _, m := range h { + err := c.write(clientMessage{ + Type: "chathistory", + Source: m.Id, + Username: m.User, + Time: m.Time, + Value: m.Value, + Kind: m.Kind, + }) + if err != nil { + return err + } } } case permissionsChangedAction: