From ee39af712e6caebe0b5539c85fa076f3b7446069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Zag=C3=B3rski?= Date: Mon, 2 Dec 2024 09:31:16 +0100 Subject: [PATCH] chore: Remove self user creator [WPB-11559] (#3118) * chore: Remove self user creator [WPB-11559] * Cleanup field from db --- .../logic/data/conversation/Conversation.kt | 1 - .../data/conversation/ConversationMapper.kt | 1 - .../logic/data/call/CallRepositoryTest.kt | 5 - .../EndCallOnConversationChangeUseCaseTest.kt | 1 - .../ObserveConversationDetailsUseCaseTest.kt | 2 - ...serveConversationListDetailsUseCaseTest.kt | 8 -- .../logic/framework/TestConversation.kt | 2 - .../framework/TestConversationDetails.kt | 1 - .../kalium/persistence/ConversationDetails.sq | 4 - .../src/commonMain/db_user/migrations/93.sqm | 127 ++++++++++++++++++ .../ConversationDetailsWithEventsMapper.kt | 2 - .../dao/conversation/ConversationMapper.kt | 2 - .../conversation/ConversationViewEntity.kt | 1 - .../persistence/dao/ConversationDAOTest.kt | 16 --- 14 files changed, 127 insertions(+), 46 deletions(-) create mode 100644 persistence/src/commonMain/db_user/migrations/93.sqm diff --git a/data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/Conversation.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/Conversation.kt index aff93e9240e..b07cf80f009 100644 --- a/data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/Conversation.kt +++ b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/Conversation.kt @@ -314,7 +314,6 @@ sealed class ConversationDetails(open val conversation: Conversation) { override val conversation: Conversation, val hasOngoingCall: Boolean = false, val isSelfUserMember: Boolean, - val isSelfUserCreator: Boolean, val selfRole: Conversation.Member.Role?, val isFavorite: Boolean = false // val isTeamAdmin: Boolean, TODO kubaz diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationMapper.kt index 2f8ec71e3de..cc2d9995a75 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationMapper.kt @@ -272,7 +272,6 @@ internal class ConversationMapperImpl( conversation = fromConversationViewToEntity(daoModel), hasOngoingCall = callStatus != null, // todo: we can do better! isSelfUserMember = isMember, - isSelfUserCreator = isCreator == 1L, selfRole = selfRole?.let { conversationRoleMapper.fromDAO(it) }, isFavorite = isFavorite ) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/CallRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/CallRepositoryTest.kt index 1b0b223aa64..d3751f62295 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/CallRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/CallRepositoryTest.kt @@ -174,7 +174,6 @@ class CallRepositoryTest { Arrangement.groupConversation, false, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) ) @@ -212,7 +211,6 @@ class CallRepositoryTest { ConversationDetails.Group( Arrangement.groupConversation, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) ) @@ -266,7 +264,6 @@ class CallRepositoryTest { ConversationDetails.Group( Arrangement.groupConversation, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) ) @@ -309,7 +306,6 @@ class CallRepositoryTest { ConversationDetails.Group( Arrangement.groupConversation, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) ) @@ -366,7 +362,6 @@ class CallRepositoryTest { ConversationDetails.Group( Arrangement.groupConversation, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) ) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/call/usecase/EndCallOnConversationChangeUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/call/usecase/EndCallOnConversationChangeUseCaseTest.kt index 6212866cc8e..77cbac0d93a 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/call/usecase/EndCallOnConversationChangeUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/call/usecase/EndCallOnConversationChangeUseCaseTest.kt @@ -249,7 +249,6 @@ class EndCallOnConversationChangeUseCaseTest { conversation = conversation, hasOngoingCall = true, isSelfUserMember = false, - isSelfUserCreator = false, selfRole = null ) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationDetailsUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationDetailsUseCaseTest.kt index 3bf203d73db..3ff8776be81 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationDetailsUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationDetailsUseCaseTest.kt @@ -81,7 +81,6 @@ class ObserveConversationDetailsUseCaseTest { ConversationDetails.Group( conversation, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) ), @@ -89,7 +88,6 @@ class ObserveConversationDetailsUseCaseTest { ConversationDetails.Group( conversation.copy(name = "New Name"), isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) ) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationListDetailsUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationListDetailsUseCaseTest.kt index e2f9044bf6c..a3340b10fef 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationListDetailsUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/conversation/ObserveConversationListDetailsUseCaseTest.kt @@ -65,7 +65,6 @@ class ObserveConversationListDetailsUseCaseTest { ConversationDetails.Group( groupConversation, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) @@ -100,14 +99,12 @@ class ObserveConversationListDetailsUseCaseTest { ConversationDetails.Group( groupConversation1, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) val groupConversationDetails2 = ConversationDetails.Group( groupConversation2, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) @@ -141,7 +138,6 @@ class ObserveConversationListDetailsUseCaseTest { val groupConversationDetails = ConversationDetails.Group( conversation = groupConversation, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) @@ -175,7 +171,6 @@ class ObserveConversationListDetailsUseCaseTest { ConversationDetails.Group( groupConversation, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) ) @@ -223,7 +218,6 @@ class ObserveConversationListDetailsUseCaseTest { val groupConversationDetails = ConversationDetails.Group( groupConversation, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) @@ -258,7 +252,6 @@ class ObserveConversationListDetailsUseCaseTest { val groupConversationDetails = ConversationDetails.Group( groupConversation, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) @@ -287,7 +280,6 @@ class ObserveConversationListDetailsUseCaseTest { val groupConversationDetails = ConversationDetails.Group( groupConversation, isSelfUserMember = true, - isSelfUserCreator = true, selfRole = Conversation.Member.Role.Member ) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestConversation.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestConversation.kt index ecd484c1d2c..6f36299004d 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestConversation.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestConversation.kt @@ -149,7 +149,6 @@ object TestConversation { userDeleted = false, connectionStatus = null, otherUserId = null, - isCreator = 0L, lastNotificationDate = null, protocolInfo = protocolInfo, creatorId = "someValue", @@ -315,7 +314,6 @@ object TestConversation { userDeleted = false, connectionStatus = null, otherUserId = null, - isCreator = 0L, lastNotificationDate = null, protocolInfo = ConversationEntity.ProtocolInfo.Proteus, creatorId = "someValue", diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestConversationDetails.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestConversationDetails.kt index 1372c6fc446..1dce7148793 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestConversationDetails.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestConversationDetails.kt @@ -45,7 +45,6 @@ object TestConversationDetails { val CONVERSATION_GROUP = ConversationDetails.Group( conversation = TestConversation.GROUP(), - isSelfUserCreator = true, isSelfUserMember = true, selfRole = Conversation.Member.Role.Member ) diff --git a/persistence/src/commonMain/db_user/com/wire/kalium/persistence/ConversationDetails.sq b/persistence/src/commonMain/db_user/com/wire/kalium/persistence/ConversationDetails.sq index 66403d5116a..b521bb3c216 100644 --- a/persistence/src/commonMain/db_user/com/wire/kalium/persistence/ConversationDetails.sq +++ b/persistence/src/commonMain/db_user/com/wire/kalium/persistence/ConversationDetails.sq @@ -58,10 +58,6 @@ CASE (Conversation.type) WHEN 'ONE_ON_ONE' THEN User.active_one_on_one_conversation_id WHEN 'CONNECTION_PENDING' THEN connection_user.active_one_on_one_conversation_id END AS otherUserActiveConversationId, -CASE - WHEN (SelfUser.id LIKE (Conversation.creator_id || '@%')) THEN 1 - ELSE 0 -END AS isCreator, CASE (Conversation.type) WHEN 'ONE_ON_ONE' THEN coalesce(User.active_one_on_one_conversation_id = Conversation.qualified_id, 0) ELSE 1 diff --git a/persistence/src/commonMain/db_user/migrations/93.sqm b/persistence/src/commonMain/db_user/migrations/93.sqm new file mode 100644 index 00000000000..30dc8b3fa11 --- /dev/null +++ b/persistence/src/commonMain/db_user/migrations/93.sqm @@ -0,0 +1,127 @@ +DROP VIEW IF EXISTS ConversationDetails; + +CREATE VIEW IF NOT EXISTS ConversationDetails AS +SELECT +Conversation.qualified_id AS qualifiedId, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.name + WHEN 'CONNECTION_PENDING' THEN connection_user.name + ELSE Conversation.name +END AS name, +Conversation.type, +Call.status AS callStatus, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.preview_asset_id + WHEN 'CONNECTION_PENDING' THEN connection_user.preview_asset_id +END AS previewAssetId, +Conversation.muted_status AS mutedStatus, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.team + ELSE Conversation.team_id +END AS teamId, +CASE (Conversation.type) + WHEN 'CONNECTION_PENDING' THEN Connection.last_update_date + ELSE Conversation.last_modified_date +END AS lastModifiedDate, +Conversation.last_read_date AS lastReadDate, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.user_availability_status + WHEN 'CONNECTION_PENDING' THEN connection_user.user_availability_status +END AS userAvailabilityStatus, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.user_type + WHEN 'CONNECTION_PENDING' THEN connection_user.user_type +END AS userType, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.bot_service + WHEN 'CONNECTION_PENDING' THEN connection_user.bot_service +END AS botService, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.deleted + WHEN 'CONNECTION_PENDING' THEN connection_user.deleted +END AS userDeleted, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.defederated + WHEN 'CONNECTION_PENDING' THEN connection_user.defederated +END AS userDefederated, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.supported_protocols + WHEN 'CONNECTION_PENDING' THEN connection_user.supported_protocols +END AS userSupportedProtocols, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.connection_status + WHEN 'CONNECTION_PENDING' THEN connection_user.connection_status +END AS connectionStatus, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.qualified_id + WHEN 'CONNECTION_PENDING' THEN connection_user.qualified_id +END AS otherUserId, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.active_one_on_one_conversation_id + WHEN 'CONNECTION_PENDING' THEN connection_user.active_one_on_one_conversation_id +END AS otherUserActiveConversationId, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN coalesce(User.active_one_on_one_conversation_id = Conversation.qualified_id, 0) + ELSE 1 +END AS isActive, +CASE (Conversation.type) + WHEN 'ONE_ON_ONE' THEN User.accent_id + ELSE 0 +END AS accentId, +Conversation.last_notified_date AS lastNotifiedMessageDate, +memberRole. role AS selfRole, +Conversation.protocol, +Conversation.mls_cipher_suite, +Conversation.mls_epoch, +Conversation.mls_group_id, +Conversation.mls_last_keying_material_update_date, +Conversation.mls_group_state, +Conversation.access_list, +Conversation.access_role_list, +Conversation.mls_proposal_timer, +Conversation.muted_time, +Conversation.creator_id, +Conversation.receipt_mode, +Conversation.message_timer, +Conversation.user_message_timer, +Conversation.incomplete_metadata, +Conversation.archived, +Conversation.archived_date_time, +Conversation.verification_status AS mls_verification_status, +Conversation.proteus_verification_status, +Conversation.legal_hold_status, +SelfUser.id AS selfUserId, +CASE + WHEN Conversation.type = 'GROUP' THEN + CASE + WHEN memberRole.role IS NOT NULL THEN 1 + ELSE 0 + END + WHEN Conversation.type = 'ONE_ON_ONE' THEN + CASE + WHEN User.defederated = 1 THEN 0 + WHEN User.deleted = 1 THEN 0 + WHEN User.connection_status = 'BLOCKED' THEN 0 + WHEN Conversation.legal_hold_status = 'DEGRADED' THEN 0 + ELSE 1 + END + ELSE 0 +END AS interactionEnabled, +LabeledConversation.folder_id IS NOT NULL AS isFavorite +FROM Conversation +LEFT JOIN SelfUser +LEFT JOIN Member ON Conversation.qualified_id = Member.conversation + AND Conversation.type IS 'ONE_ON_ONE' + AND Member.user IS NOT SelfUser.id +LEFT JOIN Member AS memberRole ON Conversation.qualified_id = memberRole.conversation + AND memberRole.user IS SelfUser.id +LEFT JOIN User ON User.qualified_id = Member.user +LEFT JOIN Connection ON Connection.qualified_conversation = Conversation.qualified_id + AND (Connection.status = 'SENT' + OR Connection.status = 'PENDING' + OR Connection.status = 'NOT_CONNECTED' + AND Conversation.type IS 'CONNECTION_PENDING') +LEFT JOIN User AS connection_user ON Connection.qualified_to = connection_user.qualified_id +LEFT JOIN Call ON Call.id IS (SELECT id FROM Call WHERE Call.conversation_id = Conversation.qualified_id AND Call.status IS 'STILL_ONGOING' ORDER BY created_at DESC LIMIT 1) +LEFT JOIN ConversationFolder AS FavoriteFolder ON FavoriteFolder.folder_type = 'FAVORITE' +LEFT JOIN LabeledConversation ON LabeledConversation.conversation_id = Conversation.qualified_id AND LabeledConversation.folder_id = FavoriteFolder.id; diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationDetailsWithEventsMapper.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationDetailsWithEventsMapper.kt index 8e77a9aa642..d59c32c6c2f 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationDetailsWithEventsMapper.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationDetailsWithEventsMapper.kt @@ -53,7 +53,6 @@ data object ConversationDetailsWithEventsMapper { connectionStatus: ConnectionEntity.State?, otherUserId: QualifiedIDEntity?, otherUserActiveConversationId: QualifiedIDEntity?, - isCreator: Long, isActive: Long, accentId: Int?, lastNotifiedMessageDate: Instant?, @@ -128,7 +127,6 @@ data object ConversationDetailsWithEventsMapper { connectionStatus = connectionStatus, otherUserId = otherUserId, otherUserActiveConversationId = otherUserActiveConversationId, - isCreator = isCreator, isActive = isActive, accentId = accentId, lastNotifiedMessageDate = lastNotifiedMessageDate, diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationMapper.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationMapper.kt index d421e6b0de0..4cb050db21d 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationMapper.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationMapper.kt @@ -49,7 +49,6 @@ data object ConversationMapper { connectionStatus: ConnectionEntity.State?, otherUserId: QualifiedIDEntity?, otherUserActiveConversationId: QualifiedIDEntity?, - isCreator: Long, isActive: Long, accentId: Int?, lastNotifiedMessageDate: Instant?, @@ -90,7 +89,6 @@ data object ConversationMapper { mlsLastKeyingMaterialUpdateDate, mlsCipherSuite ), - isCreator = isCreator, mutedStatus = mutedStatus, mutedTime = mutedTime, creatorId = creatorId, diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationViewEntity.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationViewEntity.kt index d9ebd64303b..8e5e247226e 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationViewEntity.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/conversation/ConversationViewEntity.kt @@ -47,7 +47,6 @@ data class ConversationViewEntity( val userDefederated: Boolean?, val connectionStatus: ConnectionEntity.State? = ConnectionEntity.State.NOT_CONNECTED, val otherUserId: QualifiedIDEntity?, - val isCreator: Long, val lastNotificationDate: Instant?, val selfRole: MemberEntity.Role?, val protocolInfo: ConversationEntity.ProtocolInfo, diff --git a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/ConversationDAOTest.kt b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/ConversationDAOTest.kt index 96e992c328c..a000851a0d6 100644 --- a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/ConversationDAOTest.kt +++ b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/ConversationDAOTest.kt @@ -886,21 +886,6 @@ class ConversationDAOTest : BaseDatabaseTest() { assertEquals(messageTimer, result?.messageTimer) } - @Test - fun givenSelfUserIsCreatorOfConversation_whenGettingConversationDetails_itReturnsCorrectDetails() = runTest(dispatcher) { - // given - conversationDAO.insertConversation(conversationEntity3.copy(creatorId = selfUserId.value)) - teamDAO.insertTeam(team) - userDAO.upsertUser(user2) - insertTeamUserAndMember(team, user2, conversationEntity3.id) - - // when - val result = conversationDAO.getConversationDetailsById(conversationEntity3.id) - - // then - assertEquals(1L, result?.isCreator) - } - @Test fun givenMixedConversation_whenGettingConversationProtocolInfo_itReturnsCorrectInfo() = runTest { // given @@ -2358,7 +2343,6 @@ class ConversationDAOTest : BaseDatabaseTest() { userDeleted = if (type == ConversationEntity.Type.ONE_ON_ONE) userEntity?.deleted else null, connectionStatus = if (type == ConversationEntity.Type.ONE_ON_ONE) userEntity?.connectionStatus else null, otherUserId = if (type == ConversationEntity.Type.ONE_ON_ONE) userEntity?.id else null, - isCreator = 0L, lastNotificationDate = lastNotificationDate, protocolInfo = protocolInfo, accessList = access,