diff options
author | Tristan Partin <tristan@partin.io> | 2024-05-20 21:49:24 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-05-28 23:52:39 +0200 |
commit | 9f97c698e3dd8bb98242f0db40946dee514e3ee8 (patch) | |
tree | 8622fe152a60ef9d3879f333cd443fb1b7c6f1e6 /worker/jmap/cache | |
parent | f9113810cc6cace71ab4dc506f1b106e4ae9f8dd (diff) | |
download | aerc-9f97c698e3dd8bb98242f0db40946dee514e3ee8.tar.gz |
jmap: fetch entire threads
JMAP was missing good thread support, especially when compared to Gmail.
This will fetch entire threads when possible.
Signed-off-by: Tristan Partin <tristan@partin.io>
Diffstat (limited to 'worker/jmap/cache')
-rw-r--r-- | worker/jmap/cache/gob.go | 2 | ||||
-rw-r--r-- | worker/jmap/cache/state.go | 13 | ||||
-rw-r--r-- | worker/jmap/cache/thread.go | 35 |
3 files changed, 50 insertions, 0 deletions
diff --git a/worker/jmap/cache/gob.go b/worker/jmap/cache/gob.go index f1b8be33..8b153c50 100644 --- a/worker/jmap/cache/gob.go +++ b/worker/jmap/cache/gob.go @@ -6,10 +6,12 @@ import ( "git.sr.ht/~rockorager/go-jmap/mail/email" "git.sr.ht/~rockorager/go-jmap/mail/mailbox" + "git.sr.ht/~rockorager/go-jmap/mail/thread" ) type jmapObject interface { *email.Email | + *thread.Thread | *email.QueryResponse | *mailbox.Mailbox | *FolderContents | diff --git a/worker/jmap/cache/state.go b/worker/jmap/cache/state.go index 5fec5034..6538ccad 100644 --- a/worker/jmap/cache/state.go +++ b/worker/jmap/cache/state.go @@ -12,6 +12,18 @@ func (c *JMAPCache) PutMailboxState(state string) error { return c.put(mailboxStateKey, []byte(state)) } +func (c *JMAPCache) GetThreadState() (string, error) { + buf, err := c.get(threadStateKey) + if err != nil { + return "", err + } + return string(buf), nil +} + +func (c *JMAPCache) PutThreadState(state string) error { + return c.put(threadStateKey, []byte(state)) +} + func (c *JMAPCache) GetEmailState() (string, error) { buf, err := c.get(emailStateKey) if err != nil { @@ -27,4 +39,5 @@ func (c *JMAPCache) PutEmailState(state string) error { const ( mailboxStateKey = "state/mailbox" emailStateKey = "state/email" + threadStateKey = "state/thread" ) diff --git a/worker/jmap/cache/thread.go b/worker/jmap/cache/thread.go new file mode 100644 index 00000000..ca91a4d9 --- /dev/null +++ b/worker/jmap/cache/thread.go @@ -0,0 +1,35 @@ +package cache + +import ( + "git.sr.ht/~rockorager/go-jmap" + "git.sr.ht/~rockorager/go-jmap/mail/thread" +) + +func (c *JMAPCache) GetThread(id jmap.ID) (*thread.Thread, error) { + buf, err := c.get(threadKey(id)) + if err != nil { + return nil, err + } + e := new(thread.Thread) + err = unmarshal(buf, e) + if err != nil { + return nil, err + } + return e, nil +} + +func (c *JMAPCache) PutThread(id jmap.ID, e *thread.Thread) error { + buf, err := marshal(e) + if err != nil { + return err + } + return c.put(threadKey(id), buf) +} + +func (c *JMAPCache) DeleteThread(id jmap.ID) error { + return c.delete(threadKey(id)) +} + +func threadKey(id jmap.ID) string { + return "thread/" + string(id) +} |