aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-12-21 17:01:37 -0600
committerMoritz Poldrack <git@moritz.sh>2022-12-25 18:11:08 +0100
commit6b8e0b19d35a4aa3e1d300f4d25a463755589c6e (patch)
tree73bc22b6b7b349694ab7b3a145f83a24122533f2 /lib
parenta4d7b5fc96bc2b28a18400f127b710464a143067 (diff)
downloadaerc-6b8e0b19d35a4aa3e1d300f4d25a463755589c6e.tar.gz
split: refactor to prevent stuck splits
Refactor split logic (again...) to prevent stuck splits. Use callback from msgstore.Select to tell the split which message to display. This keeps the account from having to track displayed messages, which prevents race conditions in certain situations. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/messageview.go6
-rw-r--r--lib/msgstore.go14
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/messageview.go b/lib/messageview.go
index d7ff1908..d0754cc1 100644
--- a/lib/messageview.go
+++ b/lib/messageview.go
@@ -72,6 +72,12 @@ func NewMessageStoreView(messageInfo *models.MessageInfo, setSeen bool,
store *MessageStore, pgp crypto.Provider, decryptKeys openpgp.PromptFunction,
cb func(MessageView, error),
) {
+ if messageInfo == nil {
+ // Call nils to the callback, the split view will use this to
+ // display an empty view
+ cb(nil, nil)
+ return
+ }
msv := &MessageStoreView{
messageInfo, store,
nil, nil, messageInfo.BodyStructure,
diff --git a/lib/msgstore.go b/lib/msgstore.go
index c02d8f4d..1a56b2c8 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -69,6 +69,7 @@ type MessageStore struct {
threadsMutex sync.Mutex
iterFactory iterator.Factory
+ onSelect func(*models.MessageInfo)
}
const MagicUid = 0xFFFFFFFF
@@ -79,7 +80,7 @@ func NewMessageStore(worker *types.Worker,
thread bool, clientThreads bool, clientThreadsDelay time.Duration,
reverseOrder bool, reverseThreadOrder bool, sortThreadSiblings bool,
triggerNewEmail func(*models.MessageInfo),
- triggerDirectoryChange func(),
+ triggerDirectoryChange func(), onSelect func(*models.MessageInfo),
) *MessageStore {
if !dirInfo.Caps.Thread {
clientThreads = true
@@ -116,6 +117,7 @@ func NewMessageStore(worker *types.Worker,
threadBuilderDelay: clientThreadsDelay,
iterFactory: iterator.NewFactory(reverseOrder),
+ onSelect: onSelect,
}
}
@@ -257,6 +259,9 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
merge(existing, msg.Info)
} else if msg.Info.Envelope != nil {
store.Messages[msg.Info.Uid] = msg.Info
+ if store.selectedUid == msg.Info.Uid {
+ store.onSelect(msg.Info)
+ }
}
if msg.NeedsFlags {
store.Lock()
@@ -597,7 +602,7 @@ func (store *MessageStore) Selected() *models.MessageInfo {
func (store *MessageStore) SelectedUid() uint32 {
if store.selectedUid == MagicUid && len(store.Uids()) > 0 {
iter := store.UidsIterator()
- store.selectedUid = store.Uids()[iter.StartIndex()]
+ store.Select(store.Uids()[iter.StartIndex()])
}
return store.selectedUid
}
@@ -612,6 +617,9 @@ func (store *MessageStore) Select(uid uint32) {
if store.marker != nil {
store.marker.UpdateVisualMark()
}
+ if store.onSelect != nil {
+ store.onSelect(store.Selected())
+ }
}
func (store *MessageStore) NextPrev(delta int) {
@@ -639,7 +647,7 @@ func (store *MessageStore) NextPrev(delta int) {
store.threadsMutex.Lock()
store.threadCallback = func() {
if uids := store.Uids(); len(uids) > newIdx {
- store.selectedUid = uids[newIdx]
+ store.Select(uids[newIdx])
}
}
store.threadsMutex.Unlock()