about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-02-15 14:14:44 +0100
committerDrew DeVault <sir@cmpwn.com>2020-02-16 10:41:17 -0500
commit89b742dc6c2cc4e70cc7fd44454ee184dcc4b627 (patch)
tree53d9032255e94900df7e1c8d74735b93b4635b39
parent66b68f35b3f3f3b97ec9951397fd75afeb0d0995 (diff)
downloadaerc-89b742dc6c2cc4e70cc7fd44454ee184dcc4b627.tar.gz
Request DirInfo whenever the unread count may have changed
Actions such as read / unread or the addition of new messages do change
the read/unread/recent count. Hence we request an update from the workers.
Workers going over the network should probably cache the information and invalidate
it only if necessary
-rw-r--r--lib/msgstore.go9
-rw-r--r--worker/types/messages.go7
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index e6ddf72..737ba4d 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -168,6 +168,7 @@ func merge(to *models.MessageInfo, from *models.MessageInfo) {
 func (store *MessageStore) Update(msg types.WorkerMessage) {
 	update := false
 	directoryChange := false
+	requestDirInfo := false
 	switch msg := msg.(type) {
 	case *types.DirectoryInfo:
 		store.DirInfo = *msg.Info
@@ -212,6 +213,7 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
 			}
 		}
 		update = true
+		requestDirInfo = true
 	case *types.FullMessage:
 		if _, ok := store.pendingBodies[msg.Content.Uid]; ok {
 			delete(store.pendingBodies, msg.Content.Uid)
@@ -245,6 +247,7 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
 		}
 		store.uids = uids
 		update = true
+		requestDirInfo = true
 	}
 
 	if update {
@@ -254,6 +257,12 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
 	if directoryChange && store.triggerDirectoryChange != nil {
 		store.triggerDirectoryChange()
 	}
+
+	if requestDirInfo {
+		store.worker.PostAction(&types.DirectoryInfoUpdateRequest{
+			Name: store.DirInfo.Name,
+		}, nil)
+	}
 }
 
 func (store *MessageStore) OnUpdate(fn func(store *MessageStore)) {
diff --git a/worker/types/messages.go b/worker/types/messages.go
index c7d5077..f43ab0a 100644
--- a/worker/types/messages.go
+++ b/worker/types/messages.go
@@ -149,6 +149,13 @@ type DirectoryInfo struct {
 	Info *models.DirectoryInfo
 }
 
+// Sent whenever we assume that a directory content changed
+// workers are requested to update the DirectoryInfo to display the unread count
+type DirectoryInfoUpdateRequest struct {
+	Message
+	Name string
+}
+
 type DirectoryContents struct {
 	Message
 	Uids []uint32