diff options
Diffstat (limited to 'lib/msgstore.go')
-rw-r--r-- | lib/msgstore.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go index a545f62f..58c5faba 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -48,6 +48,10 @@ type MessageStore struct { pendingHeaders map[uint32]interface{} worker *types.Worker + needsFlags []uint32 + fetchFlagsDebounce *time.Timer + fetchFlagsDelay time.Duration + triggerNewEmail func(*models.MessageInfo) triggerDirectoryChange func() @@ -91,6 +95,9 @@ func NewMessageStore(worker *types.Worker, pendingHeaders: make(map[uint32]interface{}), worker: worker, + needsFlags: []uint32{}, + fetchFlagsDelay: 50 * time.Millisecond, + triggerNewEmail: triggerNewEmail, triggerDirectoryChange: triggerDirectoryChange, @@ -251,6 +258,10 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { } else if msg.Info.Envelope != nil { store.Messages[msg.Info.Uid] = msg.Info } + if msg.NeedsFlags { + store.needsFlags = append(store.needsFlags, msg.Info.Uid) + store.fetchFlags() + } seen := false recent := false for _, flag := range msg.Info.Flags { @@ -752,3 +763,15 @@ func (store *MessageStore) Capabilities() *models.Capabilities { func (store *MessageStore) SelectedIndex() int { return store.FindIndexByUid(store.selectedUid) } + +func (store *MessageStore) fetchFlags() { + if store.fetchFlagsDebounce != nil { + store.fetchFlagsDebounce.Stop() + } + store.fetchFlagsDebounce = time.AfterFunc(store.fetchFlagsDelay, func() { + store.worker.PostAction(&types.FetchMessageFlags{ + Uids: store.needsFlags, + }, nil) + store.needsFlags = []uint32{} + }) +} |