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: only broadcast if draft/read-marker has been negotiated
// TODO: use lower priority // TODO: use lower priority
network.pushTargets.Del(entity) network.pushTargets.Del(entity)
network.broadcastWebPush(ctx, &irc.Message{ go network.broadcastWebPush(&irc.Message{
Command: "MARKREAD", Command: "MARKREAD",
Params: []string{entity, timestampStr}, 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) { if highlight || uc.isOurNick(target) {
uc.network.broadcastWebPush(ctx, msg) go uc.network.broadcastWebPush(msg)
uc.network.pushTargets.Add(bufferName) uc.network.pushTargets.Add(bufferName)
} }
@ -1551,7 +1551,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
}) })
if weAreInvited { if weAreInvited {
uc.network.broadcastWebPush(ctx, msg) go uc.network.broadcastWebPush(msg)
} }
case irc.RPL_INVITING: case irc.RPL_INVITING:
var nick, channel string 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) subs, err := net.user.srv.db.ListWebPushSubscriptions(ctx, net.user.ID, net.ID)
if err != nil { if err != nil {
net.logger.Printf("failed to list Web push subscriptions: %v", err) net.logger.Printf("failed to list Web push subscriptions: %v", err)