msglist: add initialization state

Make the msglist aware of whether we are still initializing or not.
We never stopped spinning the msglist if we didn't get any Directories back
from types.ListDirectories.
With this change, we can set the init state from the account and display
the spinner only if we don't know whether we have directories or not and else
the "no messages" string from the config.
This commit is contained in:
Reto Brunner 2019-07-31 09:50:07 +02:00 committed by Drew DeVault
parent 04ccbd09b1
commit 9570f4b4d0
2 changed files with 33 additions and 15 deletions

View File

@ -147,6 +147,8 @@ func (acct *AccountView) connected(msg types.WorkerMessage) {
if dir != "" { if dir != "" {
acct.dirlist.Select(dir) acct.dirlist.Select(dir)
} }
acct.msglist.SetInitDone()
acct.logger.Println("Connected.") acct.logger.Println("Connected.")
acct.host.SetStatus("Connected.") acct.host.SetStatus("Connected.")
}) })

View File

@ -23,6 +23,7 @@ type MessageList struct {
nmsgs int nmsgs int
spinner *Spinner spinner *Spinner
store *lib.MessageStore store *lib.MessageStore
isInitalizing bool
} }
func NewMessageList(conf *config.AercConfig, logger *log.Logger) *MessageList { func NewMessageList(conf *config.AercConfig, logger *log.Logger) *MessageList {
@ -30,6 +31,7 @@ func NewMessageList(conf *config.AercConfig, logger *log.Logger) *MessageList {
conf: conf, conf: conf,
logger: logger, logger: logger,
spinner: NewSpinner(), spinner: NewSpinner(),
isInitalizing: true,
} }
ml.spinner.OnInvalidate(func(_ ui.Drawable) { ml.spinner.OnInvalidate(func(_ ui.Drawable) {
ml.Invalidate() ml.Invalidate()
@ -49,8 +51,14 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
store := ml.Store() store := ml.Store()
if store == nil { if store == nil {
if ml.isInitalizing {
ml.spinner.Draw(ctx) ml.spinner.Draw(ctx)
return return
} else {
ml.spinner.Stop()
ml.drawEmptyMessage(ctx)
return
}
} }
var ( var (
@ -111,9 +119,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
} }
if len(uids) == 0 { if len(uids) == 0 {
msg := ml.conf.Ui.EmptyMessage ml.drawEmptyMessage(ctx)
ctx.Printf((ctx.Width()/2)-(len(msg)/2), 0,
tcell.StyleDefault, "%s", msg)
} }
if len(needsHeaders) != 0 { if len(needsHeaders) != 0 {
@ -171,6 +177,10 @@ func (ml *MessageList) SetStore(store *lib.MessageStore) {
ml.Invalidate() ml.Invalidate()
} }
func (ml *MessageList) SetInitDone() {
ml.isInitalizing = false
}
func (ml *MessageList) Store() *lib.MessageStore { func (ml *MessageList) Store() *lib.MessageStore {
return ml.store return ml.store
} }
@ -209,3 +219,9 @@ func (ml *MessageList) Scroll() {
} }
ml.Invalidate() ml.Invalidate()
} }
func (ml *MessageList) drawEmptyMessage(ctx *ui.Context) {
msg := ml.conf.Ui.EmptyMessage
ctx.Printf((ctx.Width()/2)-(len(msg)/2), 0,
tcell.StyleDefault, "%s", msg)
}