Debian Codegraph @

worker/jmap/cache/folder_contents.go

raw
1 package cache
2
3 import (
4 "reflect"
5
6 "git.sr.ht/~rjarry/aerc/lib/log"
7 "git.sr.ht/~rjarry/aerc/worker/types"
8 "git.sr.ht/~rockorager/go-jmap"
9 )
10
11 type FolderContents struct {
12 MailboxID jmap.ID
13 QueryState string
14 Filter *types.SearchCriteria
15 Sort []*types.SortCriterion
16 MessageIDs []jmap.ID
17 }
18
19 func (c *JMAPCache) GetFolderContents(mailboxId jmap.ID) (*FolderContents, error) {
20 key := folderContentsKey(mailboxId)
21 buf, err := c.get(key)
22 if err != nil {
23 return nil, err
24 }
25 m := new(FolderContents)
26 err = unmarshal(buf, m)
27 if err != nil {
28 log.Debugf("cache format has changed, purging foldercontents")
29 if e := c.purge("foldercontents/"); e != nil {
30 log.Errorf("foldercontents cache purge: %s", e)
31 }
32 return nil, err
33 }
34 return m, nil
35 }
36
37 func (c *JMAPCache) PutFolderContents(mailboxId jmap.ID, m *FolderContents) error {
38 buf, err := marshal(m)
39 if err != nil {
40 return err
41 }
42 return c.put(folderContentsKey(mailboxId), buf)
43 }
44
45 func (c *JMAPCache) DeleteFolderContents(mailboxId jmap.ID) error {
46 return c.delete(folderContentsKey(mailboxId))
47 }
48
49 func folderContentsKey(mailboxId jmap.ID) string {
50 return "foldercontents/" + string(mailboxId)
51 }
52
53 func (f *FolderContents) NeedsRefresh(
54 filter *types.SearchCriteria, sort []*types.SortCriterion,
55 ) bool {
56 return f.QueryState == "" ||
57 !reflect.DeepEqual(f.Sort, sort) ||
58 !reflect.DeepEqual(f.Filter, filter)
59 }