GODT-1381: Use in-memory cache in case local cache is unavailable

- change: refactor GUI notification object
- add: global bridge errors
- add: when cache on disk cannot be initialized fallback to memory cache
- add: show notification for CoD failure
- change: do not allow login to IMAP and SMTP when CoD init failed
This commit is contained in:
Alexander Bilyak
2021-11-17 13:19:37 +01:00
committed by Jakub
parent 5af3e930ec
commit b82e2ca176
15 changed files with 161 additions and 70 deletions

View File

@ -19,6 +19,7 @@
package bridge
import (
"errors"
"fmt"
"strconv"
"time"
@ -40,6 +41,8 @@ import (
var log = logrus.WithField("pkg", "bridge") //nolint[gochecknoglobals]
var ErrLocalCacheUnavailable = errors.New("local cache is unavailable")
type Bridge struct {
*users.Users
@ -49,6 +52,8 @@ type Bridge struct {
updater Updater
versioner Versioner
cacheProvider CacheProvider
// Bridge's global errors list.
errors []error
}
func New(
@ -241,3 +246,36 @@ func (b *Bridge) SetProxyAllowed(proxyAllowed bool) {
func (b *Bridge) GetProxyAllowed() bool {
return b.settings.GetBool(settings.AllowProxyKey)
}
// AddError add an error to a global error list if it does not contain it yet. Adding nil is noop.
func (b *Bridge) AddError(err error) {
if err == nil {
return
}
if b.HasError(err) {
return
}
b.errors = append(b.errors, err)
}
// DelError removes an error from global error list.
func (b *Bridge) DelError(err error) {
for idx, val := range b.errors {
if val == err {
b.errors = append(b.errors[:idx], b.errors[idx+1:]...)
return
}
}
}
// HasError returnes true if global error list contains an err.
func (b *Bridge) HasError(err error) bool {
for _, val := range b.errors {
if val == err {
return true
}
}
return false
}