3
0
mirror of https://github.com/ergochat/ergo.git synced 2025-01-21 01:34:20 +01:00

Merge pull request #2211 from slingamn/pushsync

fix buggy persistence of push timestamps
This commit is contained in:
Shivaram Lingamneni 2025-01-15 21:22:57 -08:00 committed by GitHub
commit b38ca31ced
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 6 deletions

View File

@ -1881,7 +1881,7 @@ func (client *Client) performWrite(additionalDirtyBits uint) {
client.server.accounts.saveRealname(account, client.realname) client.server.accounts.saveRealname(account, client.realname)
} }
if (dirtyBits & IncludePushSubscriptions) != 0 { 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 { for {
select { select {
case msg := <-client.pushQueue.queue: case msg := <-client.pushQueue.queue:
for _, sub := range client.getPushSubscriptions() { for _, sub := range client.getPushSubscriptions(false) {
if !client.skipPushMessage(msg) { if !client.skipPushMessage(msg) {
client.sendAndTrackPush(sub.Endpoint, sub.Keys, msg, true) client.sendAndTrackPush(sub.Endpoint, sub.Keys, msg, true)
} }

View File

@ -658,10 +658,17 @@ func (client *Client) hasPushSubscriptions() bool {
return client.pushSubscriptionsExist.Load() != 0 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() client.stateMutex.RLock()
defer client.stateMutex.RUnlock() defer client.stateMutex.RUnlock()
return client.cachedPushSubscriptions return client.cachedPushSubscriptions
} }

View File

@ -1683,7 +1683,7 @@ func nsPushHandler(service *ircService, server *Server, client *Client, command
return 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))) 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 { for i, subscription := range subscriptions {
service.Notice(rb, fmt.Sprintf(client.t("Subscription %d:"), i+1)) service.Notice(rb, fmt.Sprintf(client.t("Subscription %d:"), i+1))

View File

@ -311,7 +311,7 @@ func (server *Server) periodicPushMaintenance() {
func (server *Server) performPushMaintenance() { func (server *Server) performPushMaintenance() {
expiration := time.Duration(server.Config().WebPush.Expiration) expiration := time.Duration(server.Config().WebPush.Expiration)
for _, client := range server.clients.AllWithPushSubscriptions() { for _, client := range server.clients.AllWithPushSubscriptions() {
for _, sub := range client.getPushSubscriptions() { for _, sub := range client.getPushSubscriptions(true) {
now := time.Now() now := time.Now()
// require both periodic successful push messages and renewal of the subscription via WEBPUSH REGISTER // 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 { if now.Sub(sub.LastSuccess) > expiration || now.Sub(sub.LastRefresh) > expiration {