diff options
author | Jeffas <dev@jeffas.io> | 2019-07-21 22:39:36 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-07-26 14:15:27 -0400 |
commit | 1b673b5ea7d06ef914e9d48ff7299f8b5f2119fd (patch) | |
tree | 7b6598470500ec2fd923fb6f0939409c25963d79 /widgets/account.go | |
parent | dc4c36adbfbffd34319ddc007bad437ef802ee72 (diff) | |
download | aerc-1b673b5ea7d06ef914e9d48ff7299f8b5f2119fd.tar.gz |
Move msgstore map to dirstore
This map represents a mapping from directory names to their associated messagestores anyway so they should be under dirstore. This simply moves them there and adds some methods required to interact with them.
Diffstat (limited to 'widgets/account.go')
-rw-r--r-- | widgets/account.go | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/widgets/account.go b/widgets/account.go index 92e7a56..86ec00c 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -16,15 +16,14 @@ import ( ) type AccountView struct { - acct *config.AccountConfig - conf *config.AercConfig - dirlist *DirectoryList - grid *ui.Grid - host TabHost - logger *log.Logger - msglist *MessageList - msgStores map[string]*lib.MessageStore - worker *types.Worker + acct *config.AccountConfig + conf *config.AercConfig + dirlist *DirectoryList + grid *ui.Grid + host TabHost + logger *log.Logger + msglist *MessageList + worker *types.Worker } func NewAccountView(conf *config.AercConfig, acct *config.AccountConfig, @@ -58,15 +57,14 @@ func NewAccountView(conf *config.AercConfig, acct *config.AccountConfig, grid.AddChild(msglist).At(0, 1) view := &AccountView{ - acct: acct, - conf: conf, - dirlist: dirlist, - grid: grid, - host: host, - logger: logger, - msglist: msglist, - msgStores: make(map[string]*lib.MessageStore), - worker: worker, + acct: acct, + conf: conf, + dirlist: dirlist, + grid: grid, + host: host, + logger: logger, + msglist: msglist, + worker: worker, } go worker.Backend.Run() @@ -187,7 +185,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { case *types.Done: switch msg.InResponseTo().(type) { case *types.OpenDirectory: - if store, ok := acct.msgStores[acct.dirlist.selected]; ok { + if store, ok := acct.dirlist.SelectedMsgStore(); ok { // If we've opened this dir before, we can re-render it from // memory while we wait for the update and the UI feels // snappier. If not, we'll unset the store and show the spinner @@ -200,7 +198,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { acct.dirlist.UpdateList(nil) } case *types.DirectoryInfo: - if store, ok := acct.msgStores[msg.Info.Name]; ok { + if store, ok := acct.dirlist.MsgStore(msg.Info.Name); ok { store.Update(msg) } else { store = lib.NewMessageStore(acct.worker, msg.Info, @@ -208,26 +206,26 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { acct.conf.Triggers.ExecNewEmail(acct.acct, acct.conf, msg) }) - acct.msgStores[msg.Info.Name] = store + acct.dirlist.SetMsgStore(msg.Info.Name, store) store.OnUpdate(func(_ *lib.MessageStore) { store.OnUpdate(nil) acct.msglist.SetStore(store) }) } case *types.DirectoryContents: - if store, ok := acct.msgStores[acct.dirlist.selected]; ok { + if store, ok := acct.dirlist.SelectedMsgStore(); ok { store.Update(msg) } case *types.FullMessage: - if store, ok := acct.msgStores[acct.dirlist.selected]; ok { + if store, ok := acct.dirlist.SelectedMsgStore(); ok { store.Update(msg) } case *types.MessageInfo: - if store, ok := acct.msgStores[acct.dirlist.selected]; ok { + if store, ok := acct.dirlist.SelectedMsgStore(); ok { store.Update(msg) } case *types.MessagesDeleted: - if store, ok := acct.msgStores[acct.dirlist.selected]; ok { + if store, ok := acct.dirlist.SelectedMsgStore(); ok { store.Update(msg) } case *types.Error: |