diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/msgstore.go | 26 | ||||
-rw-r--r-- | lib/threadbuilder.go | 6 |
2 files changed, 23 insertions, 9 deletions
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 } |