aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/msglist.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-10 23:45:00 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-10 23:45:00 -0400
commitb3896476a0e6978c0d7f6fedfb64588934a78f1e (patch)
tree735e92c3ecb2955ab53cb3f77f0c676fcd64f1a0 /widgets/msglist.go
parent289e3b09ea20e911071e5a0f274445429502e934 (diff)
downloadaerc-b3896476a0e6978c0d7f6fedfb64588934a78f1e.tar.gz
Fetch valid UIDs from server after opening dir
Diffstat (limited to 'widgets/msglist.go')
-rw-r--r--widgets/msglist.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/widgets/msglist.go b/widgets/msglist.go
new file mode 100644
index 00000000..370ba85d
--- /dev/null
+++ b/widgets/msglist.go
@@ -0,0 +1,36 @@
+package widgets
+
+import (
+ "git.sr.ht/~sircmpwn/aerc2/worker/types"
+)
+
+type MessageStore struct {
+ DirInfo types.DirectoryInfo
+ Messages map[uint64]*types.MessageInfo
+}
+
+func NewMessageStore(dirInfo *types.DirectoryInfo) *MessageStore {
+ return &MessageStore{DirInfo: *dirInfo}
+}
+
+func (store *MessageStore) Update(msg types.WorkerMessage) {
+ switch msg := msg.(type) {
+ case *types.DirectoryInfo:
+ store.DirInfo = *msg
+ break
+ case *types.DirectoryContents:
+ newMap := make(map[uint64]*types.MessageInfo)
+ for _, uid := range msg.Uids {
+ if msg, ok := store.Messages[uid]; ok {
+ newMap[uid] = msg
+ } else {
+ newMap[uid] = nil
+ }
+ }
+ store.Messages = newMap
+ break
+ case *types.MessageInfo:
+ store.Messages[msg.Uid] = msg
+ break
+ }
+}