Skip to content

Commit

Permalink
fix: favorite folder error handling, non paginatated conversations fr…
Browse files Browse the repository at this point in the history
…om folder
  • Loading branch information
Garzas committed Dec 10, 2024
1 parent d42608c commit c67bebc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal class ConversationFolderDataSource internal constructor(
}

override suspend fun getFavoriteConversationFolder(): Either<CoreFailure, ConversationFolder> = wrapStorageRequest {
conversationFolderDAO.getFavoriteConversationFolder().toModel()
conversationFolderDAO.getFavoriteConversationFolder()?.toModel()
}

override suspend fun observeConversationsFromFolder(folderId: String): Flow<List<ConversationDetailsWithEvents>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,26 @@ internal class ObserveConversationListDetailsWithEventsUseCaseImpl(
fromArchive: Boolean,
conversationFilter: ConversationFilter
): Flow<List<ConversationDetailsWithEvents>> {
return if (conversationFilter == ConversationFilter.Favorites) {
when (val result = getFavoriteFolder()) {
GetFavoriteFolderUseCase.Result.Failure -> {
flowOf(emptyList())
return when (conversationFilter) {
ConversationFilter.Favorites -> {
when (val result = getFavoriteFolder()) {
GetFavoriteFolderUseCase.Result.Failure -> {
flowOf(emptyList())
}

is GetFavoriteFolderUseCase.Result.Success ->
conversationFolderRepository.observeConversationsFromFolder(result.folder.id)
}
}

is GetFavoriteFolderUseCase.Result.Success -> conversationFolderRepository.observeConversationsFromFolder(result.folder.id)
is ConversationFilter.Folder -> {
conversationFolderRepository.observeConversationsFromFolder(conversationFilter.folderId)
}
} else {
conversationRepository.observeConversationListDetailsWithEvents(fromArchive, conversationFilter)

ConversationFilter.All,
ConversationFilter.Groups,
ConversationFilter.OneOnOne ->
conversationRepository.observeConversationListDetailsWithEvents(fromArchive, conversationFilter)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import kotlinx.coroutines.flow.Flow
interface ConversationFolderDAO {
suspend fun getFoldersWithConversations(): List<FolderWithConversationsEntity>
suspend fun observeConversationListFromFolder(folderId: String): Flow<List<ConversationDetailsWithEventsEntity>>
suspend fun getFavoriteConversationFolder(): ConversationFolderEntity
suspend fun getFavoriteConversationFolder(): ConversationFolderEntity?
suspend fun updateConversationFolders(folderWithConversationsList: List<FolderWithConversationsEntity>)
suspend fun addConversationToFolder(conversationId: QualifiedIDEntity, folderId: String)
suspend fun removeConversationFromFolder(conversationId: QualifiedIDEntity, folderId: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ class ConversationFolderDAOImpl internal constructor(
.flowOn(coroutineContext)
}

override suspend fun getFavoriteConversationFolder(): ConversationFolderEntity {
override suspend fun getFavoriteConversationFolder(): ConversationFolderEntity? {
return conversationFoldersQueries.getFavoriteFolder { id, name, folderType ->
ConversationFolderEntity(id, name, folderType)
}
.executeAsOne()
.executeAsOneOrNull()
}

override suspend fun updateConversationFolders(folderWithConversationsList: List<FolderWithConversationsEntity>) =
Expand Down

0 comments on commit c67bebc

Please sign in to comment.