forked from Silverfish/proton-bridge
fix(GODT-2442): WIP: bad events just aborts polls, feedback processed in separete channel.
This commit is contained in:
@ -86,16 +86,16 @@ func (user *User) handleRefreshEvent(ctx context.Context, refresh proton.Refresh
|
||||
l.WithError(err).Error("Failed to report refresh to sentry")
|
||||
}
|
||||
|
||||
return user.SyncEvent(ctx)
|
||||
}
|
||||
|
||||
func (user *User) SyncEvent(ctx context.Context) error {
|
||||
// Abort the event stream
|
||||
defer user.pollAbort.Abort()
|
||||
|
||||
// Re-sync messages after the user, address and label refresh.
|
||||
defer user.goSync()
|
||||
|
||||
return user.syncUserAddressesAndLabels(ctx)
|
||||
}
|
||||
|
||||
func (user *User) syncUserAddressesAndLabels(ctx context.Context) error {
|
||||
return safe.LockRet(func() error {
|
||||
// Fetch latest user info.
|
||||
apiUser, err := user.client.GetUser(ctx)
|
||||
|
||||
@ -90,9 +90,6 @@ type User struct {
|
||||
|
||||
syncWorkers int
|
||||
showAllMail uint32
|
||||
|
||||
// doResyncFeedback must be non-blocking for first attempt (i.e. buffered)
|
||||
doResyncFeedback chan bool
|
||||
}
|
||||
|
||||
// New returns a new user.
|
||||
@ -151,8 +148,6 @@ func New(
|
||||
|
||||
syncWorkers: syncWorkers,
|
||||
showAllMail: b32(showAllMail),
|
||||
|
||||
doResyncFeedback: make(chan bool, 1),
|
||||
}
|
||||
|
||||
// Initialize the user's update channels for its current address mode.
|
||||
@ -304,14 +299,17 @@ func (user *User) SetAddressMode(_ context.Context, mode vault.AddressMode) erro
|
||||
}, user.eventLock, user.apiAddrsLock, user.updateChLock)
|
||||
}
|
||||
|
||||
// SendBadEventFeedback sends user feedback whether should do message re-sync.
|
||||
func (user *User) SendBadEventFeedback(doResync bool) {
|
||||
user.doResyncFeedback <- doResync
|
||||
// BadEventAbort stops user to communicate. The resolution is either logout or resync.
|
||||
func (user *User) BadEventAbort() {
|
||||
user.syncAbort.Abort()
|
||||
user.pollAbort.Abort()
|
||||
}
|
||||
|
||||
// GetBadEventFeedback read the user feedback whether should do message re-sync.
|
||||
func (user *User) GetBadEventFeedback() bool {
|
||||
return <-user.doResyncFeedback
|
||||
// BadEventFeedbackResync sends user feedback whether should do message re-sync.
|
||||
func (user *User) BadEventFeedbackResync(ctx context.Context) {
|
||||
if err := user.syncUserAddressesAndLabels(ctx); err != nil {
|
||||
user.log.WithError(err).Error("Bad event resync failed")
|
||||
}
|
||||
}
|
||||
|
||||
// SetShowAllMail sets whether to show the All Mail mailbox.
|
||||
|
||||
Reference in New Issue
Block a user