threading: enable toggle-threads for server-side threads

Enable the :toggle-threads command to work for workers which have Thread
capability. The implementation of that feature has the side effect that
the threading-enabled config option now sets the default view (threaded
or not threaded) for any worker, not just IMAP or notmuch.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-07-05 14:48:38 -05:00 committed by Robin Jarry
parent f0c76fad72
commit 3a614e45fc
5 changed files with 28 additions and 31 deletions

View File

@ -35,8 +35,8 @@ func (ToggleThreads) Execute(aerc *widgets.Aerc, args []string) error {
return err return err
} }
defer store.Reselect(store.Selected()) defer store.Reselect(store.Selected())
store.SetBuildThreads(!store.BuildThreads()) store.SetThreadedView(!store.ThreadedView())
acct.SetStatus(statusline.Threading(store.BuildThreads())) acct.SetStatus(statusline.Threading(store.ThreadedView()))
acct.Messages().Invalidate() acct.Messages().Invalidate()
return nil return nil
} }

View File

@ -168,10 +168,8 @@ completion-popovers=true
#[ui:account=foo] #[ui:account=foo]
# #
# Enable threading in the ui. Only works with notmuch:// and imap:// accounts # Enable a threaded view of messages. If this is not supported by the backend
# (when the server supports it). If this is not supported by the server, # (IMAP server or notmuch), threads will be built by the client.
# you can enable it on the fly by issuing the :toggle-threads command. The
# threading will be done client side instead of on the server.
# #
# Default: false # Default: false
#threading-enabled=false #threading-enabled=false

View File

@ -295,15 +295,8 @@ These options are configured in the *[ui]* section of aerc.conf.
need not be consecutive characters in the command or option. need not be consecutive characters in the command or option.
*threading-enabled* *threading-enabled*
Enable a threaded viewing of messages, works with IMAP (when there's Enable a threaded view of messages. If this is not supported by the
server support) and NotMuch backends. backend (IMAP server or notmuch), threads will be built by the client.
This option should only be set to true for specific accounts
accordingly. See *Contextual UI Configuration* below.
If this is not supported by the server, you can enable it on the fly by
issuing the _:toggle-threads_ command. The threading will be done client
side instead of on the server.
Default: false Default: false

View File

@ -38,7 +38,7 @@ type MessageStore struct {
sortCriteria []*types.SortCriterion sortCriteria []*types.SortCriterion
thread bool threadedView bool
buildThreads bool buildThreads bool
builder *ThreadBuilder builder *ThreadBuilder
@ -66,6 +66,11 @@ func NewMessageStore(worker *types.Worker,
dirInfoUpdateDelay := 5 * time.Second dirInfoUpdateDelay := 5 * time.Second
var clientThreads bool
if !dirInfo.Caps.Thread {
clientThreads = true
}
return &MessageStore{ return &MessageStore{
Deleted: make(map[uint32]interface{}), Deleted: make(map[uint32]interface{}),
DirInfo: *dirInfo, DirInfo: *dirInfo,
@ -76,7 +81,8 @@ func NewMessageStore(worker *types.Worker,
bodyCallbacks: make(map[uint32][]func(*types.FullMessage)), bodyCallbacks: make(map[uint32][]func(*types.FullMessage)),
headerCallbacks: make(map[uint32][]func(*types.MessageInfo)), headerCallbacks: make(map[uint32][]func(*types.MessageInfo)),
thread: thread, threadedView: thread,
buildThreads: clientThreads,
sortCriteria: defaultSortCriteria, sortCriteria: defaultSortCriteria,
@ -361,22 +367,22 @@ func (store *MessageStore) update() {
} }
} }
func (store *MessageStore) SetBuildThreads(buildThreads bool) { func (store *MessageStore) SetThreadedView(thread bool) {
// if worker provides threading, don't build our own threads store.threadedView = thread
if store.thread { if store.buildThreads {
return if store.threadedView {
}
store.buildThreads = buildThreads
if store.BuildThreads() {
store.runThreadBuilder() store.runThreadBuilder()
} }
return
}
store.Sort(store.sortCriteria, nil)
}
func (store *MessageStore) ThreadedView() bool {
return store.threadedView
} }
func (store *MessageStore) BuildThreads() bool { func (store *MessageStore) BuildThreads() bool {
// if worker provides threading, don't build our own threads
if store.thread {
return false
}
return store.buildThreads return store.buildThreads
} }
@ -486,7 +492,7 @@ func (store *MessageStore) Answered(uids []uint32, answered bool,
func (store *MessageStore) Uids() []uint32 { func (store *MessageStore) Uids() []uint32 {
if store.BuildThreads() && store.builder != nil { if store.ThreadedView() && store.builder != nil {
if uids := store.builder.Uids(); len(uids) > 0 { if uids := store.builder.Uids(); len(uids) > 0 {
return uids return uids
} }
@ -802,7 +808,7 @@ func (store *MessageStore) Sort(criteria []*types.SortCriterion, cb func()) {
} }
} }
if store.thread { if store.threadedView && !store.buildThreads {
store.worker.PostAction(&types.FetchDirectoryThreaded{ store.worker.PostAction(&types.FetchDirectoryThreaded{
SortCriteria: criteria, SortCriteria: criteria,
}, handle_return) }, handle_return)

View File

@ -88,7 +88,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
row int = 0 row int = 0
) )
if uiConfig.ThreadingEnabled || store.BuildThreads() { if store.ThreadedView() {
threads := store.Threads threads := store.Threads
counter := len(store.Uids()) counter := len(store.Uids())