Skip to content

Commit e68bb5e

Browse files
committed
refactor chat list loading and folder synchronization
- remove redundant `chatFolders` update collection in `ChatsListRepositoryImpl` as it is handled elsewhere - eliminate unnecessary initial `selectFolder` call in `DefaultChatListComponent` initialization - simplify `isRequestActive` and folder ID validation checks with single-line returns - remove manual client-side filtering of `includedChatIds` in `ChatListContent`, relying on the data layer for folder content - refine shimmer logic in `ChatListContent` to prevent flickering by holding initial content during the first folder transition while loading
1 parent 7b5aedd commit e68bb5e

3 files changed

Lines changed: 9 additions & 29 deletions

File tree

data/src/main/java/org/monogram/data/repository/ChatsListRepositoryImpl.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,6 @@ class ChatsListRepositoryImpl(
307307
}
308308
}
309309
}
310-
311-
scope.launch {
312-
updates.chatFolders.collect { update ->
313-
folderManager.handleChatFoldersUpdate(update)
314-
triggerUpdate()
315-
}
316-
}
317310
}
318311

319312
private suspend fun rebuildAndEmit() {
@@ -638,9 +631,7 @@ class ChatsListRepositoryImpl(
638631
setLoadingState(folderId, requestId, true)
639632

640633
scope.launch(dispatchers.io) {
641-
if (!isRequestActive(folderId, requestId)) {
642-
return@launch
643-
}
634+
if (!isRequestActive(folderId, requestId)) return@launch
644635

645636
val currentCount = _chatListFlow.value.size
646637
if (currentCount < currentLimit) {

presentation/src/main/java/org/monogram/presentation/features/chats/list/ChatListContent.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ import org.monogram.presentation.R
121121
import org.monogram.presentation.core.ui.Avatar
122122
import org.monogram.presentation.core.ui.ConfirmationSheet
123123
import org.monogram.presentation.core.util.LocalTabletInterfaceEnabled
124-
import org.monogram.presentation.features.chats.list.ChatListComponent
124+
import org.monogram.presentation.features.chats.conversation.ui.message.getEmojiFontFamily
125125
import org.monogram.presentation.features.chats.list.components.AccountMenu
126126
import org.monogram.presentation.features.chats.list.components.ArchiveHeaderCard
127127
import org.monogram.presentation.features.chats.list.components.ChatListItem
@@ -132,7 +132,6 @@ import org.monogram.presentation.features.chats.list.components.FolderTabs
132132
import org.monogram.presentation.features.chats.list.components.MessageSearchItem
133133
import org.monogram.presentation.features.chats.list.components.PermissionRequestSheet
134134
import org.monogram.presentation.features.chats.list.components.SelectionTopBar
135-
import org.monogram.presentation.features.chats.conversation.ui.message.getEmojiFontFamily
136135
import org.monogram.presentation.features.instantview.InstantViewer
137136
import org.monogram.presentation.features.stickers.ui.menu.EmojisGrid
138137
import org.monogram.presentation.features.webapp.MiniAppViewer
@@ -1104,16 +1103,15 @@ fun ChatListContent(component: ChatListComponent) {
11041103
return@HorizontalPager
11051104
}
11061105
val rawFolderChats = foldersState.chatsByFolder[folderId].orEmpty()
1107-
val folderChats = if (folderId > 0 && folder.includedChatIds.isNotEmpty()) {
1108-
val includedChatIds = folder.includedChatIds.toHashSet()
1109-
rawFolderChats.filter { chat -> chat.id in includedChatIds }
1110-
} else {
1111-
rawFolderChats
1112-
}
1106+
val folderChats = rawFolderChats
11131107
val isFolderLoading = foldersState.isLoadingByFolder[folderId] ?: false
11141108
val hasFolderLoadState = foldersState.isLoadingByFolder.containsKey(folderId)
1115-
val showFolderShimmer = folderChats.isEmpty() && (isFolderLoading || !hasFolderLoadState)
11161109
val shouldAnimateFirstFolderTransition = firstFolderTransitionCompleted[folderId] != true
1110+
val shouldHoldInitialFolderContent = folderId > 0 &&
1111+
shouldAnimateFirstFolderTransition &&
1112+
isFolderLoading
1113+
val showFolderShimmer = shouldHoldInitialFolderContent ||
1114+
(folderChats.isEmpty() && (isFolderLoading || !hasFolderLoadState))
11171115

11181116
val scrollState = rememberManagedChatListState(
11191117
stateKey = "folder:$folderId",

presentation/src/main/java/org/monogram/presentation/features/chats/list/DefaultChatListComponent.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ import org.monogram.presentation.BuildConfig
3535
import org.monogram.presentation.core.util.AppPreferences
3636
import org.monogram.presentation.core.util.coRunCatching
3737
import org.monogram.presentation.core.util.componentScope
38-
import org.monogram.presentation.features.chats.list.ChatListComponent
39-
import org.monogram.presentation.features.chats.list.ChatListStore
40-
import org.monogram.presentation.features.chats.list.ChatListStoreFactory
4138
import org.monogram.presentation.root.AppComponentContext
4239

4340
class DefaultChatListComponent(
@@ -367,10 +364,6 @@ class DefaultChatListComponent(
367364
}
368365
}
369366
.launchIn(scope)
370-
371-
scope.launch(Dispatchers.IO) {
372-
chatListRepository.selectFolder(_state.value.selectedFolderId)
373-
}
374367
}
375368

376369
override fun retryConnection() = store.accept(ChatListStore.Intent.RetryConnection)
@@ -405,9 +398,7 @@ class DefaultChatListComponent(
405398
if (_state.value.isLoadingByFolder[targetFolderId] == true) return
406399

407400
scope.launch(Dispatchers.IO) {
408-
if (folderId != null && folderId != _state.value.selectedFolderId) {
409-
return@launch
410-
}
401+
if (folderId != null && folderId != _state.value.selectedFolderId) return@launch
411402
chatListRepository.loadNextChunk(20)
412403
}
413404
}

0 commit comments

Comments
 (0)