mirror of
https://github.com/lone-cloud/prism
synced 2026-06-03 08:43:10 -07:00
don't cache signal auth status, dont send empty messages to non-webpush channels
This commit is contained in:
parent
897df27e00
commit
f5d3703097
3 changed files with 15 additions and 29 deletions
|
|
@ -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: "",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue