mirror of
https://git.sr.ht/~rjarry/aerc
synced 2026-03-02 18:23:33 +01:00
Add a new models.UID type (an alias to string). Replace all occurrences of uint32 being used as message UID or thread UID with models.UID. Update all workers to only expose models.UID values and deal with the conversion internally. Only IMAP needs to convert these to uint32. All other backends already use plain strings as message identifiers, in which case no conversion is even needed. The directory tree implementation needed to be heavily refactored in order to accommodate thread UID not being usable as a list index. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net> Tested-by: Tim Culverhouse <tim@timculverhouse.com>
127 lines
2.2 KiB
Go
127 lines
2.2 KiB
Go
package iterator
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"git.sr.ht/~rjarry/aerc/models"
|
|
"git.sr.ht/~rjarry/aerc/worker/types"
|
|
)
|
|
|
|
// defaultFactory
|
|
type defaultFactory struct{}
|
|
|
|
func (df *defaultFactory) NewIterator(a interface{}) Iterator {
|
|
switch data := a.(type) {
|
|
case []models.UID:
|
|
return &defaultUid{data: data, index: len(data)}
|
|
case []*types.Thread:
|
|
return &defaultThread{data: data, index: len(data)}
|
|
}
|
|
panic(errors.New("a iterator for this type is not implemented yet"))
|
|
}
|
|
|
|
// defaultUid
|
|
type defaultUid struct {
|
|
data []models.UID
|
|
index int
|
|
}
|
|
|
|
func (du *defaultUid) Next() bool {
|
|
du.index--
|
|
return du.index >= 0
|
|
}
|
|
|
|
func (du *defaultUid) Value() interface{} {
|
|
return du.data[du.index]
|
|
}
|
|
|
|
func (du *defaultUid) StartIndex() int {
|
|
return len(du.data) - 1
|
|
}
|
|
|
|
func (du *defaultUid) EndIndex() int {
|
|
return 0
|
|
}
|
|
|
|
// defaultThread
|
|
type defaultThread struct {
|
|
data []*types.Thread
|
|
index int
|
|
}
|
|
|
|
func (dt *defaultThread) Next() bool {
|
|
dt.index--
|
|
return dt.index >= 0
|
|
}
|
|
|
|
func (dt *defaultThread) Value() interface{} {
|
|
return dt.data[dt.index]
|
|
}
|
|
|
|
func (dt *defaultThread) StartIndex() int {
|
|
return len(dt.data) - 1
|
|
}
|
|
|
|
func (dt *defaultThread) EndIndex() int {
|
|
return 0
|
|
}
|
|
|
|
// reverseFactory
|
|
type reverseFactory struct{}
|
|
|
|
func (rf *reverseFactory) NewIterator(a interface{}) Iterator {
|
|
switch data := a.(type) {
|
|
case []models.UID:
|
|
return &reverseUid{data: data, index: -1}
|
|
case []*types.Thread:
|
|
return &reverseThread{data: data, index: -1}
|
|
}
|
|
panic(errors.New("an iterator for this type is not implemented yet"))
|
|
}
|
|
|
|
// reverseUid
|
|
type reverseUid struct {
|
|
data []models.UID
|
|
index int
|
|
}
|
|
|
|
func (ru *reverseUid) Next() bool {
|
|
ru.index++
|
|
return ru.index < len(ru.data)
|
|
}
|
|
|
|
func (ru *reverseUid) Value() interface{} {
|
|
return ru.data[ru.index]
|
|
}
|
|
|
|
func (ru *reverseUid) StartIndex() int {
|
|
return 0
|
|
}
|
|
|
|
func (ru *reverseUid) EndIndex() int {
|
|
return len(ru.data) - 1
|
|
}
|
|
|
|
// reverseThread
|
|
type reverseThread struct {
|
|
data []*types.Thread
|
|
index int
|
|
}
|
|
|
|
func (rt *reverseThread) Next() bool {
|
|
rt.index++
|
|
return rt.index < len(rt.data)
|
|
}
|
|
|
|
func (rt *reverseThread) Value() interface{} {
|
|
return rt.data[rt.index]
|
|
}
|
|
|
|
func (rt *reverseThread) StartIndex() int {
|
|
return 0
|
|
}
|
|
|
|
func (rt *reverseThread) EndIndex() int {
|
|
return len(rt.data) - 1
|
|
}
|