Merge pull request #5687 from k9mail/update_folder_list
Update displayed folder list when folders on server have changed
This commit is contained in:
commit
e9d7606592
1 changed files with 10 additions and 3 deletions
|
@ -57,21 +57,28 @@ class FolderRepository(
|
|||
|
||||
fun getDisplayFoldersFlow(account: Account, displayMode: FolderMode): Flow<List<DisplayFolder>> {
|
||||
val messagingController = DI.get<MessagingController>()
|
||||
val messageStore = messageStoreManager.getMessageStore(account)
|
||||
|
||||
return callbackFlow {
|
||||
send(getDisplayFolders(account, displayMode))
|
||||
|
||||
val listener = object : SimpleMessagingListener() {
|
||||
val folderStatusChangedListener = object : SimpleMessagingListener() {
|
||||
override fun folderStatusChanged(statusChangedAccount: Account, folderId: Long) {
|
||||
if (statusChangedAccount.uuid == account.uuid) {
|
||||
sendBlockingSilently(getDisplayFolders(account, displayMode))
|
||||
}
|
||||
}
|
||||
}
|
||||
messagingController.addListener(listener)
|
||||
messagingController.addListener(folderStatusChangedListener)
|
||||
|
||||
val folderSettingsChangedListener = FolderSettingsChangedListener {
|
||||
sendBlockingSilently(getDisplayFolders(account, displayMode))
|
||||
}
|
||||
messageStore.addFolderSettingsChangedListener(folderSettingsChangedListener)
|
||||
|
||||
awaitClose {
|
||||
messagingController.removeListener(listener)
|
||||
messagingController.removeListener(folderStatusChangedListener)
|
||||
messageStore.removeFolderSettingsChangedListener(folderSettingsChangedListener)
|
||||
}
|
||||
}.buffer(capacity = Channel.CONFLATED)
|
||||
.distinctUntilChanged()
|
||||
|
|
Loading…
Reference in a new issue