Merge pull request #5687 from k9mail/update_folder_list

Update displayed folder list when folders on server have changed
This commit is contained in:
cketti 2021-09-22 18:29:37 +02:00 committed by GitHub
commit e9d7606592
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,21 +57,28 @@ class FolderRepository(
fun getDisplayFoldersFlow(account: Account, displayMode: FolderMode): Flow<List<DisplayFolder>> { fun getDisplayFoldersFlow(account: Account, displayMode: FolderMode): Flow<List<DisplayFolder>> {
val messagingController = DI.get<MessagingController>() val messagingController = DI.get<MessagingController>()
val messageStore = messageStoreManager.getMessageStore(account)
return callbackFlow { return callbackFlow {
send(getDisplayFolders(account, displayMode)) send(getDisplayFolders(account, displayMode))
val listener = object : SimpleMessagingListener() { val folderStatusChangedListener = object : SimpleMessagingListener() {
override fun folderStatusChanged(statusChangedAccount: Account, folderId: Long) { override fun folderStatusChanged(statusChangedAccount: Account, folderId: Long) {
if (statusChangedAccount.uuid == account.uuid) { if (statusChangedAccount.uuid == account.uuid) {
sendBlockingSilently(getDisplayFolders(account, displayMode)) sendBlockingSilently(getDisplayFolders(account, displayMode))
} }
} }
} }
messagingController.addListener(listener) messagingController.addListener(folderStatusChangedListener)
val folderSettingsChangedListener = FolderSettingsChangedListener {
sendBlockingSilently(getDisplayFolders(account, displayMode))
}
messageStore.addFolderSettingsChangedListener(folderSettingsChangedListener)
awaitClose { awaitClose {
messagingController.removeListener(listener) messagingController.removeListener(folderStatusChangedListener)
messageStore.removeFolderSettingsChangedListener(folderSettingsChangedListener)
} }
}.buffer(capacity = Channel.CONFLATED) }.buffer(capacity = Channel.CONFLATED)
.distinctUntilChanged() .distinctUntilChanged()