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) {
|
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{
|
notif := notification.Notification{
|
||||||
Tag: "proton-" + msgID,
|
Tag: "proton-" + msgID,
|
||||||
Title: "",
|
Title: "",
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -19,11 +18,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
ConfigPath string
|
ConfigPath string
|
||||||
enabled bool
|
enabled bool
|
||||||
accountCache *Account
|
|
||||||
accountCacheTime time.Time
|
|
||||||
accountCacheMu sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient() *Client {
|
func NewClient() *Client {
|
||||||
|
|
@ -76,25 +72,8 @@ func (c *Client) GetLinkedAccount() (*Account, error) {
|
||||||
return nil, nil
|
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")
|
accountsFile := filepath.Join(c.ConfigPath, "data", "accounts.json")
|
||||||
if _, err := os.Stat(accountsFile); os.IsNotExist(err) {
|
if _, err := os.Stat(accountsFile); os.IsNotExist(err) {
|
||||||
c.accountCache = nil
|
|
||||||
c.accountCacheTime = time.Now()
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,8 +94,6 @@ func (c *Client) GetLinkedAccount() (*Account, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(accountsData.Accounts) == 0 {
|
if len(accountsData.Accounts) == 0 {
|
||||||
c.accountCache = nil
|
|
||||||
c.accountCacheTime = time.Now()
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,14 +107,10 @@ func (c *Client) GetLinkedAccount() (*Account, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errStr := strings.ToLower(string(output))
|
errStr := strings.ToLower(string(output))
|
||||||
if strings.Contains(errStr, "not registered") || strings.Contains(errStr, "authorization failed") {
|
if strings.Contains(errStr, "not registered") || strings.Contains(errStr, "authorization failed") {
|
||||||
c.accountCache = nil
|
|
||||||
c.accountCacheTime = time.Now()
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.accountCache = account
|
|
||||||
c.accountCacheTime = time.Now()
|
|
||||||
return account, nil
|
return account, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,10 @@ func (d *Dispatcher) RegisterSender(channel Channel, sender NotificationSender)
|
||||||
d.senders[channel] = sender
|
d.senders[channel] = sender
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Dispatcher) GetStore() *Store {
|
||||||
|
return d.store
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Dispatcher) HasSignal() bool {
|
func (d *Dispatcher) HasSignal() bool {
|
||||||
_, ok := d.senders[ChannelSignal]
|
_, ok := d.senders[ChannelSignal]
|
||||||
return ok
|
return ok
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue