threading: add backend capabilities to workers
This patch provides a method to report backend capabilities to the UI. The intial capabilities included in the report are Sort and Thread. Having these available to the UI enables the client to better handle server side threading. Signed-off-by: Koni Marti <koni.marti@gmail.com> Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
a8879d79c6
commit
f0c76fad72
|
@ -51,6 +51,15 @@ type DirectoryInfo struct {
|
|||
|
||||
// set to true if the value counts are accurate
|
||||
AccurateCounts bool
|
||||
|
||||
// Caps contains the backend capabilities
|
||||
Caps *Capabilities
|
||||
}
|
||||
|
||||
// Capabilities provides the backend capabilities
|
||||
type Capabilities struct {
|
||||
Sort bool
|
||||
Thread bool
|
||||
}
|
||||
|
||||
// A MessageInfo holds information about the structure of a message
|
||||
|
|
|
@ -31,6 +31,7 @@ func (w *IMAPWorker) handleCheckMailMessage(msg *types.CheckMail) {
|
|||
Exists: int(status.Messages),
|
||||
Recent: int(status.Recent),
|
||||
Unseen: int(status.Unseen),
|
||||
Caps: w.caps,
|
||||
},
|
||||
SkipSort: true,
|
||||
}, nil)
|
||||
|
|
|
@ -66,6 +66,8 @@ type IMAPWorker struct {
|
|||
idler *idler
|
||||
observer *observer
|
||||
cache *leveldb.DB
|
||||
|
||||
caps *models.Capabilities
|
||||
}
|
||||
|
||||
func NewIMAPWorker(worker *types.Worker) (types.Backend, error) {
|
||||
|
@ -75,6 +77,7 @@ func NewIMAPWorker(worker *types.Worker) (types.Backend, error) {
|
|||
selected: &imap.MailboxStatus{},
|
||||
idler: newIdler(imapConfig{}, worker),
|
||||
observer: newObserver(imapConfig{}, worker),
|
||||
caps: &models.Capabilities{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -83,6 +86,16 @@ func (w *IMAPWorker) newClient(c *client.Client) {
|
|||
w.client = &imapClient{c, sortthread.NewThreadClient(c), sortthread.NewSortClient(c)}
|
||||
w.idler.SetClient(w.client)
|
||||
w.observer.SetClient(w.client)
|
||||
sort, err := w.client.sort.SupportSort()
|
||||
if err == nil && sort {
|
||||
w.caps.Sort = true
|
||||
w.worker.Logger.Println("Server Capability found: Sort")
|
||||
}
|
||||
thread, err := w.client.thread.SupportThread()
|
||||
if err == nil && thread {
|
||||
w.caps.Thread = true
|
||||
w.worker.Logger.Println("Server Capability found: Thread")
|
||||
}
|
||||
}
|
||||
|
||||
func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
|
||||
|
@ -226,6 +239,7 @@ func (w *IMAPWorker) handleImapUpdate(update client.Update) {
|
|||
Exists: int(status.Messages),
|
||||
Recent: int(status.Recent),
|
||||
Unseen: int(status.Unseen),
|
||||
Caps: w.caps,
|
||||
},
|
||||
}, nil)
|
||||
case *client.MessageUpdate:
|
||||
|
|
|
@ -186,6 +186,11 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo {
|
|||
Unseen: 0,
|
||||
|
||||
AccurateCounts: false,
|
||||
|
||||
Caps: &models.Capabilities{
|
||||
Sort: true,
|
||||
Thread: false,
|
||||
},
|
||||
}
|
||||
|
||||
dir := w.c.Dir(name)
|
||||
|
|
|
@ -228,6 +228,11 @@ func (w *worker) gatherDirectoryInfo(name string, query string) (
|
|||
// total unread
|
||||
Unseen: count.Unread,
|
||||
AccurateCounts: true,
|
||||
|
||||
Caps: &models.Capabilities{
|
||||
Sort: true,
|
||||
Thread: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
return info, nil
|
||||
|
|
Loading…
Reference in New Issue