dirlist: fix panic when disconnecting with dirlist-tree=false
Commit2027223a
created a panic when attempting to clear the dirlist when the config option dirlist-tree is set to false. This patch fixes that panic by creating a dirlist.ClearList() function to prevent needing to check a callback. Tested with both dirlist-tree=false and true Fixes:2027223ab3
("fix: clear dirlist on disconnect") Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
2027223ab3
commit
115447e57f
3 changed files with 10 additions and 17 deletions
|
@ -246,7 +246,6 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
|
||||||
case *types.Connect, *types.Reconnect:
|
case *types.Connect, *types.Reconnect:
|
||||||
acct.SetStatus(statusline.ConnectionActivity("Listing mailboxes..."))
|
acct.SetStatus(statusline.ConnectionActivity("Listing mailboxes..."))
|
||||||
acct.logger.Println("Listing mailboxes...")
|
acct.logger.Println("Listing mailboxes...")
|
||||||
acct.dirlist.SetConnected(true)
|
|
||||||
acct.dirlist.UpdateList(func(dirs []string) {
|
acct.dirlist.UpdateList(func(dirs []string) {
|
||||||
var dir string
|
var dir string
|
||||||
for _, _dir := range dirs {
|
for _, _dir := range dirs {
|
||||||
|
@ -267,8 +266,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
|
||||||
acct.newConn = true
|
acct.newConn = true
|
||||||
})
|
})
|
||||||
case *types.Disconnect:
|
case *types.Disconnect:
|
||||||
acct.dirlist.SetConnected(false)
|
acct.dirlist.ClearList()
|
||||||
acct.dirlist.UpdateList(nil)
|
|
||||||
acct.msglist.SetStore(nil)
|
acct.msglist.SetStore(nil)
|
||||||
acct.logger.Println("Disconnected.")
|
acct.logger.Println("Disconnected.")
|
||||||
acct.SetStatus(statusline.SetConnected(false))
|
acct.SetStatus(statusline.SetConnected(false))
|
||||||
|
|
|
@ -31,7 +31,7 @@ type DirectoryLister interface {
|
||||||
|
|
||||||
UpdateList(func([]string))
|
UpdateList(func([]string))
|
||||||
List() []string
|
List() []string
|
||||||
SetConnected(bool)
|
ClearList()
|
||||||
|
|
||||||
NextPrev(int)
|
NextPrev(int)
|
||||||
|
|
||||||
|
@ -93,24 +93,15 @@ func (dirlist *DirectoryList) UiConfig() config.UIConfig {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dirlist *DirectoryList) SetConnected(c bool) {
|
|
||||||
dirlist.connected = c
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dirlist *DirectoryList) List() []string {
|
func (dirlist *DirectoryList) List() []string {
|
||||||
return dirlist.store.List()
|
return dirlist.store.List()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dirlist *DirectoryList) ClearList() {
|
||||||
|
dirlist.dirs = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
|
func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
|
||||||
// Clear out dirlist if not connected
|
|
||||||
if !dirlist.connected {
|
|
||||||
// Only dirlist.dirs is used for the UI. No need to update dirstore
|
|
||||||
dirlist.dirs = []string{}
|
|
||||||
dirlist.Invalidate()
|
|
||||||
// Call callback with empty array for dirtree
|
|
||||||
done(dirlist.dirs)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// TODO: move this logic into dirstore
|
// TODO: move this logic into dirstore
|
||||||
var dirs []string
|
var dirs []string
|
||||||
dirlist.worker.PostAction(
|
dirlist.worker.PostAction(
|
||||||
|
|
|
@ -32,6 +32,10 @@ func NewDirectoryTree(dirlist *DirectoryList, pathSeparator string) DirectoryLis
|
||||||
return dt
|
return dt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dt *DirectoryTree) ClearList() {
|
||||||
|
dt.list = make([]*types.Thread, 0)
|
||||||
|
}
|
||||||
|
|
||||||
func (dt *DirectoryTree) UpdateList(done func([]string)) {
|
func (dt *DirectoryTree) UpdateList(done func([]string)) {
|
||||||
dt.DirectoryList.UpdateList(func(dirs []string) {
|
dt.DirectoryList.UpdateList(func(dirs []string) {
|
||||||
if done != nil {
|
if done != nil {
|
||||||
|
|
Loading…
Reference in a new issue