aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/account.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-04-16 09:53:40 -0500
committerRobin Jarry <robin@jarry.cc>2023-04-22 22:40:12 +0200
commit8ced001d82b59f353c33ad34ca0c79313eef41af (patch)
tree1044ba34ffd9f8b66a04cac16c83de56bd363e34 /widgets/account.go
parent2fbb7ce4cbf67538fb7e3416ba0820a22607d452 (diff)
downloadaerc-8ced001d82b59f353c33ad34ca0c79313eef41af.tar.gz
listDirectories: refactor listdirectories handling
ListDirectories is called when connecting, reconnecting, and creation/deletion of a directory. The code is not in the same style as other areas of aerc. Refactor to match coding style of the rest of aerc by creating an Update function which handles necessary updates in the dirlist. This style does not use a callback, making it clearer what is happening in the message flow, and operates similar to how the msgstore receives updates. Use a map in the dirstore to reduce duplicate storage of directory names. Directly add or remove directories from the map when created / deleted to prevent a new ListDirectories message, and a flash of the UI. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets/account.go')
-rw-r--r--widgets/account.go48
1 files changed, 27 insertions, 21 deletions
diff --git a/widgets/account.go b/widgets/account.go
index 3ba511de..ad9d200a 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -231,26 +231,10 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
switch msg.InResponseTo().(type) {
case *types.Connect, *types.Reconnect:
acct.SetStatus(state.ConnectionActivity("Listing mailboxes..."))
+ log.Infof("[%s] connected.", acct.acct.Name)
+ acct.SetStatus(state.SetConnected(true))
log.Tracef("Listing mailboxes...")
- acct.dirlist.UpdateList(func(dirs []string) {
- var dir string
- for _, _dir := range dirs {
- if _dir == acct.acct.Default {
- dir = _dir
- break
- }
- }
- if dir == "" && len(dirs) > 0 {
- dir = dirs[0]
- }
- if dir != "" {
- acct.dirlist.Select(dir)
- }
- acct.msglist.SetInitDone()
- log.Infof("[%s] connected.", acct.acct.Name)
- acct.SetStatus(state.SetConnected(true))
- acct.newConn = true
- })
+ acct.worker.PostAction(&types.ListDirectories{}, nil)
case *types.Disconnect:
acct.dirlist.ClearList()
acct.msglist.SetStore(nil)
@@ -268,13 +252,35 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
acct.msglist.SetStore(nil)
}
case *types.CreateDirectory:
- acct.dirlist.UpdateList(nil)
+ acct.dirlist.Update(msg)
case *types.RemoveDirectory:
- acct.dirlist.UpdateList(nil)
+ acct.dirlist.Update(msg)
case *types.FetchMessageHeaders:
if acct.newConn {
acct.checkMailOnStartup()
}
+ case *types.ListDirectories:
+ acct.dirlist.Update(msg)
+ if acct.dirlist.Selected() != "" {
+ return
+ }
+ // Nothing selected, select based on config
+ dirs := acct.dirlist.List()
+ var dir string
+ for _, _dir := range dirs {
+ if _dir == acct.acct.Default {
+ dir = _dir
+ break
+ }
+ }
+ if dir == "" && len(dirs) > 0 {
+ dir = dirs[0]
+ }
+ if dir != "" {
+ acct.dirlist.Select(dir)
+ }
+ acct.msglist.SetInitDone()
+ acct.newConn = true
}
case *types.Directory:
name := msg.Dir.Name