diff --git a/downstream.go b/downstream.go index 6336eed..1c95e0c 100644 --- a/downstream.go +++ b/downstream.go @@ -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}, }) diff --git a/upstream.go b/upstream.go index d731b3d..3c22173 100644 --- a/upstream.go +++ b/upstream.go @@ -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 diff --git a/user.go b/user.go index 8c072f5..6d93bc2 100644 --- a/user.go +++ b/user.go @@ -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)