From f5d370309737b7242ae75382c72e4ac525c75eb6 Mon Sep 17 00:00:00 2001 From: Egor Date: Mon, 9 Feb 2026 02:07:32 -0800 Subject: [PATCH] don't cache signal auth status, dont send empty messages to non-webpush channels --- service/integration/proton/monitor.go | 9 ++++++++ service/integration/signal/client.go | 31 ++------------------------- service/notification/dispatcher.go | 4 ++++ 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/service/integration/proton/monitor.go b/service/integration/proton/monitor.go index c10bb8d..0596875 100644 --- a/service/integration/proton/monitor.go +++ b/service/integration/proton/monitor.go @@ -316,6 +316,15 @@ func (m *Monitor) sendNotification(msg *protonmail.Message) { } func (m *Monitor) clearNotification(msgID string) { + mapping, err := m.dispatcher.GetStore().GetApp(prismTopic) + if err != nil || mapping == nil { + return + } + + if mapping.Channel != notification.ChannelWebPush { + return + } + notif := notification.Notification{ Tag: "proton-" + msgID, Title: "", diff --git a/service/integration/signal/client.go b/service/integration/signal/client.go index b1fe983..b57ed4d 100644 --- a/service/integration/signal/client.go +++ b/service/integration/signal/client.go @@ -9,7 +9,6 @@ import ( "os/exec" "path/filepath" "strings" - "sync" "time" ) @@ -19,11 +18,8 @@ const ( ) type Client struct { - ConfigPath string - enabled bool - accountCache *Account - accountCacheTime time.Time - accountCacheMu sync.RWMutex + ConfigPath string + enabled bool } func NewClient() *Client { @@ -76,25 +72,8 @@ func (c *Client) GetLinkedAccount() (*Account, error) { return nil, nil } - c.accountCacheMu.RLock() - if time.Since(c.accountCacheTime) < 30*time.Second { - cached := c.accountCache - c.accountCacheMu.RUnlock() - return cached, nil - } - c.accountCacheMu.RUnlock() - - c.accountCacheMu.Lock() - defer c.accountCacheMu.Unlock() - - if time.Since(c.accountCacheTime) < 30*time.Second { - return c.accountCache, nil - } - accountsFile := filepath.Join(c.ConfigPath, "data", "accounts.json") if _, err := os.Stat(accountsFile); os.IsNotExist(err) { - c.accountCache = nil - c.accountCacheTime = time.Now() return nil, nil } @@ -115,8 +94,6 @@ func (c *Client) GetLinkedAccount() (*Account, error) { } if len(accountsData.Accounts) == 0 { - c.accountCache = nil - c.accountCacheTime = time.Now() return nil, nil } @@ -130,14 +107,10 @@ func (c *Client) GetLinkedAccount() (*Account, error) { if err != nil { errStr := strings.ToLower(string(output)) if strings.Contains(errStr, "not registered") || strings.Contains(errStr, "authorization failed") { - c.accountCache = nil - c.accountCacheTime = time.Now() return nil, nil } } - c.accountCache = account - c.accountCacheTime = time.Now() return account, nil } diff --git a/service/notification/dispatcher.go b/service/notification/dispatcher.go index 4f166a4..ade7b48 100644 --- a/service/notification/dispatcher.go +++ b/service/notification/dispatcher.go @@ -30,6 +30,10 @@ func (d *Dispatcher) RegisterSender(channel Channel, sender NotificationSender) d.senders[channel] = sender } +func (d *Dispatcher) GetStore() *Store { + return d.store +} + func (d *Dispatcher) HasSignal() bool { _, ok := d.senders[ChannelSignal] return ok