From 36bc8e15b24c7c44f2c5d37d9e66073ebf355f53 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Tue, 28 Nov 2023 14:52:50 +0100 Subject: [PATCH 1/4] feat: stop handling team member add/removed events --- .../com/wire/kalium/logic/data/event/Event.kt | 34 +----- .../kalium/logic/data/event/EventMapper.kt | 29 ----- .../kalium/logic/data/team/TeamRepository.kt | 36 ------ .../kalium/logic/feature/UserSessionScope.kt | 7 +- .../logic/sync/receiver/TeamEventReceiver.kt | 110 +----------------- .../logic/sync/receiver/UserEventReceiver.kt | 2 + .../wire/kalium/logic/framework/TestEvent.kt | 18 --- .../sync/receiver/TeamEventReceiverTest.kt | 87 +------------- .../notification/EventContentDTO.kt | 17 --- .../persistence/dao/message/MessageEntity.kt | 2 + 10 files changed, 12 insertions(+), 330 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt index 5c0a809c8bb..0c998445a2c 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt @@ -24,8 +24,8 @@ import com.wire.kalium.logger.obfuscateDomain import com.wire.kalium.logger.obfuscateId import com.wire.kalium.logic.data.client.Client import com.wire.kalium.logic.data.conversation.ClientId -import com.wire.kalium.logic.data.conversation.Conversation.Protocol import com.wire.kalium.logic.data.conversation.Conversation.Member +import com.wire.kalium.logic.data.conversation.Conversation.Protocol import com.wire.kalium.logic.data.conversation.Conversation.ReceiptMode import com.wire.kalium.logic.data.conversation.Conversation.TypingIndicatorMode import com.wire.kalium.logic.data.conversation.MutedConversationStatus @@ -446,38 +446,6 @@ sealed class Event(open val id: String, open val transient: Boolean, open val li ) } - data class MemberJoin( - override val id: String, - override val teamId: String, - override val transient: Boolean, - override val live: Boolean, - val memberId: String, - ) : Team(id, teamId, transient, live) { - override fun toLogMap(): Map = mapOf( - typeKey to "Team.MemberJoin", - idKey to id.obfuscateId(), - teamIdKey to teamId.obfuscateId(), - memberIdKey to memberId.obfuscateId(), - ) - } - - data class MemberLeave( - override val id: String, - override val transient: Boolean, - override val live: Boolean, - override val teamId: String, - val memberId: String, - val timestampIso: String, - ) : Team(id, teamId, transient, live) { - override fun toLogMap(): Map = mapOf( - typeKey to "Team.MemberLeave", - idKey to id.obfuscateId(), - teamIdKey to teamId.obfuscateId(), - timestampIsoKey to timestampIso, - memberIdKey to memberId.obfuscateId(), - ) - } - data class MemberUpdate( override val id: String, override val teamId: String, diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt index 5bc6dd20fed..e84b2200ce0 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/EventMapper.kt @@ -95,8 +95,6 @@ class EventMapper( is EventContentDTO.Conversation.AccessUpdate -> unknown(id, transient, live, eventContentDTO) is EventContentDTO.Conversation.DeletedConversationDTO -> conversationDeleted(id, eventContentDTO, transient, live) is EventContentDTO.Conversation.ConversationRenameDTO -> conversationRenamed(id, eventContentDTO, transient, live) - is EventContentDTO.Team.MemberJoin -> teamMemberJoined(id, eventContentDTO, transient, live) - is EventContentDTO.Team.MemberLeave -> teamMemberLeft(id, eventContentDTO, transient, live) is EventContentDTO.Team.MemberUpdate -> teamMemberUpdate(id, eventContentDTO, transient, live) is EventContentDTO.Team.Update -> teamUpdate(id, eventContentDTO, transient, live) is EventContentDTO.User.UpdateDTO -> userUpdate(id, eventContentDTO, transient, live) @@ -655,33 +653,6 @@ class EventMapper( timestampIso = event.time, ) - private fun teamMemberJoined( - id: String, - event: EventContentDTO.Team.MemberJoin, - transient: Boolean, - live: Boolean - ) = Event.Team.MemberJoin( - id = id, - teamId = event.teamId, - transient = transient, - live = live, - memberId = event.teamMember.nonQualifiedUserId - ) - - private fun teamMemberLeft( - id: String, - event: EventContentDTO.Team.MemberLeave, - transient: Boolean, - live: Boolean - ) = Event.Team.MemberLeave( - id = id, - teamId = event.teamId, - memberId = event.teamMember.nonQualifiedUserId, - transient = transient, - live = live, - timestampIso = event.time - ) - private fun teamMemberUpdate( id: String, event: EventContentDTO.Team.MemberUpdate, diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/team/TeamRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/team/TeamRepository.kt index 8bdea9145ae..6e506a46f5a 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/team/TeamRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/team/TeamRepository.kt @@ -23,7 +23,6 @@ import com.wire.kalium.logic.data.id.ConversationId import com.wire.kalium.logic.data.id.TeamId import com.wire.kalium.logic.data.service.ServiceMapper import com.wire.kalium.logic.data.user.UserId -import com.wire.kalium.logic.data.user.UserMapper import com.wire.kalium.logic.data.user.type.UserEntityTypeMapper import com.wire.kalium.logic.di.MapperProvider import com.wire.kalium.logic.functional.Either @@ -33,9 +32,6 @@ import com.wire.kalium.logic.functional.onSuccess import com.wire.kalium.logic.wrapApiRequest import com.wire.kalium.logic.wrapStorageRequest import com.wire.kalium.network.api.base.authenticated.TeamsApi -import com.wire.kalium.network.api.base.authenticated.userDetails.UserDetailsApi -import com.wire.kalium.network.api.base.model.QualifiedID -import com.wire.kalium.persistence.dao.ConnectionEntity import com.wire.kalium.persistence.dao.QualifiedIDEntity import com.wire.kalium.persistence.dao.ServiceDAO import com.wire.kalium.persistence.dao.TeamDAO @@ -49,8 +45,6 @@ interface TeamRepository { suspend fun getTeam(teamId: TeamId): Flow suspend fun deleteConversation(conversationId: ConversationId, teamId: TeamId): Either suspend fun updateMemberRole(teamId: String, userId: String, permissionCode: Int?): Either - suspend fun fetchTeamMember(teamId: String, userId: String): Either - suspend fun removeTeamMember(teamId: String, userId: String): Either suspend fun updateTeam(team: Team): Either suspend fun syncServices(teamId: TeamId): Either suspend fun approveLegalHoldRequest(teamId: TeamId, password: String?): Either @@ -62,10 +56,8 @@ internal class TeamDataSource( private val userConfigDAO: UserConfigDAO, private val teamDAO: TeamDAO, private val teamsApi: TeamsApi, - private val userDetailsApi: UserDetailsApi, private val selfUserId: UserId, private val serviceDAO: ServiceDAO, - private val userMapper: UserMapper = MapperProvider.userMapper(), private val teamMapper: TeamMapper = MapperProvider.teamMapper(), private val serviceMapper: ServiceMapper = MapperProvider.serviceMapper(), private val userTypeEntityTypeMapper: UserEntityTypeMapper = MapperProvider.userTypeEntityMapper() @@ -105,34 +97,6 @@ internal class TeamDataSource( } } - override suspend fun fetchTeamMember(teamId: String, userId: String): Either { - return wrapApiRequest { - teamsApi.getTeamMember( - teamId = teamId, - userId = userId, - ) - }.flatMap { member -> - wrapApiRequest { userDetailsApi.getUserInfo(userId = QualifiedID(userId, selfUserId.domain)) } - .flatMap { userProfileDTO -> - wrapStorageRequest { - val userEntity = userMapper.fromUserProfileDtoToUserEntity( - userProfile = userProfileDTO, - connectionState = ConnectionEntity.State.ACCEPTED, - userTypeEntity = userTypeEntityTypeMapper.teamRoleCodeToUserType(member.permissions?.own) - ) - userDAO.upsertUser(userEntity) - userDAO.upsertConnectionStatuses(mapOf(userEntity.id to userEntity.connectionStatus)) - } - } - } - } - - override suspend fun removeTeamMember(teamId: String, userId: String): Either { - return wrapStorageRequest { - userDAO.markUserAsDeleted(QualifiedIDEntity(userId, selfUserId.domain)) - } - } - override suspend fun updateTeam(team: Team): Either { return wrapStorageRequest { teamDAO.updateTeam(teamMapper.fromModelToEntity(team)) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt index ba365a5535c..a39ad236cc5 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt @@ -217,10 +217,10 @@ import com.wire.kalium.logic.feature.featureConfig.handler.SecondFactorPasswordC import com.wire.kalium.logic.feature.featureConfig.handler.SelfDeletingMessagesConfigHandler import com.wire.kalium.logic.feature.keypackage.KeyPackageManager import com.wire.kalium.logic.feature.keypackage.KeyPackageManagerImpl -import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldRequestUseCase -import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldRequestUseCaseImpl import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldForSelfUserUseCase import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldForSelfUserUseCaseImpl +import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldRequestUseCase +import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldRequestUseCaseImpl import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldStateForUserUseCase import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldStateForUserUseCaseImpl import com.wire.kalium.logic.feature.message.AddSystemMessageToAllConversationsUseCase @@ -712,7 +712,6 @@ class UserSessionScope internal constructor( userStorage.database.userConfigDAO, userStorage.database.teamDAO, authenticatedNetworkContainer.teamsApi, - authenticatedNetworkContainer.userDetailsApi, userId, userStorage.database.serviceDAO ) @@ -1377,7 +1376,7 @@ class UserSessionScope internal constructor( ) private val teamEventReceiver: TeamEventReceiver - get() = TeamEventReceiverImpl(teamRepository, conversationRepository, userRepository, persistMessage, userId) + get() = TeamEventReceiverImpl(teamRepository) private val guestRoomConfigHandler get() = GuestRoomConfigHandler(userConfigRepository, kaliumConfigs) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/TeamEventReceiver.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/TeamEventReceiver.kt index 0dad1ff5726..b0d164488c2 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/TeamEventReceiver.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/TeamEventReceiver.kt @@ -18,140 +18,36 @@ package com.wire.kalium.logic.sync.receiver -import com.benasher44.uuid.uuid4 import com.wire.kalium.logic.CoreFailure -import com.wire.kalium.logic.data.conversation.ConversationRepository import com.wire.kalium.logic.data.event.Event import com.wire.kalium.logic.data.event.EventLoggingStatus import com.wire.kalium.logic.data.event.logEventProcessing -import com.wire.kalium.logic.data.message.Message -import com.wire.kalium.logic.data.message.MessageContent -import com.wire.kalium.logic.data.message.PersistMessageUseCase import com.wire.kalium.logic.data.team.Team import com.wire.kalium.logic.data.team.TeamRepository -import com.wire.kalium.logic.data.user.UserId -import com.wire.kalium.logic.data.user.UserRepository import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.functional.onFailure import com.wire.kalium.logic.functional.onSuccess import com.wire.kalium.logic.kaliumLogger -import kotlinx.coroutines.flow.first internal interface TeamEventReceiver : EventReceiver internal class TeamEventReceiverImpl( - private val teamRepository: TeamRepository, - private val conversationRepository: ConversationRepository, - private val userRepository: UserRepository, - private val persistMessage: PersistMessageUseCase, - private val selfUserId: UserId, + private val teamRepository: TeamRepository + ) : TeamEventReceiver { override suspend fun onEvent(event: Event.Team): Either { when (event) { - is Event.Team.MemberJoin -> handleMemberJoin(event) - is Event.Team.MemberLeave -> handleMemberLeave(event) is Event.Team.MemberUpdate -> handleMemberUpdate(event) is Event.Team.Update -> handleUpdate(event) } // TODO: Make sure errors are accounted for by each handler. // onEvent now requires Either, so we can propagate errors, - // but not all handlers are using it yet. + // but not all handlers are using it yet.® // Returning Either.Right is the equivalent of how it was originally working. return Either.Right(Unit) } - private suspend fun handleMemberJoin(event: Event.Team.MemberJoin) = - teamRepository.fetchTeamMember( - teamId = event.teamId, - userId = event.memberId, - ) - .onSuccess { - kaliumLogger - .logEventProcessing( - EventLoggingStatus.SUCCESS, - event - ) - } - .onFailure { - kaliumLogger - .logEventProcessing( - EventLoggingStatus.FAILURE, - event, - Pair("errorInfo", "$it") - ) - } - - @Suppress("LongMethod") - private suspend fun handleMemberLeave(event: Event.Team.MemberLeave) { - val userId = UserId(event.memberId, selfUserId.domain) - teamRepository.removeTeamMember( - teamId = event.teamId, - userId = event.memberId, - ) - .onSuccess { - val knownUser = userRepository.getKnownUser(userId).first() - if (knownUser?.name != null) { - conversationRepository.getConversationsByUserId(userId) - .onSuccess { - it.forEach { conversation -> - val message = Message.System( - id = uuid4().toString(), // We generate a random uuid for this new system message - content = MessageContent.TeamMemberRemoved(knownUser.name), - conversationId = conversation.id, - date = event.timestampIso, - senderUserId = userId, - status = Message.Status.Sent, - visibility = Message.Visibility.VISIBLE, - expirationData = null - ) - persistMessage(message) - } - - conversationRepository.deleteUserFromConversations(userId) - .onSuccess { - kaliumLogger - .logEventProcessing( - EventLoggingStatus.SUCCESS, - event - ) - } - .onFailure { deleteFailure -> - kaliumLogger - .logEventProcessing( - EventLoggingStatus.FAILURE, - event, - Pair("errorInfo", "$deleteFailure") - ) - } - - }.onFailure { - kaliumLogger - .logEventProcessing( - EventLoggingStatus.FAILURE, - event, - Pair("errorInfo", "$it") - ) - } - } else { - kaliumLogger - .logEventProcessing( - EventLoggingStatus.SKIPPED, - event, - Pair("info", "User or User name is null") - ) - } - } - .onFailure { - kaliumLogger - .logEventProcessing( - EventLoggingStatus.FAILURE, - event, - Pair("errorInfo", "$it") - ) - } - } - private suspend fun handleMemberUpdate(event: Event.Team.MemberUpdate) = teamRepository.updateMemberRole( teamId = event.teamId, diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/UserEventReceiver.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/UserEventReceiver.kt index c3daeb7cb7d..8a9a008a7e4 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/UserEventReceiver.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/UserEventReceiver.kt @@ -182,6 +182,8 @@ internal class UserEventReceiverImpl internal constructor( logout(LogoutReason.DELETED_ACCOUNT) Either.Right(Unit) } else { + // TODO: those 2 steps must be done in one transaction + // userRepo.markAsDeleted(event.userId) will ma userRepository.removeUser(event.userId) .onSuccess { conversationRepository.deleteUserFromConversations(event.userId) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestEvent.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestEvent.kt index ef5553cc666..3b697dc360d 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestEvent.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/framework/TestEvent.kt @@ -30,7 +30,6 @@ import com.wire.kalium.logic.data.user.Connection import com.wire.kalium.logic.data.user.ConnectionState import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.util.DateTimeUtil.toIsoDateTimeString -import com.wire.kalium.util.time.Second import io.ktor.util.encodeBase64 import kotlinx.datetime.Instant @@ -156,23 +155,6 @@ object TestEvent { icon = "icon", ) - fun teamMemberJoin(eventId: String = "eventId") = Event.Team.MemberJoin( - eventId, - teamId = "teamId", - transient = false, - live = false, - memberId = "memberId" - ) - - fun teamMemberLeave(eventId: String = "eventId") = Event.Team.MemberLeave( - eventId, - teamId = "teamId", - memberId = "memberId", - timestampIso = "2022-03-30T15:36:00.000Z", - transient = false, - live = false - ) - fun teamMemberUpdate(eventId: String = "eventId", permissionCode: Int) = Event.Team.MemberUpdate( eventId, teamId = "teamId", diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/sync/receiver/TeamEventReceiverTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/sync/receiver/TeamEventReceiverTest.kt index 77bce7c129d..89840bc7b8e 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/sync/receiver/TeamEventReceiverTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/sync/receiver/TeamEventReceiverTest.kt @@ -18,15 +18,9 @@ package com.wire.kalium.logic.sync.receiver -import com.wire.kalium.logic.data.conversation.Conversation -import com.wire.kalium.logic.data.conversation.ConversationRepository -import com.wire.kalium.logic.data.message.PersistMessageUseCase import com.wire.kalium.logic.data.team.TeamRepository import com.wire.kalium.logic.data.team.TeamRole -import com.wire.kalium.logic.data.user.UserRepository -import com.wire.kalium.logic.framework.TestConversation import com.wire.kalium.logic.framework.TestEvent -import com.wire.kalium.logic.framework.TestUser import com.wire.kalium.logic.functional.Either import io.mockative.Mock import io.mockative.any @@ -35,7 +29,6 @@ import io.mockative.given import io.mockative.mock import io.mockative.once import io.mockative.verify -import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest import kotlin.test.Test @@ -56,49 +49,6 @@ class TeamEventReceiverTest { .wasInvoked(exactly = once) } - @Test - fun givenMemberJoinEvent_repoIsInvoked() = runTest { - val event = TestEvent.teamMemberJoin() - val (arrangement, eventReceiver) = Arrangement() - .withMemberJoinSuccess() - .arrange() - - eventReceiver.onEvent(event) - - verify(arrangement.teamRepository) - .suspendFunction(arrangement.teamRepository::fetchTeamMember) - .with(any(), any()) - .wasInvoked(exactly = once) - } - - @Test - fun givenMemberLeaveEvent_RepoAndPersisMessageAreInvoked() = runTest { - val event = TestEvent.teamMemberLeave() - val (arrangement, eventReceiver) = Arrangement() - .withMemberLeaveSuccess() - .withConversationsByUserId(listOf(TestConversation.CONVERSATION)) - .withPersistMessageSuccess() - .arrange() - - eventReceiver.onEvent(event) - - verify(arrangement.teamRepository) - .suspendFunction(arrangement.teamRepository::removeTeamMember) - .with(any(), any()) - .wasInvoked(exactly = once) - - verify(arrangement.conversationRepository) - .suspendFunction(arrangement.conversationRepository::deleteUserFromConversations) - .with(any()) - .wasInvoked(exactly = once) - - verify(arrangement.persistMessageUseCase) - .suspendFunction(arrangement.persistMessageUseCase::invoke) - .with(any()) - .wasInvoked(exactly = once) - - } - @Test fun givenMemberUpdateEvent_RepoIsInvoked() = runTest { val event = TestEvent.teamMemberUpdate(permissionCode = TeamRole.Member.value) @@ -118,28 +68,10 @@ class TeamEventReceiverTest { @Mock val teamRepository = mock(classOf()) - @Mock - val conversationRepository = mock(classOf()) - - @Mock - val userRepository = mock(classOf()) - - @Mock - val persistMessageUseCase = mock(classOf()) - private val teamEventReceiver: TeamEventReceiver = TeamEventReceiverImpl( - teamRepository, conversationRepository, userRepository, persistMessageUseCase, - TestUser.USER_ID + teamRepository ) - init { - apply { - given(userRepository).suspendFunction(userRepository::getKnownUser) - .whenInvokedWith(any()) - .thenReturn(flowOf(TestUser.OTHER)) - } - } - fun withUpdateTeamSuccess() = apply { given(teamRepository).suspendFunction(teamRepository::updateTeam).whenInvokedWith(any()) .thenReturn(Either.Right(Unit)) @@ -150,28 +82,11 @@ class TeamEventReceiverTest { .whenInvokedWith(any(), any()).thenReturn(Either.Right(Unit)) } - fun withMemberLeaveSuccess() = apply { - given(teamRepository).suspendFunction(teamRepository::removeTeamMember) - .whenInvokedWith(any(), any()).thenReturn(Either.Right(Unit)) - given(conversationRepository).suspendFunction(conversationRepository::deleteUserFromConversations) - .whenInvokedWith(any()).thenReturn(Either.Right(Unit)) - } - fun withMemberUpdateSuccess() = apply { given(teamRepository).suspendFunction(teamRepository::updateMemberRole) .whenInvokedWith(any(), any(), any()).thenReturn(Either.Right(Unit)) } - fun withConversationsByUserId(conversationIds: List) = apply { - given(conversationRepository).suspendFunction(conversationRepository::getConversationsByUserId) - .whenInvokedWith(any()).thenReturn(Either.Right(conversationIds)) - } - - fun withPersistMessageSuccess() = apply { - given(persistMessageUseCase).suspendFunction(persistMessageUseCase::invoke) - .whenInvokedWith(any()).thenReturn(Either.Right(Unit)) - } - fun arrange() = this to teamEventReceiver } } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/notification/EventContentDTO.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/notification/EventContentDTO.kt index 84b3bc90621..f868c30a175 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/notification/EventContentDTO.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/notification/EventContentDTO.kt @@ -37,7 +37,6 @@ import com.wire.kalium.network.api.base.authenticated.featureConfigs.FeatureFlag import com.wire.kalium.network.api.base.authenticated.keypackage.LastPreKeyDTO import com.wire.kalium.network.api.base.authenticated.notification.conversation.MessageEventData import com.wire.kalium.network.api.base.authenticated.notification.team.PermissionsData -import com.wire.kalium.network.api.base.authenticated.notification.team.TeamMemberIdData import com.wire.kalium.network.api.base.authenticated.notification.team.TeamUpdateData import com.wire.kalium.network.api.base.authenticated.notification.user.RemoveClientEventData import com.wire.kalium.network.api.base.authenticated.notification.user.UserUpdateEventData @@ -291,22 +290,6 @@ sealed class EventContentDTO { val time: String, ) : Team() - @Serializable - @SerialName("team.member-join") - data class MemberJoin( - @SerialName("data") val teamMember: TeamMemberIdData, - @SerialName("team") val teamId: TeamId, - val time: String, - ) : Team() - - @Serializable - @SerialName("team.member-leave") - data class MemberLeave( - @SerialName("data") val teamMember: TeamMemberIdData, - @SerialName("team") val teamId: TeamId, - val time: String, - ) : Team() - @Serializable @SerialName("team.member-update") data class MemberUpdate( diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageEntity.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageEntity.kt index 3e37afeadd5..5d779add717 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageEntity.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageEntity.kt @@ -327,6 +327,8 @@ sealed class MessageEntityContent { data object MissedCall : System() data object CryptoSessionReset : System() data class ConversationRenamed(val conversationName: String) : System() + + @Deprecated("not maintained and will be deleted") data class TeamMemberRemoved(val userName: String) : System() data class NewConversationReceiptMode(val receiptMode: Boolean) : System() data class ConversationReceiptModeChanged(val receiptMode: Boolean) : System() From f8b547f9b56b7c3a4329cb381e93c4de5c30ed0f Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Tue, 28 Nov 2023 15:58:29 +0100 Subject: [PATCH 2/4] fix tests --- .../logic/data/team/TeamRepositoryTest.kt | 38 ------------------- .../sync/receiver/TeamEventReceiverTest.kt | 5 --- 2 files changed, 43 deletions(-) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/team/TeamRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/team/TeamRepositoryTest.kt index ea8455f2e86..39606df0971 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/team/TeamRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/team/TeamRepositoryTest.kt @@ -28,7 +28,6 @@ import com.wire.kalium.logic.framework.TestUser import com.wire.kalium.logic.util.shouldFail import com.wire.kalium.logic.util.shouldSucceed import com.wire.kalium.network.api.base.authenticated.TeamsApi -import com.wire.kalium.network.api.base.authenticated.userDetails.UserDetailsApi import com.wire.kalium.network.api.base.model.ErrorResponse import com.wire.kalium.network.api.base.model.ServiceDetailDTO import com.wire.kalium.network.api.base.model.ServiceDetailResponse @@ -168,27 +167,6 @@ class TeamRepositoryTest { .wasInvoked(once) } - @Test - fun givenTeamIdAndUserId_whenFetchingTeamMember_thenTeamMemberShouldBeSuccessful() = runTest { - val teamMemberDTO = TestTeam.memberDTO( - nonQualifiedUserId = "teamMember1" - ) - - val (arrangement, teamRepository) = Arrangement() - .withApiGetTeamMemberSuccess(teamMemberDTO) - .withGetUsersInfoSuccess() - .arrange() - - val result = teamRepository.fetchTeamMember("teamId", "userId") - - result.shouldSucceed() - - verify(arrangement.userDAO) - .suspendFunction(arrangement.userDAO::upsertUser) - .with(any()) - .wasInvoked(once) - } - @Test fun givenTeamId_whenSyncingWhitelistedServices_thenInsertIntoDatabase() = runTest { // given @@ -213,7 +191,6 @@ class TeamRepositoryTest { // given val (arrangement, teamRepository) = Arrangement() .withApiApproveLegalHoldSuccess() - .withGetUsersInfoSuccess() .arrange() // when val result = teamRepository.approveLegalHoldRequest(teamId = TeamId(value = "teamId"), password = "password") @@ -242,15 +219,9 @@ class TeamRepositoryTest { val teamMapper = MapperProvider.teamMapper() - @Mock - val userMapper = MapperProvider.userMapper() - @Mock val teamsApi = mock(classOf()) - @Mock - val userDetailsApi = mock(classOf()) - @Mock val serviceDAO = configure(mock(classOf())) { stubsUnitByDefault = true @@ -260,10 +231,8 @@ class TeamRepositoryTest { teamDAO = teamDAO, teamMapper = teamMapper, teamsApi = teamsApi, - userDetailsApi = userDetailsApi, userDAO = userDAO, userConfigDAO = userConfigDAO, - userMapper = userMapper, selfUserId = TestUser.USER_ID, serviceDAO = serviceDAO ) @@ -275,13 +244,6 @@ class TeamRepositoryTest { .then { NetworkResponse.Success(value = teamDTO, headers = mapOf(), httpCode = 200) } } - fun withGetUsersInfoSuccess() = apply { - given(userDetailsApi) - .suspendFunction(userDetailsApi::getUserInfo) - .whenInvokedWith(any()) - .thenReturn(NetworkResponse.Success(TestUser.USER_PROFILE_DTO, mapOf(), 200)) - } - fun withApiGetTeamMemberSuccess(teamMemberDTO: TeamsApi.TeamMemberDTO) = apply { given(teamsApi) .suspendFunction(teamsApi::getTeamMember) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/sync/receiver/TeamEventReceiverTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/sync/receiver/TeamEventReceiverTest.kt index 89840bc7b8e..6c37a45f5ab 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/sync/receiver/TeamEventReceiverTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/sync/receiver/TeamEventReceiverTest.kt @@ -77,11 +77,6 @@ class TeamEventReceiverTest { .thenReturn(Either.Right(Unit)) } - fun withMemberJoinSuccess() = apply { - given(teamRepository).suspendFunction(teamRepository::fetchTeamMember) - .whenInvokedWith(any(), any()).thenReturn(Either.Right(Unit)) - } - fun withMemberUpdateSuccess() = apply { given(teamRepository).suspendFunction(teamRepository::updateMemberRole) .whenInvokedWith(any(), any(), any()).thenReturn(Either.Right(Unit)) From 024c1caad23213f7fc048187c20f0515a999be07 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Wed, 29 Nov 2023 09:39:22 +0100 Subject: [PATCH 3/4] merge issues --- .../kotlin/com/wire/kalium/logic/data/team/TeamRepository.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/team/TeamRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/team/TeamRepository.kt index fb872c098a2..bff6be63d70 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/team/TeamRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/team/TeamRepository.kt @@ -37,6 +37,8 @@ import com.wire.kalium.logic.sync.receiver.handler.legalhold.LegalHoldRequestHan import com.wire.kalium.logic.wrapApiRequest import com.wire.kalium.logic.wrapStorageRequest import com.wire.kalium.network.api.base.authenticated.TeamsApi +import com.wire.kalium.network.api.base.authenticated.notification.EventContentDTO +import com.wire.kalium.network.api.base.model.LegalHoldStatusDTO import com.wire.kalium.persistence.dao.QualifiedIDEntity import com.wire.kalium.persistence.dao.ServiceDAO import com.wire.kalium.persistence.dao.TeamDAO From ff7672c7f6b3d473278e7b7b44e9d54e1500a006 Mon Sep 17 00:00:00 2001 From: MohamadJaara Date: Wed, 29 Nov 2023 14:29:51 +0100 Subject: [PATCH 4/4] missing comment --- .../com/wire/kalium/logic/sync/receiver/UserEventReceiver.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/UserEventReceiver.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/UserEventReceiver.kt index 8a9a008a7e4..fa016d0e897 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/UserEventReceiver.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/UserEventReceiver.kt @@ -183,7 +183,7 @@ internal class UserEventReceiverImpl internal constructor( Either.Right(Unit) } else { // TODO: those 2 steps must be done in one transaction - // userRepo.markAsDeleted(event.userId) will ma + // userRepo.markAsDeleted(event.userId) will mark user as deleted and remove from the group conversations userRepository.removeUser(event.userId) .onSuccess { conversationRepository.deleteUserFromConversations(event.userId)