aboutsummaryrefslogtreecommitdiff
path: root/widgets/msglist.go
diff options
context:
space:
mode:
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 0000000..370ba85
--- /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
+ }
+}