From f5c9f2d0111527b5d5d2efed2e94a01b9f382709 Mon Sep 17 00:00:00 2001 From: cos Date: Tue, 26 Jul 2022 20:38:24 +0200 Subject: fixup: Hack up message list to be sorted ascending An attempt at making ascending or descending message list configurable. Seems to work for me, but a proper take on this might need to involve having to rethink what configuration options to present and how direct they map towards the operations happening under the hood. --- config/config.go | 1 + lib/msgstore.go | 26 ++++++++++++++++++++++---- lib/threadbuilder.go | 6 +----- widgets/account.go | 1 + widgets/msglist.go | 8 +++++++- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/config/config.go b/config/config.go index e0c8608..e9ae56e 100644 --- a/config/config.go +++ b/config/config.go @@ -61,6 +61,7 @@ type UIConfig struct { DirListDelay time.Duration `ini:"dirlist-delay"` DirListTree bool `ini:"dirlist-tree"` Sort []string `delim:" "` + MsgListOrdAscending bool `ini:"msglist-ascending"` NextMessageOnDelete bool `ini:"next-message-on-delete"` CompletionDelay time.Duration `ini:"completion-delay"` CompletionPopovers bool `ini:"completion-popovers"` diff --git a/lib/msgstore.go b/lib/msgstore.go index 4aaad82..a99259e 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -15,6 +15,7 @@ type MessageStore struct { DirInfo models.DirectoryInfo Messages map[uint32]*models.MessageInfo Sorting bool + OrdAsc bool // Ordered list of known UIDs uids []uint32 @@ -60,6 +61,7 @@ type MessageStore struct { func NewMessageStore(worker *types.Worker, dirInfo *models.DirectoryInfo, defaultSortCriteria []*types.SortCriterion, + ascending bool, thread bool, clientThreads bool, triggerNewEmail func(*models.MessageInfo), triggerDirectoryChange func()) *MessageStore { @@ -74,6 +76,7 @@ func NewMessageStore(worker *types.Worker, Deleted: make(map[uint32]interface{}), DirInfo: *dirInfo, Messages: make(map[uint32]*models.MessageInfo), + OrdAsc: ascending, selected: 0, marked: make(map[uint32]struct{}), @@ -225,10 +228,20 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { var uids []uint32 newMap := make(map[uint32]*models.MessageInfo) - for i := len(msg.Threads) - 1; i >= 0; i-- { - msg.Threads[i].Walk(func(t *types.Thread, level int, currentErr error) error { + for i := 0; i < len(msg.Threads); i++ { + var j = 0 + if store.OrdAsc { + j = i + } else { + j = len(msg.Threads) - i - 1 + } + msg.Threads[j].Walk(func(t *types.Thread, level int, currentErr error) error { uid := t.Uid - uids = append([]uint32{uid}, uids...) + if store.OrdAsc { + uids = append(uids, uid) + } else { + uids = append([]uint32{uid}, uids...) + } if msg, ok := store.Messages[uid]; ok { newMap[uid] = msg } else { @@ -491,7 +504,12 @@ func (store *MessageStore) Uids() []uint32 { func (store *MessageStore) Selected() *models.MessageInfo { uids := store.Uids() - idx := store.selected + var idx = 0 + if store.OrdAsc { + idx = store.selected + } else { + idx = len(uids) - store.selected - 1 + } if len(uids) == 0 || idx < 0 || idx >= len(uids) { return nil } diff --git a/lib/threadbuilder.go b/lib/threadbuilder.go index 334a846..a1954cb 100644 --- a/lib/threadbuilder.go +++ b/lib/threadbuilder.go @@ -145,16 +145,12 @@ func (builder *ThreadBuilder) sortThreads(threads []*types.Thread, orderedUids [ // RebuildUids rebuilds the uids from the given slice of threads func (builder *ThreadBuilder) RebuildUids(threads []*types.Thread) { uids := make([]uint32, 0, len(threads)) - for i := len(threads) - 1; i >= 0; i-- { + for i := 0; i < len(threads); i++ { threads[i].Walk(func(t *types.Thread, level int, currentErr error) error { uids = append(uids, t.Uid) return nil }) } - // copy in reverse as msgList displays backwards - for i, j := 0, len(uids)-1; i < j; i, j = i+1, j-1 { - uids[i], uids[j] = uids[j], uids[i] - } builder.threadedUids = uids } diff --git a/widgets/account.go b/widgets/account.go index 6e03160..75373aa 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -294,6 +294,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { } else { store = lib.NewMessageStore(acct.worker, msg.Info, acct.GetSortCriteria(), + acct.UiConfig().MsgListOrdAscending, acct.UiConfig().ThreadingEnabled, acct.UiConfig().ForceClientThreads, func(msg *models.MessageInfo) { diff --git a/widgets/msglist.go b/widgets/msglist.go index 395fb54..c1bf0f4 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -93,8 +93,14 @@ func (ml *MessageList) Draw(ctx *ui.Context) { counter := len(store.Uids()) for i := 0; i < len(threads); i++ { + var j = 0 + if ml.conf.Ui.MsgListOrdAscending { + j = i + } else { + j = len(threads) - i - 1 + } var lastSubject string - threads[i].Walk(func(t *types.Thread, _ int, currentErr error) error { + threads[j].Walk(func(t *types.Thread, _ int, currentErr error) error { if currentErr != nil { return currentErr } -- cgit v1.2.3