Skip to content

Commit 47e355d

Browse files
committed
adapt tag behavior to new searchmode
adapt behavior to #6336 Assisted-by: Claude Code 2.1.199:claude-sonnet-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
1 parent a1e0b6f commit 47e355d

1 file changed

Lines changed: 19 additions & 20 deletions

File tree

app/src/main/java/com/nextcloud/talk/conversationlist/viewmodels/ConversationsListViewModel.kt

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ class ConversationsListViewModel @Inject constructor(
226226
RESULTS
227227
}
228228

229+
private data class TagFilterSelection(val tagId: String? = null, val isFavorites: Boolean = false)
230+
229231
private val _selectedTagFilterFlow = MutableStateFlow<String?>(null)
230232
val selectedTagFilterFlow: StateFlow<String?> = _selectedTagFilterFlow.asStateFlow()
231233

@@ -238,25 +240,12 @@ class ConversationsListViewModel @Inject constructor(
238240
selectedTagIsFavoritesFlow.value = tagId != null && isFavorites
239241
}
240242

241-
private val tagFilteredRoomsFlow: StateFlow<List<ConversationModel>> = combine(
242-
getRoomsStateFlow,
243-
_selectedTagFilterFlow,
244-
selectedTagIsFavoritesFlow
245-
) { rooms, tagId, isFavorites ->
246-
when {
247-
tagId == null -> rooms
248-
// Favorites has no relation to tagIds; it mirrors the pre-existing favorite flag.
249-
isFavorites -> rooms.filter { it.favorite }
250-
else -> rooms.filter { it.tagIds.contains(tagId) }
251-
}
252-
}.stateIn(viewModelScope, SharingStarted.Eagerly, listOf())
253-
254243
/**
255244
* Single source of truth for the [ConversationList] LazyColumn.
256-
* Auto-reacts to rooms, filter, search-active and search-result changes.
245+
* Auto-reacts to rooms, filter, tag filter, search-active and search-result changes.
257246
*/
258247
val conversationListEntriesFlow: StateFlow<List<ConversationListEntry>> = combine(
259-
tagFilteredRoomsFlow,
248+
getRoomsStateFlow,
260249
_filterStateFlow,
261250
combine(_isSearchActiveFlow, _currentSearchQueryFlow) { active, query ->
262251
when {
@@ -265,10 +254,10 @@ class ConversationsListViewModel @Inject constructor(
265254
else -> SearchDisplayMode.RESULTS
266255
}
267256
},
268-
searchResultEntries,
269-
hideRoomToken
270-
) { rooms, filterState, searchMode, searchResults, hideToken ->
271-
buildConversationListEntries(rooms, filterState, searchMode, searchResults, hideToken)
257+
combine(_selectedTagFilterFlow, selectedTagIsFavoritesFlow, ::TagFilterSelection),
258+
combine(searchResultEntries, hideRoomToken, ::Pair)
259+
) { rooms, filterState, searchMode, tagFilter, (searchResults, hideToken) ->
260+
buildConversationListEntries(rooms, filterState, searchMode, tagFilter, searchResults, hideToken)
272261
}.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())
273262

274263
/** Clears the tag filter when the filtered-by tag no longer exists (e.g. it was deleted). */
@@ -625,10 +614,12 @@ class ConversationsListViewModel @Inject constructor(
625614
}
626615
}
627616

617+
@Suppress("LongParameterList")
628618
private fun buildConversationListEntries(
629619
rooms: List<ConversationModel>,
630620
filterState: Map<String, Boolean>,
631621
searchMode: SearchDisplayMode,
622+
tagFilter: TagFilterSelection,
632623
searchResults: List<ConversationListEntry>,
633624
hideToken: String?
634625
): List<ConversationListEntry> {
@@ -649,12 +640,20 @@ class ConversationsListViewModel @Inject constructor(
649640

650641
filtered = when {
651642
// While search is open with an empty query, all conversations are listed,
652-
// ignoring active filters and the default hiding of archived/future-event rooms
643+
// ignoring active filters, the tag filter and the default hiding of archived/future-event rooms
653644
searchMode == SearchDisplayMode.ALL_CONVERSATIONS -> filtered
654645
hasFilterEnabled -> filtered.filter { filterConversationModel(it, filterState) }
655646
else -> filtered.filter { !isFutureEvent(it) && !it.hasArchived }
656647
}
657648

649+
if (searchMode != SearchDisplayMode.ALL_CONVERSATIONS) {
650+
filtered = when {
651+
tagFilter.isFavorites -> filtered.filter { it.favorite }
652+
tagFilter.tagId != null -> filtered.filter { it.tagIds.contains(tagFilter.tagId) }
653+
else -> filtered
654+
}
655+
}
656+
658657
val sorted = filtered.sortedWith(
659658
compareByDescending<ConversationModel> { it.favorite }
660659
.thenByDescending { it.lastActivity }

0 commit comments

Comments
 (0)