aboutsummaryrefslogtreecommitdiffstats
path: root/worker/notmuch/worker.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2024-08-14 16:59:11 +0200
committerRobin Jarry <robin@jarry.cc>2024-08-28 12:06:01 +0200
commit73dc39c6ee0827fc68b93af8dc438b0e1c14e929 (patch)
treeaff067600ea6326ff179447ed968b6712013b889 /worker/notmuch/worker.go
parent2950d919a5c5a55bd0eb53d6c41f989d8b70bd55 (diff)
downloadaerc-73dc39c6ee0827fc68b93af8dc438b0e1c14e929.tar.gz
treewide: replace uint32 uids with opaque strings
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>
Diffstat (limited to 'worker/notmuch/worker.go')
-rw-r--r--worker/notmuch/worker.go28
1 files changed, 11 insertions, 17 deletions
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go
index 06c0cde6..8c954a61 100644
--- a/worker/notmuch/worker.go
+++ b/worker/notmuch/worker.go
@@ -457,27 +457,21 @@ func (w *worker) handleFetchMessageHeaders(
return nil
}
-func (w *worker) uidsFromQuery(ctx context.Context, query string) ([]uint32, error) {
+func (w *worker) uidsFromQuery(ctx context.Context, query string) ([]models.UID, error) {
msgIDs, err := w.db.MsgIDsFromQuery(ctx, query)
if err != nil {
return nil, err
}
- var uids []uint32
+ var uids []models.UID
for _, id := range msgIDs {
- uid := w.db.UidFromKey(id)
- uids = append(uids, uid)
-
+ uids = append(uids, models.UID(id))
}
return uids, nil
}
-func (w *worker) msgFromUid(uid uint32) (*Message, error) {
- key, ok := w.db.KeyFromUid(uid)
- if !ok {
- return nil, fmt.Errorf("Invalid uid: %v", uid)
- }
+func (w *worker) msgFromUid(uid models.UID) (*Message, error) {
msg := &Message{
- key: key,
+ key: string(uid),
uid: uid,
db: w.db,
}
@@ -613,7 +607,7 @@ func (w *worker) handleModifyLabels(msg *types.ModifyLabels) error {
for _, uid := range msg.Uids {
m, err := w.msgFromUid(uid)
if err != nil {
- return fmt.Errorf("could not get message from uid %d: %w", uid, err)
+ return fmt.Errorf("could not get message from uid %s: %w", uid, err)
}
err = m.ModifyTags(msg.Add, msg.Remove)
if err != nil {
@@ -699,7 +693,7 @@ func (w *worker) emitDirectoryThreaded(parent types.WorkerMessage) error {
return nil
}
-func (w *worker) emitMessageInfoError(msg types.WorkerMessage, uid uint32, err error) {
+func (w *worker) emitMessageInfoError(msg types.WorkerMessage, uid models.UID, err error) {
w.w.PostMessage(&types.MessageInfo{
Info: &models.MessageInfo{
Envelope: &models.Envelope{},
@@ -743,9 +737,9 @@ func (w *worker) emitLabelList() {
w.w.PostMessage(&types.LabelList{Labels: tags}, nil)
}
-func (w *worker) sort(uids []uint32,
+func (w *worker) sort(uids []models.UID,
criteria []*types.SortCriterion,
-) ([]uint32, error) {
+) ([]models.UID, error) {
if len(criteria) == 0 {
return uids, nil
}
@@ -796,7 +790,7 @@ func (w *worker) handleDeleteMessages(msg *types.DeleteMessages) error {
return errUnsupported
}
- var deleted []uint32
+ var deleted []models.UID
folders, _ := w.store.FolderMap()
curDir := folders[w.currentQueryName]
@@ -874,7 +868,7 @@ func (w *worker) handleMoveMessages(msg *types.MoveMessages) error {
return errUnsupported
}
- var moved []uint32
+ var moved []models.UID
folders, _ := w.store.FolderMap()