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

Send chathistory messages in the client goroutine.

We used to send the chat history from the reader goroutine,
which would cause them to race with the join message.
This commit is contained in:
Juliusz Chroboczek 2022-09-06 03:03:50 +02:00
parent 533e4b9b32
commit 3a2efbcc7e

View file

@ -1177,7 +1177,7 @@ func handleAction(c *webClient, a interface{}) error {
} }
} }
perms := append([]string(nil), c.permissions...) perms := append([]string(nil), c.permissions...)
return c.write(clientMessage{ err := c.write(clientMessage{
Type: "joined", Type: "joined",
Kind: a.kind, Kind: a.kind,
Group: a.group, Group: a.group,
@ -1187,6 +1187,23 @@ func handleAction(c *webClient, a interface{}) error {
Data: data, Data: data,
RTCConfiguration: ice.ICEConfiguration(), RTCConfiguration: ice.ICEConfiguration(),
}) })
if err != nil {
return err
}
h := c.group.GetChatHistory()
for _, m := range h {
err := c.write(clientMessage{
Type: "chathistory",
Id: m.Id,
Username: m.User,
Time: m.Time,
Value: m.Value,
Kind: m.Kind,
})
if err != nil {
return err
}
}
case permissionsChangedAction: case permissionsChangedAction:
g := c.Group() g := c.Group()
if g == nil { if g == nil {
@ -1426,20 +1443,6 @@ func handleClientMessage(c *webClient, m clientMessage) error {
}) })
} }
c.group = g c.group = g
h := c.group.GetChatHistory()
for _, m := range h {
err := c.write(clientMessage{
Type: "chathistory",
Id: m.Id,
Username: m.User,
Time: m.Time,
Value: m.Value,
Kind: m.Kind,
})
if err != nil {
return err
}
}
case "request": case "request":
requested, err := parseRequested(m.Request) requested, err := parseRequested(m.Request)
if err != nil { if err != nil {