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
This commit is contained in:
Reto Brunner 2020-02-15 14:14:44 +01:00 committed by Drew DeVault
parent 66b68f35b3
commit 89b742dc6c
2 changed files with 16 additions and 0 deletions

View File

@ -168,6 +168,7 @@ func merge(to *models.MessageInfo, from *models.MessageInfo) {
func (store *MessageStore) Update(msg types.WorkerMessage) { func (store *MessageStore) Update(msg types.WorkerMessage) {
update := false update := false
directoryChange := false directoryChange := false
requestDirInfo := false
switch msg := msg.(type) { switch msg := msg.(type) {
case *types.DirectoryInfo: case *types.DirectoryInfo:
store.DirInfo = *msg.Info store.DirInfo = *msg.Info
@ -212,6 +213,7 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
} }
} }
update = true update = true
requestDirInfo = true
case *types.FullMessage: case *types.FullMessage:
if _, ok := store.pendingBodies[msg.Content.Uid]; ok { if _, ok := store.pendingBodies[msg.Content.Uid]; ok {
delete(store.pendingBodies, msg.Content.Uid) delete(store.pendingBodies, msg.Content.Uid)
@ -245,6 +247,7 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
} }
store.uids = uids store.uids = uids
update = true update = true
requestDirInfo = true
} }
if update { if update {
@ -254,6 +257,12 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
if directoryChange && store.triggerDirectoryChange != nil { if directoryChange && store.triggerDirectoryChange != nil {
store.triggerDirectoryChange() store.triggerDirectoryChange()
} }
if requestDirInfo {
store.worker.PostAction(&types.DirectoryInfoUpdateRequest{
Name: store.DirInfo.Name,
}, nil)
}
} }
func (store *MessageStore) OnUpdate(fn func(store *MessageStore)) { func (store *MessageStore) OnUpdate(fn func(store *MessageStore)) {

View File

@ -149,6 +149,13 @@ type DirectoryInfo struct {
Info *models.DirectoryInfo 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 { type DirectoryContents struct {
Message Message
Uids []uint32 Uids []uint32