Skip to content

Commit

Permalink
Merge pull request #2211 from slingamn/pushsync
Browse files Browse the repository at this point in the history
fix buggy persistence of push timestamps
  • Loading branch information
slingamn authored Jan 16, 2025
2 parents 9dd7a2b + 7b71839 commit b38ca31
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions irc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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)
}
Expand Down
11 changes: 9 additions & 2 deletions irc/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion irc/nickserv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion irc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b38ca31

Please sign in to comment.