From 46ea87602c092750984307e4f31200ad3b9d7fe4 Mon Sep 17 00:00:00 2001 From: Nicolas Dichtel Date: Thu, 15 Feb 2024 15:36:39 +0100 Subject: store: fix split view blinking When split view and threading mode are enabled, the message is blinking. First, since commit ddfa5cac1fe9 ("msgstore: fix deadlock in thread builder"), the threadCallback is never set to nil: the thread builder calls it continuously. After setting it to nil, the message is still blinking once. To avoid this, don't call the onSelect method (which points to AccountView.updateSplitView()) from the thread builder: the message is already displayed. Let's rewrite Select and selectPriv: - Select(): it takes the lock and calls the onSelect callback; - selectPriv: the assumption is that the lock is held. It doesn't call the onSelect callback. This function is only used by the thread builder. Fixes: 588be1a28422 ("store: improve cursor position") Fixes: ddfa5cac1fe9 ("msgstore: fix deadlock in thread builder") Signed-off-by: Nicolas Dichtel Acked-by: Robin Jarry --- lib/msgstore.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/msgstore.go b/lib/msgstore.go index 33daa9ff..274e42ba 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -718,22 +718,26 @@ func (store *MessageStore) SelectedUid() uint32 { } func (store *MessageStore) Select(uid uint32) { - store.threadsMutex.Lock() - if store.threadCallback != nil { - store.threadCallback = nil + store.selectPriv(uid, false) + if store.onSelect != nil { + store.onSelect(store.Selected()) } - store.threadsMutex.Unlock() - store.selectPriv(uid) } -func (store *MessageStore) selectPriv(uid uint32) { +func (store *MessageStore) selectPriv(uid uint32, lockHeld bool) { + if !lockHeld { + store.threadsMutex.Lock() + } + if store.threadCallback != nil { + store.threadCallback = nil + } + if !lockHeld { + store.threadsMutex.Unlock() + } store.selectedUid = uid if store.marker != nil { store.marker.UpdateVisualMark() } - if store.onSelect != nil { - store.onSelect(store.Selected()) - } } func (store *MessageStore) NextPrev(delta int) { @@ -761,7 +765,7 @@ func (store *MessageStore) NextPrev(delta int) { store.threadsMutex.Lock() store.threadCallback = func() { if uids := store.Uids(); len(uids) > newIdx { - store.selectPriv(uids[newIdx]) + store.selectPriv(uids[newIdx], true) } } store.threadsMutex.Unlock() -- cgit