summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2019-07-31 09:50:07 +0200
committerDrew DeVault <sir@cmpwn.com>2019-08-02 09:26:10 -0400
commit9570f4b4d0cdf525ce1695971636a0b58f1a091b (patch)
tree4a6d8773945d43ef8db4b8e8b298be306c822081
parent04ccbd09b1f9369949b89b4815752d08a0ca9786 (diff)
downloadaerc-9570f4b4d0cdf525ce1695971636a0b58f1a091b.tar.gz
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.
-rw-r--r--widgets/account.go2
-rw-r--r--widgets/msglist.go46
2 files changed, 33 insertions, 15 deletions
diff --git a/widgets/account.go b/widgets/account.go
index de81ab8..07b5010 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -147,6 +147,8 @@ func (acct *AccountView) connected(msg types.WorkerMessage) {
 			if dir != "" {
 				acct.dirlist.Select(dir)
 			}
+
+			acct.msglist.SetInitDone()
 			acct.logger.Println("Connected.")
 			acct.host.SetStatus("Connected.")
 		})
diff --git a/widgets/msglist.go b/widgets/msglist.go
index abf6921..9900a32 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -16,20 +16,22 @@ import (
 
 type MessageList struct {
 	ui.Invalidatable
-	conf    *config.AercConfig
-	logger  *log.Logger
-	height  int
-	scroll  int
-	nmsgs   int
-	spinner *Spinner
-	store   *lib.MessageStore
+	conf          *config.AercConfig
+	logger        *log.Logger
+	height        int
+	scroll        int
+	nmsgs         int
+	spinner       *Spinner
+	store         *lib.MessageStore
+	isInitalizing bool
 }
 
 func NewMessageList(conf *config.AercConfig, logger *log.Logger) *MessageList {
 	ml := &MessageList{
-		conf:    conf,
-		logger:  logger,
-		spinner: NewSpinner(),
+		conf:          conf,
+		logger:        logger,
+		spinner:       NewSpinner(),
+		isInitalizing: true,
 	}
 	ml.spinner.OnInvalidate(func(_ ui.Drawable) {
 		ml.Invalidate()
@@ -49,8 +51,14 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
 
 	store := ml.Store()
 	if store == nil {
-		ml.spinner.Draw(ctx)
-		return
+		if ml.isInitalizing {
+			ml.spinner.Draw(ctx)
+			return
+		} else {
+			ml.spinner.Stop()
+			ml.drawEmptyMessage(ctx)
+			return
+		}
 	}
 
 	var (
@@ -111,9 +119,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
 	}
 
 	if len(uids) == 0 {
-		msg := ml.conf.Ui.EmptyMessage
-		ctx.Printf((ctx.Width()/2)-(len(msg)/2), 0,
-			tcell.StyleDefault, "%s", msg)
+		ml.drawEmptyMessage(ctx)
 	}
 
 	if len(needsHeaders) != 0 {
@@ -171,6 +177,10 @@ func (ml *MessageList) SetStore(store *lib.MessageStore) {
 	ml.Invalidate()
 }
 
+func (ml *MessageList) SetInitDone() {
+	ml.isInitalizing = false
+}
+
 func (ml *MessageList) Store() *lib.MessageStore {
 	return ml.store
 }
@@ -209,3 +219,9 @@ func (ml *MessageList) Scroll() {
 	}
 	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)
+}
> 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456