Skip to content

Commit

Permalink
feat: filter conversation list [WPB-11637] (#3077)
Browse files Browse the repository at this point in the history
* feat: filter conversation list

* review fixes
  • Loading branch information
Garzas authored Oct 29, 2024
1 parent 2a06026 commit 77e42a2
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.logic.data.conversation

enum class ConversationFilter {
ALL,
FAVORITES,
GROUPS,
ONE_ON_ONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.wire.kalium.persistence.dao.conversation.ConversationEntity
import com.wire.kalium.persistence.dao.conversation.ConversationEntity.GroupState
import com.wire.kalium.persistence.dao.conversation.ConversationEntity.Protocol
import com.wire.kalium.persistence.dao.conversation.ConversationEntity.ProtocolInfo
import com.wire.kalium.persistence.dao.conversation.ConversationFilterEntity
import com.wire.kalium.persistence.dao.conversation.ConversationViewEntity
import com.wire.kalium.persistence.dao.conversation.ProposalTimerEntity
import com.wire.kalium.persistence.dao.unread.UnreadEventTypeEntity
Expand Down Expand Up @@ -671,3 +672,17 @@ internal fun ConversationEntity.VerificationStatus.toModel(): Conversation.Verif
ConversationEntity.VerificationStatus.NOT_VERIFIED -> Conversation.VerificationStatus.NOT_VERIFIED
ConversationEntity.VerificationStatus.DEGRADED -> Conversation.VerificationStatus.DEGRADED
}

internal fun ConversationFilter.toDao(): ConversationFilterEntity = when (this) {
ConversationFilter.ALL -> ConversationFilterEntity.ALL
ConversationFilter.FAVORITES -> ConversationFilterEntity.FAVORITES
ConversationFilter.GROUPS -> ConversationFilterEntity.GROUPS
ConversationFilter.ONE_ON_ONE -> ConversationFilterEntity.ONE_ON_ONE
}

internal fun ConversationFilterEntity.toModel(): ConversationFilter = when (this) {
ConversationFilterEntity.ALL -> ConversationFilter.ALL
ConversationFilterEntity.FAVORITES -> ConversationFilter.FAVORITES
ConversationFilterEntity.GROUPS -> ConversationFilter.GROUPS
ConversationFilterEntity.ONE_ON_ONE -> ConversationFilter.ONE_ON_ONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ class ConversationRepositoryExtensionsImpl internal constructor(
): Flow<PagingData<ConversationDetailsWithEvents>> {
val pager: KaliumPager<ConversationDetailsWithEventsEntity> = with(queryConfig) {
conversationDAO.platformExtensions.getPagerForConversationDetailsWithEventsSearch(
queryConfig = QueryConfig(searchQuery, fromArchive, onlyInteractionEnabled, newActivitiesOnTop),
queryConfig = QueryConfig(
searchQuery = searchQuery,
fromArchive = fromArchive,
onlyInteractionEnabled = onlyInteractionEnabled,
newActivitiesOnTop = newActivitiesOnTop,
conversationFilter = conversationFilter.toDao()
),
pagingConfig = pagingConfig
)
}
Expand Down Expand Up @@ -85,4 +91,5 @@ data class ConversationQueryConfig(
val fromArchive: Boolean = false,
val onlyInteractionEnabled: Boolean = false,
val newActivitiesOnTop: Boolean = false,
val conversationFilter: ConversationFilter = ConversationFilter.ALL,
)
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,16 @@ selectConversationDetailsWithEventsFromSearch:
SELECT * FROM ConversationDetailsWithEvents
WHERE
archived = :fromArchive
AND CASE
-- When filter is ALL, do not apply additional filters on conversation type
WHEN :conversationFilter = 'ALL' THEN 1 = 1
-- When filter is GROUPS, filter only group conversations
WHEN :conversationFilter = 'GROUPS' THEN type = 'GROUP'
-- When filter is ONE_ON_ONE, filter only one-on-one conversations
WHEN :conversationFilter = 'ONE_ON_ONE' THEN type = 'ONE_ON_ONE'
-- When filter is FAVORITES (future implementation)
ELSE 1 = 0
END
AND CASE WHEN :onlyInteractionsEnabled THEN interactionEnabled = 1 ELSE 1 END
AND name LIKE ('%' || :searchQuery || '%')
ORDER BY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface ConversationExtensions {
val fromArchive: Boolean = false,
val onlyInteractionEnabled: Boolean = false,
val newActivitiesOnTop: Boolean = false,
val conversationFilter: ConversationFilterEntity = ConversationFilterEntity.ALL,
)
}

Expand Down Expand Up @@ -71,6 +72,7 @@ internal class ConversationExtensionsImpl internal constructor(
onlyInteractionsEnabled = onlyInteractionEnabled,
searchQuery = searchQuery,
newActivitiesOnTop = newActivitiesOnTop,
conversationFilter = conversationFilter.name,
limit = limit,
offset = offset,
mapper = mapper::fromViewToModel,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.persistence.dao.conversation

enum class ConversationFilterEntity {
ALL,
FAVORITES,
GROUPS,
ONE_ON_ONE
}

0 comments on commit 77e42a2

Please sign in to comment.