Broadcast Web Push subscriptions in a new goroutine

This commit is contained in:
Simon Ser 2022-08-17 16:09:12 +02:00
parent 05a382ef16
commit 65f0b2367e
3 changed files with 11 additions and 4 deletions

View file

@ -3060,7 +3060,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
// TODO: only broadcast if draft/read-marker has been negotiated
// TODO: use lower priority
network.pushTargets.Del(entity)
network.broadcastWebPush(ctx, &irc.Message{
go network.broadcastWebPush(&irc.Message{
Command: "MARKREAD",
Params: []string{entity, timestampStr},
})

View file

@ -547,7 +547,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
}
if highlight || uc.isOurNick(target) {
uc.network.broadcastWebPush(ctx, msg)
go uc.network.broadcastWebPush(msg)
uc.network.pushTargets.Add(bufferName)
}
@ -1551,7 +1551,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
})
if weAreInvited {
uc.network.broadcastWebPush(ctx, msg)
go uc.network.broadcastWebPush(msg)
}
case irc.RPL_INVITING:
var nick, channel string

View file

@ -456,7 +456,14 @@ func (net *network) autoSaveSASLPlain(ctx context.Context, username, password st
}
}
func (net *network) broadcastWebPush(ctx context.Context, msg *irc.Message) {
// broadcastWebPush broadcasts a Web Push message for the given IRC message.
//
// Broadcasting the message to all Web Push endpoints might take a while, so
// callers should call this function in a new goroutine.
func (net *network) broadcastWebPush(msg *irc.Message) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
subs, err := net.user.srv.db.ListWebPushSubscriptions(ctx, net.user.ID, net.ID)
if err != nil {
net.logger.Printf("failed to list Web push subscriptions: %v", err)