diff --git a/irc/client.go b/irc/client.go index f6bca331..85750519 100644 --- a/irc/client.go +++ b/irc/client.go @@ -1881,7 +1881,7 @@ func (client *Client) performWrite(additionalDirtyBits uint) { client.server.accounts.saveRealname(account, client.realname) } if (dirtyBits & IncludePushSubscriptions) != 0 { - client.server.accounts.savePushSubscriptions(account, client.getPushSubscriptions()) + client.server.accounts.savePushSubscriptions(account, client.getPushSubscriptions(true)) } } @@ -1968,7 +1968,7 @@ func (client *Client) pushWorker() { for { select { case msg := <-client.pushQueue.queue: - for _, sub := range client.getPushSubscriptions() { + for _, sub := range client.getPushSubscriptions(false) { if !client.skipPushMessage(msg) { client.sendAndTrackPush(sub.Endpoint, sub.Keys, msg, true) } diff --git a/irc/getters.go b/irc/getters.go index 5db89ab5..d0e08256 100644 --- a/irc/getters.go +++ b/irc/getters.go @@ -658,10 +658,17 @@ func (client *Client) hasPushSubscriptions() bool { return client.pushSubscriptionsExist.Load() != 0 } -func (client *Client) getPushSubscriptions() []storedPushSubscription { +func (client *Client) getPushSubscriptions(refresh bool) []storedPushSubscription { + if refresh { + func() { + client.stateMutex.Lock() + defer client.stateMutex.Unlock() + client.rebuildPushSubscriptionCache() + }() + } + client.stateMutex.RLock() defer client.stateMutex.RUnlock() - return client.cachedPushSubscriptions } diff --git a/irc/nickserv.go b/irc/nickserv.go index 3e4637f4..51735be1 100644 --- a/irc/nickserv.go +++ b/irc/nickserv.go @@ -1683,7 +1683,7 @@ func nsPushHandler(service *ircService, server *Server, client *Client, command return } } - subscriptions := target.getPushSubscriptions() + subscriptions := target.getPushSubscriptions(true) service.Notice(rb, fmt.Sprintf(client.t("Nickname %[1]s has %[2]d push subscription(s)"), target.Nick(), len(subscriptions))) for i, subscription := range subscriptions { service.Notice(rb, fmt.Sprintf(client.t("Subscription %d:"), i+1)) diff --git a/irc/server.go b/irc/server.go index 72660bc9..e4b93e81 100644 --- a/irc/server.go +++ b/irc/server.go @@ -311,7 +311,7 @@ func (server *Server) periodicPushMaintenance() { func (server *Server) performPushMaintenance() { expiration := time.Duration(server.Config().WebPush.Expiration) for _, client := range server.clients.AllWithPushSubscriptions() { - for _, sub := range client.getPushSubscriptions() { + for _, sub := range client.getPushSubscriptions(true) { now := time.Now() // require both periodic successful push messages and renewal of the subscription via WEBPUSH REGISTER if now.Sub(sub.LastSuccess) > expiration || now.Sub(sub.LastRefresh) > expiration {