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
5 changed files with 34 additions and 0 deletions
|
@ -51,6 +51,15 @@ type DirectoryInfo struct {
|
||||||
|
|
||||||
// set to true if the value counts are accurate
|
// set to true if the value counts are accurate
|
||||||
AccurateCounts bool
|
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
|
// 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),
|
Exists: int(status.Messages),
|
||||||
Recent: int(status.Recent),
|
Recent: int(status.Recent),
|
||||||
Unseen: int(status.Unseen),
|
Unseen: int(status.Unseen),
|
||||||
|
Caps: w.caps,
|
||||||
},
|
},
|
||||||
SkipSort: true,
|
SkipSort: true,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
|
@ -66,6 +66,8 @@ type IMAPWorker struct {
|
||||||
idler *idler
|
idler *idler
|
||||||
observer *observer
|
observer *observer
|
||||||
cache *leveldb.DB
|
cache *leveldb.DB
|
||||||
|
|
||||||
|
caps *models.Capabilities
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIMAPWorker(worker *types.Worker) (types.Backend, error) {
|
func NewIMAPWorker(worker *types.Worker) (types.Backend, error) {
|
||||||
|
@ -75,6 +77,7 @@ func NewIMAPWorker(worker *types.Worker) (types.Backend, error) {
|
||||||
selected: &imap.MailboxStatus{},
|
selected: &imap.MailboxStatus{},
|
||||||
idler: newIdler(imapConfig{}, worker),
|
idler: newIdler(imapConfig{}, worker),
|
||||||
observer: newObserver(imapConfig{}, worker),
|
observer: newObserver(imapConfig{}, worker),
|
||||||
|
caps: &models.Capabilities{},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +86,16 @@ func (w *IMAPWorker) newClient(c *client.Client) {
|
||||||
w.client = &imapClient{c, sortthread.NewThreadClient(c), sortthread.NewSortClient(c)}
|
w.client = &imapClient{c, sortthread.NewThreadClient(c), sortthread.NewSortClient(c)}
|
||||||
w.idler.SetClient(w.client)
|
w.idler.SetClient(w.client)
|
||||||
w.observer.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 {
|
func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
|
||||||
|
@ -226,6 +239,7 @@ func (w *IMAPWorker) handleImapUpdate(update client.Update) {
|
||||||
Exists: int(status.Messages),
|
Exists: int(status.Messages),
|
||||||
Recent: int(status.Recent),
|
Recent: int(status.Recent),
|
||||||
Unseen: int(status.Unseen),
|
Unseen: int(status.Unseen),
|
||||||
|
Caps: w.caps,
|
||||||
},
|
},
|
||||||
}, nil)
|
}, nil)
|
||||||
case *client.MessageUpdate:
|
case *client.MessageUpdate:
|
||||||
|
|
|
@ -186,6 +186,11 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo {
|
||||||
Unseen: 0,
|
Unseen: 0,
|
||||||
|
|
||||||
AccurateCounts: false,
|
AccurateCounts: false,
|
||||||
|
|
||||||
|
Caps: &models.Capabilities{
|
||||||
|
Sort: true,
|
||||||
|
Thread: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := w.c.Dir(name)
|
dir := w.c.Dir(name)
|
||||||
|
|
|
@ -228,6 +228,11 @@ func (w *worker) gatherDirectoryInfo(name string, query string) (
|
||||||
// total unread
|
// total unread
|
||||||
Unseen: count.Unread,
|
Unseen: count.Unread,
|
||||||
AccurateCounts: true,
|
AccurateCounts: true,
|
||||||
|
|
||||||
|
Caps: &models.Capabilities{
|
||||||
|
Sort: true,
|
||||||
|
Thread: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return info, nil
|
return info, nil
|
||||||
|
|
Loading…
Reference in a new issue