aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
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
parent289e3b09ea20e911071e5a0f274445429502e934 (diff)
downloadaerc-b3896476a0e6978c0d7f6fedfb64588934a78f1e.tar.gz
Fetch valid UIDs from server after opening dir
Diffstat (limited to 'widgets')
-rw-r--r--widgets/account.go35
-rw-r--r--widgets/msglist.go36
2 files changed, 65 insertions, 6 deletions
diff --git a/widgets/account.go b/widgets/account.go
index c5545ef5..3085d271 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -21,6 +21,7 @@ type AccountView struct {
interactive ui.Interactive
onInvalidate func(d ui.Drawable)
runCmd func(cmd string) error
+ msgStores map[string]*MessageStore
statusline *StatusLine
statusbar *ui.Stack
worker *types.Worker
@@ -64,9 +65,10 @@ func NewAccountView(conf *config.AccountConfig,
dirlist: dirlist,
grid: grid,
logger: logger,
+ msgStores: make(map[string]*MessageStore),
runCmd: runCmd,
- statusline: statusline,
statusbar: statusbar,
+ statusline: statusline,
worker: worker,
}
@@ -157,10 +159,6 @@ func (acct *AccountView) connected(msg types.WorkerMessage) {
Message: types.RespondTo(msg),
Approved: true,
}, acct.connected)
- case *types.Error:
- acct.logger.Printf("%v", msg.Error)
- acct.statusline.Set(fmt.Sprintf("%v", msg.Error)).
- Color(tcell.ColorRed, tcell.ColorDefault)
}
}
@@ -169,5 +167,30 @@ func (acct *AccountView) Directories() *DirectoryList {
}
func (acct *AccountView) onMessage(msg types.WorkerMessage) {
- // TODO
+ switch msg := msg.(type) {
+ case *types.Done:
+ switch msg.InResponseTo().(type) {
+ case *types.OpenDirectory:
+ acct.worker.PostAction(&types.FetchDirectoryContents{},
+ func(msg types.WorkerMessage) {
+ // TODO: Do we care
+ })
+ }
+ case *types.DirectoryInfo:
+ if store, ok := acct.msgStores[msg.Name]; ok {
+ store.Update(msg)
+ } else {
+ acct.msgStores[msg.Name] = NewMessageStore(msg)
+ }
+ case *types.DirectoryContents:
+ store := acct.msgStores[acct.dirlist.selected]
+ store.Update(msg)
+ case *types.MessageInfo:
+ store := acct.msgStores[acct.dirlist.selected]
+ store.Update(msg)
+ case *types.Error:
+ acct.logger.Printf("%v", msg.Error)
+ acct.statusline.Set(fmt.Sprintf("%v", msg.Error)).
+ Color(tcell.ColorRed, tcell.ColorDefault)
+ }
}
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
+ }
+}