diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/Asset.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/Asset.kt index 7daac349e36..1f845b70ad1 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/Asset.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/asset/Asset.kt @@ -22,7 +22,7 @@ import okio.Path data class UploadedAssetId( val key: String, - val domain: String? = null, + val domain: String, val assetToken: String? = null ) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionMapper.kt index e6bc1fb71a1..e0aea32afbf 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionMapper.kt @@ -23,8 +23,8 @@ import com.wire.kalium.logic.data.conversation.ConversationDetails import com.wire.kalium.logic.data.id.IdMapper import com.wire.kalium.logic.data.id.toDao import com.wire.kalium.logic.data.id.toModel -import com.wire.kalium.logic.data.publicuser.PublicUserMapper import com.wire.kalium.logic.data.user.Connection +import com.wire.kalium.logic.data.user.UserMapper import com.wire.kalium.logic.data.user.type.DomainUserTypeMapper import com.wire.kalium.logic.data.user.type.UserType import com.wire.kalium.logic.di.MapperProvider @@ -46,7 +46,7 @@ interface ConnectionMapper { internal class ConnectionMapperImpl( private val idMapper: IdMapper = MapperProvider.idMapper(), private val statusMapper: ConnectionStatusMapper = MapperProvider.connectionStatusMapper(), - private val publicUserMapper: PublicUserMapper = MapperProvider.publicUserMapper(), + private val userMapper: UserMapper = MapperProvider.userMapper(), private val userTypeMapper: DomainUserTypeMapper = MapperProvider.userTypeMapper(), ) : ConnectionMapper { override fun fromApiToDao(state: ConnectionDTO): ConnectionEntity = ConnectionEntity( @@ -68,14 +68,14 @@ internal class ConnectionMapperImpl( qualifiedToId = qualifiedToId.toModel(), status = statusMapper.fromDaoModel(status), toId = toId, - fromUser = otherUser?.let { publicUserMapper.fromUserDetailsEntityToOtherUser(it) } + fromUser = otherUser?.let { userMapper.fromUserDetailsEntityToOtherUser(it) } ) } override fun fromDaoToConversationDetails(connection: ConnectionEntity): ConversationDetails = with(connection) { ConversationDetails.Connection( conversationId = qualifiedConversationId.toModel(), - otherUser = otherUser?.let { publicUserMapper.fromUserDetailsEntityToOtherUser(it) }, + otherUser = otherUser?.let { userMapper.fromUserDetailsEntityToOtherUser(it) }, userType = otherUser?.let { userTypeMapper.fromUserTypeEntity(it.userType) } ?: UserType.GUEST, lastModifiedDate = lastUpdateDate.toIsoDateTimeString(), connection = fromDaoToModel(this), diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/publicuser/PublicUserMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/publicuser/PublicUserMapper.kt deleted file mode 100644 index effb61eb294..00000000000 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/publicuser/PublicUserMapper.kt +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Wire - * Copyright (C) 2023 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.publicuser - -import com.wire.kalium.logic.data.id.QualifiedID -import com.wire.kalium.logic.data.id.TeamId -import com.wire.kalium.logic.data.id.toDao -import com.wire.kalium.logic.data.id.toModel -import com.wire.kalium.logic.data.message.UserSummary -import com.wire.kalium.logic.data.user.AvailabilityStatusMapper -import com.wire.kalium.logic.data.user.BotService -import com.wire.kalium.logic.data.user.ConnectionState -import com.wire.kalium.logic.data.user.ConnectionStateMapper -import com.wire.kalium.logic.data.user.OtherUser -import com.wire.kalium.logic.data.user.OtherUserMinimized -import com.wire.kalium.logic.data.user.SupportedProtocol -import com.wire.kalium.logic.data.user.UserAvailabilityStatus -import com.wire.kalium.logic.data.user.UserId -import com.wire.kalium.logic.data.user.toDao -import com.wire.kalium.logic.data.user.toModel -import com.wire.kalium.logic.data.user.type.DomainUserTypeMapper -import com.wire.kalium.logic.data.user.type.UserEntityTypeMapper -import com.wire.kalium.logic.data.user.type.UserType -import com.wire.kalium.logic.di.MapperProvider -import com.wire.kalium.network.api.base.model.UserProfileDTO -import com.wire.kalium.network.api.base.model.getCompleteAssetOrNull -import com.wire.kalium.network.api.base.model.getPreviewAssetOrNull -import com.wire.kalium.persistence.dao.BotIdEntity -import com.wire.kalium.persistence.dao.UserDetailsEntity -import com.wire.kalium.persistence.dao.UserEntity -import com.wire.kalium.persistence.dao.UserEntityMinimized -import kotlinx.datetime.toInstant - -interface PublicUserMapper { - fun fromUserEntityToOtherUser(userEntity: UserEntity): OtherUser - fun fromOtherToUserEntity(otherUser: OtherUser): UserEntity - fun fromUserEntityToOtherUserMinimized(userEntity: UserEntityMinimized): OtherUserMinimized - fun fromUserProfileDtoToOtherUser( - userDetailResponse: UserProfileDTO, - // UserProfileDTO has no info about userType, we need to pass it explicitly - userType: UserType - ): OtherUser - - fun fromEntityToUserSummary(userEntity: UserEntity): UserSummary - fun fromUserDetailsEntityToUserSummary(userDetailsEntity: UserDetailsEntity): UserSummary - fun fromUserDetailsEntityToOtherUser(userDetailsEntity: UserDetailsEntity): OtherUser - fun fromOtherToUserDetailsEntity(otherUser: OtherUser): UserDetailsEntity -} - -class PublicUserMapperImpl( - private val availabilityStatusMapper: AvailabilityStatusMapper = MapperProvider.availabilityStatusMapper(), - private val connectionStateMapper: ConnectionStateMapper = MapperProvider.connectionStateMapper(), - private val domainUserTypeMapper: DomainUserTypeMapper = MapperProvider.userTypeMapper(), - private val userEntityTypeMapper: UserEntityTypeMapper = MapperProvider.userTypeEntityMapper() -) : PublicUserMapper { - - override fun fromUserEntityToOtherUser(userEntity: UserEntity) = OtherUser( - id = userEntity.id.toModel(), - name = userEntity.name, - handle = userEntity.handle, - email = userEntity.email, - phone = userEntity.phone, - accentId = userEntity.accentId, - teamId = userEntity.team?.let { TeamId(it) }, - connectionStatus = connectionStateMapper.fromDaoConnectionStateToUser(connectionState = userEntity.connectionStatus), - previewPicture = userEntity.previewAssetId?.toModel(), - completePicture = userEntity.completeAssetId?.toModel(), - availabilityStatus = availabilityStatusMapper.fromDaoAvailabilityStatusToModel(userEntity.availabilityStatus), - userType = domainUserTypeMapper.fromUserTypeEntity(userEntity.userType), - botService = userEntity.botService?.let { BotService(it.id, it.provider) }, - deleted = userEntity.deleted, - expiresAt = userEntity.expiresAt, - defederated = userEntity.defederated, - isProteusVerified = false, - supportedProtocols = userEntity.supportedProtocols?.toModel(), - activeOneOnOneConversationId = userEntity.activeOneOnOneConversationId?.toModel() - ) - - override fun fromUserDetailsEntityToOtherUser(userDetailsEntity: UserDetailsEntity) = OtherUser( - id = userDetailsEntity.id.toModel(), - name = userDetailsEntity.name, - handle = userDetailsEntity.handle, - email = userDetailsEntity.email, - phone = userDetailsEntity.phone, - accentId = userDetailsEntity.accentId, - teamId = userDetailsEntity.team?.let { TeamId(it) }, - connectionStatus = connectionStateMapper.fromDaoConnectionStateToUser(connectionState = userDetailsEntity.connectionStatus), - previewPicture = userDetailsEntity.previewAssetId?.toModel(), - completePicture = userDetailsEntity.completeAssetId?.toModel(), - availabilityStatus = availabilityStatusMapper.fromDaoAvailabilityStatusToModel(userDetailsEntity.availabilityStatus), - userType = domainUserTypeMapper.fromUserTypeEntity(userDetailsEntity.userType), - botService = userDetailsEntity.botService?.let { BotService(it.id, it.provider) }, - deleted = userDetailsEntity.deleted, - expiresAt = userDetailsEntity.expiresAt, - defederated = userDetailsEntity.defederated, - isProteusVerified = userDetailsEntity.isProteusVerified, - supportedProtocols = userDetailsEntity.supportedProtocols?.toModel() - ) - - override fun fromOtherToUserEntity(otherUser: OtherUser): UserEntity = with(otherUser) { - UserEntity( - id = id.toDao(), - name = name, - handle = handle, - email = email, - phone = phone, - accentId = accentId, - team = teamId?.value, - connectionStatus = connectionStateMapper.fromUserConnectionStateToDao(connectionStatus), - previewAssetId = previewPicture?.toDao(), - completeAssetId = completePicture?.toDao(), - availabilityStatus = availabilityStatusMapper.fromModelAvailabilityStatusToDao(availabilityStatus), - userType = userEntityTypeMapper.fromUserType(userType), - botService = botService?.let { BotIdEntity(it.id, it.provider) }, - deleted = deleted, - expiresAt = expiresAt, - hasIncompleteMetadata = false, - defederated = defederated, - supportedProtocols = supportedProtocols?.toDao(), - activeOneOnOneConversationId = activeOneOnOneConversationId?.toDao() - ) - } - - override fun fromOtherToUserDetailsEntity(otherUser: OtherUser): UserDetailsEntity = with(otherUser) { - UserDetailsEntity( - id = id.toDao(), - name = name, - handle = handle, - email = email, - phone = phone, - accentId = accentId, - team = teamId?.value, - connectionStatus = connectionStateMapper.fromUserConnectionStateToDao(connectionStatus), - previewAssetId = previewPicture?.toDao(), - completeAssetId = completePicture?.toDao(), - availabilityStatus = availabilityStatusMapper.fromModelAvailabilityStatusToDao(availabilityStatus), - userType = userEntityTypeMapper.fromUserType(userType), - botService = botService?.let { BotIdEntity(it.id, it.provider) }, - deleted = deleted, - expiresAt = expiresAt, - hasIncompleteMetadata = false, - defederated = defederated, - isProteusVerified = otherUser.isProteusVerified, - supportedProtocols = supportedProtocols?.toDao(), - activeOneOnOneConversationId = activeOneOnOneConversationId?.toDao() - ) - } - - override fun fromUserEntityToOtherUserMinimized(userEntity: UserEntityMinimized): OtherUserMinimized = - OtherUserMinimized( - id = userEntity.id.toModel(), - name = userEntity.name, - completePicture = userEntity.completeAssetId?.toModel(), - userType = domainUserTypeMapper.fromUserTypeEntity(userEntity.userType), - ) - - override fun fromUserProfileDtoToOtherUser( - userDetailResponse: UserProfileDTO, - userType: UserType - ) = OtherUser( - id = UserId(userDetailResponse.id.value, userDetailResponse.id.domain), - name = userDetailResponse.name, - handle = userDetailResponse.handle, - accentId = userDetailResponse.accentId, - teamId = userDetailResponse.teamId?.let { TeamId(it) }, - connectionStatus = ConnectionState.NOT_CONNECTED, - previewPicture = userDetailResponse.assets.getPreviewAssetOrNull() - ?.let { QualifiedID(it.key, userDetailResponse.id.domain) }, - completePicture = userDetailResponse.assets.getCompleteAssetOrNull() - ?.let { QualifiedID(it.key, userDetailResponse.id.domain) }, - availabilityStatus = UserAvailabilityStatus.NONE, - userType = userType, - botService = userDetailResponse.service?.let { BotService(it.id, it.provider) }, - deleted = userDetailResponse.deleted ?: false, - expiresAt = userDetailResponse.expiresAt?.toInstant(), - defederated = false, - isProteusVerified = false, - supportedProtocols = userDetailResponse.supportedProtocols?.toModel() ?: setOf(SupportedProtocol.PROTEUS) - ) - - override fun fromEntityToUserSummary(userEntity: UserEntity) = with(userEntity) { - UserSummary( - userId = UserId(id.value, id.domain), - userHandle = handle, - userName = name, - userPreviewAssetId = previewAssetId?.toModel(), - userType = domainUserTypeMapper.fromUserTypeEntity(userType), - isUserDeleted = deleted, - availabilityStatus = availabilityStatusMapper.fromDaoAvailabilityStatusToModel(availabilityStatus), - connectionStatus = connectionStateMapper.fromDaoConnectionStateToUser(connectionStatus) - ) - } - - override fun fromUserDetailsEntityToUserSummary(userDetailsEntity: UserDetailsEntity): UserSummary = with(userDetailsEntity) { - UserSummary( - userId = UserId(id.value, id.domain), - userHandle = handle, - userName = name, - userPreviewAssetId = previewAssetId?.toModel(), - userType = domainUserTypeMapper.fromUserTypeEntity(userType), - isUserDeleted = deleted, - availabilityStatus = availabilityStatusMapper.fromDaoAvailabilityStatusToModel(availabilityStatus), - connectionStatus = connectionStateMapper.fromDaoConnectionStateToUser(connectionStatus) - ) - } -} diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/publicuser/SearchUserRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/publicuser/SearchUserRepository.kt index e59e1bf70ea..1c7b72d7970 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/publicuser/SearchUserRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/publicuser/SearchUserRepository.kt @@ -26,7 +26,7 @@ import com.wire.kalium.logic.data.publicuser.model.UserSearchResult import com.wire.kalium.logic.data.user.SelfUser import com.wire.kalium.logic.data.user.UserDataSource import com.wire.kalium.logic.data.user.UserMapper -import com.wire.kalium.logic.data.user.type.DomainUserTypeMapper +import com.wire.kalium.logic.data.user.type.UserEntityTypeMapper import com.wire.kalium.logic.di.MapperProvider import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.functional.flatMap @@ -92,9 +92,8 @@ internal class SearchUserRepositoryImpl( private val metadataDAO: MetadataDAO, private val userDetailsApi: UserDetailsApi, private val userSearchAPiWrapper: UserSearchApiWrapper, - private val publicUserMapper: PublicUserMapper = MapperProvider.publicUserMapper(), private val userMapper: UserMapper = MapperProvider.userMapper(), - private val userTypeMapper: DomainUserTypeMapper = MapperProvider.userTypeMapper() + private val userTypeEntityMapper: UserEntityTypeMapper = MapperProvider.userTypeEntityMapper() ) : SearchUserRepository { override suspend fun searchKnownUsersByNameOrHandleOrEmail( @@ -159,16 +158,7 @@ internal class SearchUserRepositoryImpl( val otherUserList = if (userProfileDTOList.isEmpty()) emptyList() else { val selfUser = getSelfUser() userProfileDTOList.map { userProfileDTO -> - publicUserMapper.fromUserProfileDtoToOtherUser( - userDetailResponse = userProfileDTO, - userType = userTypeMapper.fromTeamAndDomain( - otherUserDomain = userProfileDTO.id.domain, - selfUserTeamId = selfUser.teamId?.value, - otherUserTeamId = userProfileDTO.teamId, - selfUserDomain = selfUser.id.domain, - isService = userProfileDTO.service != null, - ) - ) + userMapper.fromUserProfileDtoToOtherUser(userProfileDTO, selfUser) } } UserSearchResult(otherUserList) @@ -202,7 +192,7 @@ internal class SearchUserRepositoryImpl( } return listFlow.map { - UserSearchResult(it.map(publicUserMapper::fromUserDetailsEntityToOtherUser)) + UserSearchResult(it.map(userMapper::fromUserDetailsEntityToOtherUser)) } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserMapper.kt index 0fd650a89b4..1f35ad6bd45 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserMapper.kt @@ -24,6 +24,9 @@ import com.wire.kalium.logic.data.id.NetworkQualifiedId import com.wire.kalium.logic.data.id.TeamId import com.wire.kalium.logic.data.id.toDao import com.wire.kalium.logic.data.id.toModel +import com.wire.kalium.logic.data.message.UserSummary +import com.wire.kalium.logic.data.user.type.DomainUserTypeMapper +import com.wire.kalium.logic.data.user.type.UserEntityTypeMapper import com.wire.kalium.logic.di.MapperProvider import com.wire.kalium.network.api.base.authenticated.self.UserUpdateRequest import com.wire.kalium.network.api.base.model.AssetSizeDTO @@ -42,15 +45,20 @@ import com.wire.kalium.persistence.dao.SupportedProtocolEntity import com.wire.kalium.persistence.dao.UserAvailabilityStatusEntity import com.wire.kalium.persistence.dao.UserDetailsEntity import com.wire.kalium.persistence.dao.UserEntity +import com.wire.kalium.persistence.dao.UserEntityMinimized import com.wire.kalium.persistence.dao.UserTypeEntity import kotlinx.datetime.toInstant @Suppress("TooManyFunctions") interface UserMapper { - fun fromSelfUserDtoToUserEntity(userDTO: SelfUserDTO): UserEntity + fun fromSelfUserToUserEntity(selfUser: SelfUser): UserEntity + fun fromOtherToUserEntity(otherUser: OtherUser): UserEntity fun fromUserEntityToSelfUser(userEntity: UserEntity): SelfUser fun fromUserDetailsEntityToSelfUser(userEntity: UserDetailsEntity): SelfUser - fun fromSelfUserToUserEntity(selfUser: SelfUser): UserEntity + fun fromUserEntityToOtherUser(userEntity: UserEntity): OtherUser + fun fromUserDetailsEntityToOtherUser(userEntity: UserDetailsEntity): OtherUser + fun fromUserEntityToOtherUserMinimized(userEntity: UserEntityMinimized): OtherUserMinimized + fun fromEntityToUserSummary(userEntity: UserEntity): UserSummary /** * Maps the user data to be updated. if the parameters [newName] [newAccent] [newAssetId] are nulls, @@ -59,43 +67,38 @@ interface UserMapper { * TODO(assets): handle deletion of assets references, emptyAssetList */ fun fromModelToUpdateApiModel( - user: SelfUser, newName: String?, newAccent: Int?, newAssetId: String? ): UserUpdateRequest - fun fromUpdateRequestToDaoModel( - user: SelfUser, - updateRequest: UserUpdateRequest - ): UserEntity + fun fromUpdateRequestToPartialUserEntity( + updateRequest: UserUpdateRequest, + selfUserId: UserId, + ): PartialUserEntity fun fromUserUpdateEventToPartialUserEntity(event: Event.User.Update): PartialUserEntity + fun fromSelfUserDtoToUserEntity(userDTO: SelfUserDTO): UserEntity + fun fromUserProfileDtoToUserEntity( userProfile: UserProfileDTO, connectionState: ConnectionEntity.State, userTypeEntity: UserTypeEntity ): UserEntity - fun fromFailedUserToEntity(userId: NetworkQualifiedId): UserEntity - fun fromSelfUserToUserDetailsEntity(selfUser: SelfUser): UserDetailsEntity - fun fromSelfUserDtoToUserDetailsEntity(userDTO: SelfUserDTO): UserDetailsEntity + fun fromUserProfileDtoToOtherUser(userProfile: UserProfileDTO, selfUser: SelfUser): OtherUser - fun fromUserProfileDtoToUserDetailsEntity( - userProfile: UserProfileDTO, - connectionState: ConnectionEntity.State, - userTypeEntity: UserTypeEntity - ): UserDetailsEntity - - fun fromFailedUserToDetailsEntity(userId: NetworkQualifiedId): UserDetailsEntity + fun fromFailedUserToEntity(userId: NetworkQualifiedId): UserEntity } @Suppress("TooManyFunctions") internal class UserMapperImpl( private val idMapper: IdMapper = MapperProvider.idMapper(), + private val domainUserTypeMapper: DomainUserTypeMapper = MapperProvider.userTypeMapper(), private val availabilityStatusMapper: AvailabilityStatusMapper = MapperProvider.availabilityStatusMapper(), - private val connectionStateMapper: ConnectionStateMapper = MapperProvider.connectionStateMapper() + private val connectionStateMapper: ConnectionStateMapper = MapperProvider.connectionStateMapper(), + private val userEntityTypeMapper: UserEntityTypeMapper = MapperProvider.userTypeEntityMapper() ) : UserMapper { override fun fromUserEntityToSelfUser(userEntity: UserEntity) = with(userEntity) { @@ -134,6 +137,71 @@ internal class UserMapperImpl( ) } + override fun fromUserEntityToOtherUser(userEntity: UserEntity) = OtherUser( + id = userEntity.id.toModel(), + name = userEntity.name, + handle = userEntity.handle, + email = userEntity.email, + phone = userEntity.phone, + accentId = userEntity.accentId, + teamId = userEntity.team?.let { TeamId(it) }, + connectionStatus = connectionStateMapper.fromDaoConnectionStateToUser(connectionState = userEntity.connectionStatus), + previewPicture = userEntity.previewAssetId?.toModel(), + completePicture = userEntity.completeAssetId?.toModel(), + availabilityStatus = availabilityStatusMapper.fromDaoAvailabilityStatusToModel(userEntity.availabilityStatus), + userType = domainUserTypeMapper.fromUserTypeEntity(userEntity.userType), + botService = userEntity.botService?.let { BotService(it.id, it.provider) }, + deleted = userEntity.deleted, + expiresAt = userEntity.expiresAt, + defederated = userEntity.defederated, + isProteusVerified = false, + supportedProtocols = userEntity.supportedProtocols?.toModel(), + activeOneOnOneConversationId = userEntity.activeOneOnOneConversationId?.toModel() + ) + + override fun fromUserDetailsEntityToOtherUser(userEntity: UserDetailsEntity): OtherUser = OtherUser( + id = userEntity.id.toModel(), + name = userEntity.name, + handle = userEntity.handle, + email = userEntity.email, + phone = userEntity.phone, + accentId = userEntity.accentId, + teamId = userEntity.team?.let { TeamId(it) }, + connectionStatus = connectionStateMapper.fromDaoConnectionStateToUser(connectionState = userEntity.connectionStatus), + previewPicture = userEntity.previewAssetId?.toModel(), + completePicture = userEntity.completeAssetId?.toModel(), + availabilityStatus = availabilityStatusMapper.fromDaoAvailabilityStatusToModel(userEntity.availabilityStatus), + userType = domainUserTypeMapper.fromUserTypeEntity(userEntity.userType), + botService = userEntity.botService?.let { BotService(it.id, it.provider) }, + deleted = userEntity.deleted, + expiresAt = userEntity.expiresAt, + defederated = userEntity.defederated, + isProteusVerified = userEntity.isProteusVerified, + supportedProtocols = userEntity.supportedProtocols?.toModel(), + activeOneOnOneConversationId = userEntity.activeOneOnOneConversationId?.toModel() + ) + + override fun fromUserEntityToOtherUserMinimized(userEntity: UserEntityMinimized): OtherUserMinimized = + OtherUserMinimized( + id = userEntity.id.toModel(), + name = userEntity.name, + completePicture = userEntity.completeAssetId?.toModel(), + userType = domainUserTypeMapper.fromUserTypeEntity(userEntity.userType), + ) + + override fun fromEntityToUserSummary(userEntity: UserEntity) = with(userEntity) { + UserSummary( + userId = UserId(id.value, id.domain), + userHandle = handle, + userName = name, + userPreviewAssetId = previewAssetId?.toModel(), + userType = domainUserTypeMapper.fromUserTypeEntity(userType), + isUserDeleted = deleted, + availabilityStatus = availabilityStatusMapper.fromDaoAvailabilityStatusToModel(availabilityStatus), + connectionStatus = connectionStateMapper.fromDaoConnectionStateToUser(connectionStatus) + ) + } + override fun fromSelfUserToUserEntity(selfUser: SelfUser): UserEntity = with(selfUser) { UserEntity( id = id.toDao(), @@ -157,8 +225,8 @@ internal class UserMapperImpl( ) } - override fun fromSelfUserToUserDetailsEntity(selfUser: SelfUser): UserDetailsEntity = with(selfUser) { - UserDetailsEntity( + override fun fromOtherToUserEntity(otherUser: OtherUser): UserEntity = with(otherUser) { + UserEntity( id = id.toDao(), name = name, handle = handle, @@ -170,14 +238,14 @@ internal class UserMapperImpl( previewAssetId = previewPicture?.toDao(), completeAssetId = completePicture?.toDao(), availabilityStatus = availabilityStatusMapper.fromModelAvailabilityStatusToDao(availabilityStatus), - userType = UserTypeEntity.STANDARD, - botService = null, - deleted = false, + userType = userEntityTypeMapper.fromUserType(userType), + botService = botService?.let { BotIdEntity(it.id, it.provider) }, + deleted = deleted, expiresAt = expiresAt, - defederated = false, - isProteusVerified = false, - supportedProtocols = supportedProtocols?.toDao() ?: setOf(SupportedProtocolEntity.PROTEUS), - activeOneOnOneConversationId = null + hasIncompleteMetadata = false, + defederated = defederated, + supportedProtocols = supportedProtocols?.toDao(), + activeOneOnOneConversationId = activeOneOnOneConversationId?.toDao() ) } @@ -203,31 +271,7 @@ internal class UserMapperImpl( ) } - override fun fromSelfUserDtoToUserDetailsEntity(userDTO: SelfUserDTO): UserDetailsEntity = with(userDTO) { - UserDetailsEntity( - id = idMapper.fromApiToDao(id), - name = name, - handle = handle, - email = email, - phone = phone, - accentId = accentId, - team = teamId, - previewAssetId = assets.getPreviewAssetOrNull()?.let { QualifiedIDEntity(it.key, id.domain) }, - completeAssetId = assets.getCompleteAssetOrNull()?.let { QualifiedIDEntity(it.key, id.domain) }, - availabilityStatus = UserAvailabilityStatusEntity.NONE, - userType = UserTypeEntity.STANDARD, - botService = null, - deleted = userDTO.deleted ?: false, - expiresAt = expiresAt?.toInstant(), - defederated = false, - isProteusVerified = false, - supportedProtocols = supportedProtocols?.toDao() ?: setOf(SupportedProtocolEntity.PROTEUS), - activeOneOnOneConversationId = null - ) - } - override fun fromModelToUpdateApiModel( - user: SelfUser, newName: String?, newAccent: Int?, newAssetId: String? @@ -244,16 +288,13 @@ internal class UserMapperImpl( ) } - override fun fromUpdateRequestToDaoModel( - user: SelfUser, - updateRequest: UserUpdateRequest - ): UserEntity = - fromSelfUserToUserEntity( - user.copy( - previewPicture = updateRequest.assets.getPreviewAssetOrNull()?.toModel(user.id.domain), - completePicture = updateRequest.assets.getCompleteAssetOrNull()?.toModel(user.id.domain) - ) - ) + override fun fromUpdateRequestToPartialUserEntity( + updateRequest: UserUpdateRequest, + selfUserId: UserId, + ): PartialUserEntity = PartialUserEntity( + previewAssetId = updateRequest.assets.getPreviewAssetOrNull()?.toDao(selfUserId.domain), + completeAssetId = updateRequest.assets.getCompleteAssetOrNull()?.toDao(selfUserId.domain) + ) override fun fromUserProfileDtoToUserEntity( userProfile: UserProfileDTO, @@ -282,33 +323,20 @@ internal class UserMapperImpl( activeOneOnOneConversationId = null ) - override fun fromUserProfileDtoToUserDetailsEntity( - userProfile: UserProfileDTO, - connectionState: ConnectionEntity.State, - userTypeEntity: UserTypeEntity - ) = UserDetailsEntity( - id = idMapper.fromApiToDao(userProfile.id), - name = userProfile.name, - handle = userProfile.handle, - email = userProfile.email, - phone = null, - accentId = userProfile.accentId, - team = userProfile.teamId, - previewAssetId = userProfile.assets.getPreviewAssetOrNull() - ?.let { QualifiedIDEntity(it.key, userProfile.id.domain) }, - completeAssetId = userProfile.assets.getCompleteAssetOrNull() - ?.let { QualifiedIDEntity(it.key, userProfile.id.domain) }, - connectionStatus = connectionState, - availabilityStatus = UserAvailabilityStatusEntity.NONE, - userType = userTypeEntity, - botService = userProfile.service?.let { BotIdEntity(it.id, it.provider) }, - deleted = userProfile.deleted ?: false, - expiresAt = userProfile.expiresAt?.toInstant(), - defederated = false, - isProteusVerified = false, - supportedProtocols = userProfile.supportedProtocols?.toDao() ?: setOf(SupportedProtocolEntity.PROTEUS), - activeOneOnOneConversationId = null - ) + override fun fromUserProfileDtoToOtherUser(userProfile: UserProfileDTO, selfUser: SelfUser): OtherUser = + fromUserEntityToOtherUser( + fromUserProfileDtoToUserEntity( + userProfile = userProfile, + connectionState = ConnectionEntity.State.NOT_CONNECTED, + userTypeEntity = userEntityTypeMapper.fromTeamAndDomain( + otherUserDomain = userProfile.id.domain, + selfUserTeamId = selfUser.teamId?.value, + otherUserTeamId = userProfile.teamId, + selfUserDomain = selfUser.id.domain, + isService = userProfile.service != null, + ) + ) + ) override fun fromUserUpdateEventToPartialUserEntity(event: Event.User.Update): PartialUserEntity = PartialUserEntity( @@ -348,31 +376,6 @@ internal class UserMapperImpl( activeOneOnOneConversationId = null ) } - - override fun fromFailedUserToDetailsEntity(userId: NetworkQualifiedId): UserDetailsEntity { - return UserDetailsEntity( - id = userId.toDao(), - name = null, - handle = null, - email = null, - phone = null, - accentId = 1, - team = null, - connectionStatus = ConnectionEntity.State.ACCEPTED, - previewAssetId = null, - completeAssetId = null, - availabilityStatus = UserAvailabilityStatusEntity.NONE, - userType = UserTypeEntity.STANDARD, - botService = null, - deleted = false, - hasIncompleteMetadata = true, - expiresAt = null, - defederated = false, - isProteusVerified = false, - supportedProtocols = null, - activeOneOnOneConversationId = null - ) - } } fun SupportedProtocol.toApi() = when (this) { diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt index 7257b68e72d..3d366244990 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt @@ -32,11 +32,9 @@ import com.wire.kalium.logic.data.id.toApi import com.wire.kalium.logic.data.id.toDao import com.wire.kalium.logic.data.id.toModel import com.wire.kalium.logic.data.message.UserSummary -import com.wire.kalium.logic.data.publicuser.PublicUserMapper import com.wire.kalium.logic.data.session.SessionRepository import com.wire.kalium.logic.data.team.Team import com.wire.kalium.logic.data.team.TeamMapper -import com.wire.kalium.logic.data.user.type.DomainUserTypeMapper import com.wire.kalium.logic.data.user.type.UserEntityTypeMapper import com.wire.kalium.logic.data.user.type.isFederated import com.wire.kalium.logic.di.MapperProvider @@ -90,7 +88,7 @@ internal interface UserRepository { suspend fun fetchUsersIfUnknownByIds(ids: Set): Either suspend fun observeSelfUser(): Flow suspend fun observeSelfUserWithTeam(): Flow> - suspend fun updateSelfUser(newName: String? = null, newAccent: Int? = null, newAssetId: String? = null): Either + suspend fun updateSelfUser(newName: String? = null, newAccent: Int? = null, newAssetId: String? = null): Either suspend fun getSelfUser(): SelfUser? suspend fun observeAllKnownUsers(): Flow>> suspend fun getKnownUser(userId: UserId): Flow @@ -152,11 +150,9 @@ internal class UserDataSource internal constructor( private val idMapper: IdMapper = MapperProvider.idMapper(), private val userMapper: UserMapper = MapperProvider.userMapper(), private val teamMapper: TeamMapper = MapperProvider.teamMapper(), - private val publicUserMapper: PublicUserMapper = MapperProvider.publicUserMapper(), private val availabilityStatusMapper: AvailabilityStatusMapper = MapperProvider.availabilityStatusMapper(), private val userTypeEntityMapper: UserEntityTypeMapper = MapperProvider.userTypeEntityMapper(), private val memberMapper: MemberMapper = MapperProvider.memberMapper(), - private val userTypeMapper: DomainUserTypeMapper = MapperProvider.userTypeMapper() ) : UserRepository { /** @@ -189,14 +185,14 @@ internal class UserDataSource internal constructor( override suspend fun getKnownUser(userId: UserId): Flow = userDAO.observeUserDetailsByQualifiedID(qualifiedID = userId.toDao()) .map { userEntity -> - userEntity?.let { publicUserMapper.fromUserDetailsEntityToOtherUser(userEntity) } + userEntity?.let { userMapper.fromUserDetailsEntityToOtherUser(userEntity) } }.onEach { otherUser -> processFederatedUserRefresh(userId, otherUser) } override suspend fun getUsersWithOneOnOneConversation(): List { return userDAO.getUsersWithOneOnOneConversation() - .map(publicUserMapper::fromUserEntityToOtherUser) + .map(userMapper::fromUserEntityToOtherUser) } /** @@ -338,16 +334,15 @@ internal class UserDataSource internal constructor( replaceWith = ReplaceWith("eg: updateSelfDisplayName(displayName: String)") ) // FIXME(refactor): create a dedicated function to update avatar, as this is the only usage of this function. - override suspend fun updateSelfUser(newName: String?, newAccent: Int?, newAssetId: String?): Either { - val user = getSelfUser() ?: return Either.Left(CoreFailure.Unknown(NullPointerException())) - val updateRequest = userMapper.fromModelToUpdateApiModel(user, newName, newAccent, newAssetId) + override suspend fun updateSelfUser(newName: String?, newAccent: Int?, newAssetId: String?): Either { + val updateRequest = userMapper.fromModelToUpdateApiModel(newName, newAccent, newAssetId) return wrapApiRequest { selfApi.updateSelf(updateRequest) } - .map { userMapper.fromUpdateRequestToDaoModel(user, updateRequest) } - .flatMap { userEntity -> + .map { userMapper.fromUpdateRequestToPartialUserEntity(updateRequest, selfUserId) } + .flatMap { partialUserEntity -> wrapStorageRequest { - userDAO.upsertUser(userEntity) - }.map { userMapper.fromUserEntityToSelfUser(userEntity) } - } + userDAO.updateUser(selfUserId.toDao(), partialUserEntity) + } + }.map { } } // TODO: replace the flow with selfUser and cache it @@ -361,14 +356,14 @@ internal class UserDataSource internal constructor( .mapRight { users -> users .filter { it.id != selfUserId && !it.deleted && !it.hasIncompleteMetadata } - .map { userEntity -> publicUserMapper.fromUserDetailsEntityToOtherUser(userEntity) } + .map { userEntity -> userMapper.fromUserDetailsEntityToOtherUser(userEntity) } } } override suspend fun getKnownUserMinimized(userId: UserId) = userDAO.getUserMinimizedByQualifiedID( qualifiedID = userId.toDao() )?.let { - publicUserMapper.fromUserEntityToOtherUserMinimized(it) + userMapper.fromUserEntityToOtherUserMinimized(it) } override suspend fun observeUser(userId: UserId): Flow = @@ -378,26 +373,17 @@ internal class UserDataSource internal constructor( if (userId == selfUserId) { userEntity?.let { userMapper.fromUserDetailsEntityToSelfUser(userEntity) } } else { - userEntity?.let { publicUserMapper.fromUserDetailsEntityToOtherUser(userEntity) } + userEntity?.let { userMapper.fromUserDetailsEntityToOtherUser(userEntity) } } } override suspend fun userById(userId: UserId): Either = wrapApiRequest { userDetailsApi.getUserInfo(userId.toApi()) }.flatMap { userProfileDTO -> - getSelfUser()?.teamId.let { selfTeamId -> + getSelfUser()?.let { selfUser -> Either.Right( - publicUserMapper.fromUserProfileDtoToOtherUser( - userDetailResponse = userProfileDTO, - userType = userTypeMapper.fromTeamAndDomain( - otherUserDomain = userProfileDTO.id.domain, - selfUserTeamId = selfTeamId?.value, - otherUserTeamId = userProfileDTO.teamId, - selfUserDomain = selfUserId.domain, - isService = userProfileDTO.service != null - ) - ) + userMapper.fromUserProfileDtoToOtherUser(userProfileDTO, selfUser) ) - } + } ?: Either.Left(StorageFailure.DataNotFound) } override suspend fun updateOtherUserAvailabilityStatus(userId: UserId, status: UserAvailabilityStatus) { @@ -424,7 +410,7 @@ internal class UserDataSource internal constructor( .mapRight { users -> users .filter { !it.deleted && !it.hasIncompleteMetadata } - .map { publicUserMapper.fromUserDetailsEntityToOtherUser(it) } + .map { userMapper.fromUserDetailsEntityToOtherUser(it) } } } @@ -474,7 +460,7 @@ internal class UserDataSource internal constructor( userDAO.insertOrIgnoreUsers( users.map { user -> when (user) { - is OtherUser -> publicUserMapper.fromOtherToUserEntity(user) + is OtherUser -> userMapper.fromOtherToUserEntity(user) is SelfUser -> userMapper.fromSelfUserToUserEntity(user) } } @@ -496,7 +482,7 @@ internal class UserDataSource internal constructor( override suspend fun getUsersSummaryByIds(userIds: List): Either> = wrapStorageRequest { userDAO.getUsersDetailsByQualifiedIDList(userIds.map { it.toDao() }).map { - publicUserMapper.fromUserDetailsEntityToUserSummary(it) + userMapper.fromEntityToUserSummary(it.toSimpleEntity()) } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/di/MapperProvider.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/di/MapperProvider.kt index 789995b4b3d..6bb0ccd60f0 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/di/MapperProvider.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/di/MapperProvider.kt @@ -78,8 +78,6 @@ import com.wire.kalium.logic.data.notification.LocalNotificationMessageMapperImp import com.wire.kalium.logic.data.prekey.PreKeyListMapper import com.wire.kalium.logic.data.prekey.PreKeyMapper import com.wire.kalium.logic.data.prekey.PreKeyMapperImpl -import com.wire.kalium.logic.data.publicuser.PublicUserMapper -import com.wire.kalium.logic.data.publicuser.PublicUserMapperImpl import com.wire.kalium.logic.data.service.ServiceMapper import com.wire.kalium.logic.data.session.SessionMapper import com.wire.kalium.logic.data.session.SessionMapperImpl @@ -105,9 +103,7 @@ internal object MapperProvider { fun sessionMapper(): SessionMapper = SessionMapperImpl(idMapper()) fun availabilityStatusMapper(): AvailabilityStatusMapper = AvailabilityStatusMapperImpl() fun connectionStateMapper(): ConnectionStateMapper = ConnectionStateMapperImpl() - fun userMapper(): UserMapper = UserMapperImpl( - idMapper(), availabilityStatusMapper(), connectionStateMapper() - ) + fun userMapper(): UserMapper = UserMapperImpl() fun userTypeMapper(): DomainUserTypeMapper = DomainUserTypeMapperImpl() fun reactionsMapper(): ReactionsMapper = ReactionsMapperImpl(domainUserTypeMapper = userTypeMapper()) @@ -131,7 +127,6 @@ internal object MapperProvider { ) fun conversationRoleMapper(): ConversationRoleMapper = ConversationRoleMapperImpl() - fun publicUserMapper(): PublicUserMapper = PublicUserMapperImpl() fun sendMessageFailureMapper(): SendMessageFailureMapper = SendMessageFailureMapperImpl() fun assetMapper(): AssetMapper = AssetMapperImpl() fun encryptionAlgorithmMapper(): EncryptionAlgorithmMapper = EncryptionAlgorithmMapper() diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/UploadUserAvatarUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/UploadUserAvatarUseCase.kt index 9d1fc0d98b3..4a329854dd6 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/UploadUserAvatarUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/UploadUserAvatarUseCase.kt @@ -24,6 +24,7 @@ import com.wire.kalium.logic.data.user.UserAssetId import com.wire.kalium.logic.data.user.UserRepository import com.wire.kalium.logic.functional.flatMap import com.wire.kalium.logic.functional.fold +import com.wire.kalium.logic.functional.map import okio.Path interface UploadUserAvatarUseCase { @@ -44,11 +45,11 @@ internal class UploadUserAvatarUseCaseImpl( override suspend operator fun invoke(imageDataPath: Path, imageDataSize: Long): UploadAvatarResult { return assetDataSource.uploadAndPersistPublicAsset("image/jpg", imageDataPath, imageDataSize).flatMap { asset -> - userDataSource.updateSelfUser(newAssetId = asset.key) + userDataSource.updateSelfUser(newAssetId = asset.key).map { asset } }.fold({ UploadAvatarResult.Failure(it) - }) { updatedUser -> - UploadAvatarResult.Success(updatedUser.completePicture!!) + }) { updatedAsset -> + UploadAvatarResult.Success(UserAssetId(updatedAsset.key, updatedAsset.domain)) } // TODO(assets): remove old assets, non blocking this response, as will imply deleting locally and remotely } } diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/connection/ConnectionMapperTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/connection/ConnectionMapperTest.kt index afc54ee5b3e..09fb476596e 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/connection/ConnectionMapperTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/connection/ConnectionMapperTest.kt @@ -90,9 +90,7 @@ class ConnectionMapperTest { val statusMapper = MapperProvider.connectionStatusMapper() - val publicUserMapper = MapperProvider.publicUserMapper() - - val mapper = ConnectionMapperImpl(idMapper, statusMapper, publicUserMapper) + val mapper = ConnectionMapperImpl(idMapper, statusMapper) val stubConnectionResponse = ConnectionDTO( "someId", diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/publicuser/SearchUserRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/publicuser/SearchUserRepositoryTest.kt index 693c491f5dc..34cecb4a572 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/publicuser/SearchUserRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/publicuser/SearchUserRepositoryTest.kt @@ -70,9 +70,6 @@ class SearchUserRepositoryTest { @Mock private val userSearchApiWrapper: UserSearchApiWrapper = mock(classOf()) - @Mock - private val publicUserMapper: PublicUserMapper = mock(classOf()) - @Mock private val userMapper: UserMapper = mock(classOf()) @@ -94,9 +91,7 @@ class SearchUserRepositoryTest { metadataDAO, userDetailsApi, userSearchApiWrapper, - publicUserMapper, - userMapper, - domainUserTypeMapper + userMapper ) given(domainUserTypeMapper).invocation { federated }.then { UserType.FEDERATED } @@ -157,8 +152,8 @@ class SearchUserRepositoryTest { .with(any()) .wasNotInvoked() - verify(publicUserMapper) - .function(publicUserMapper::fromUserProfileDtoToOtherUser) + verify(userMapper) + .function(userMapper::fromUserProfileDtoToOtherUser) .with(any(), any()) .wasNotInvoked() } @@ -200,8 +195,8 @@ class SearchUserRepositoryTest { searchUserRepository.searchUserDirectory(TEST_QUERY, TEST_DOMAIN) // then - verify(publicUserMapper) - .function(publicUserMapper::fromUserProfileDtoToOtherUser) + verify(userMapper) + .function(userMapper::fromUserProfileDtoToOtherUser) .with(any(), any()) .wasNotInvoked() } @@ -247,8 +242,8 @@ class SearchUserRepositoryTest { .whenInvokedWith(any()) .then { NetworkResponse.Success(USER_RESPONSE, mapOf(), 200) } - given(publicUserMapper) - .function(publicUserMapper::fromUserProfileDtoToOtherUser) + given(userMapper) + .function(userMapper::fromUserProfileDtoToOtherUser) .whenInvokedWith(any(), any()) .then { _, _ -> TestUser.OTHER } @@ -298,8 +293,8 @@ class SearchUserRepositoryTest { .whenInvokedWith(any()) .then { NetworkResponse.Success(USER_RESPONSE, mapOf(), 200) } - given(publicUserMapper) - .function(publicUserMapper::fromUserProfileDtoToOtherUser) + given(userMapper) + .function(userMapper::fromUserProfileDtoToOtherUser) .whenInvokedWith(any(), any()) .then { _, _ -> TestUser.OTHER } diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/UploadUserAvatarUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/UploadUserAvatarUseCaseTest.kt index ddbb9b65fe6..18b033d684a 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/UploadUserAvatarUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/UploadUserAvatarUseCaseTest.kt @@ -51,7 +51,7 @@ class UploadUserAvatarUseCaseTest { @Test fun givenValidParams_whenUploadingUserAvatar_thenShouldReturnsASuccessResult() = runTest { - val expected = UploadedAssetId("some_key") + val expected = UploadedAssetId("some_key", "some_domain") val avatarImage = "An Avatar Image (:".encodeToByteArray() val avatarPath = "some-image-asset".toPath() val (arrangement, uploadUserAvatar) = Arrangement() @@ -62,7 +62,7 @@ class UploadUserAvatarUseCaseTest { val actual = uploadUserAvatar(avatarPath, avatarImage.size.toLong()) assertEquals(UploadAvatarResult.Success::class, actual::class) - assertEquals("value2", (actual as UploadAvatarResult.Success).userAssetId.value) + assertEquals(expected.key, (actual as UploadAvatarResult.Success).userAssetId.value) with(arrangement) { verify(assetRepository) @@ -152,7 +152,7 @@ class UploadUserAvatarUseCaseTest { given(userRepository) .suspendFunction(userRepository::updateSelfUser) .whenInvokedWith(eq(null), eq(null), eq(expectedResponse.key)) - .thenReturn(Either.Right(dummySelfUser)) + .thenReturn(Either.Right(Unit)) return this } diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/UserDAO.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/UserDAO.kt index 69007ef7f20..28a6d22756f 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/UserDAO.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/UserDAO.kt @@ -142,13 +142,13 @@ data class BotIdEntity( ) data class PartialUserEntity( - val name: String?, - val handle: String?, - val email: String?, - val accentId: Int?, - val previewAssetId: UserAssetIdEntity?, - val completeAssetId: UserAssetIdEntity?, - val supportedProtocols: Set? + val name: String? = null, + val handle: String? = null, + val email: String? = null, + val accentId: Int? = null, + val previewAssetId: UserAssetIdEntity? = null, + val completeAssetId: UserAssetIdEntity? = null, + val supportedProtocols: Set? = null ) enum class UserTypeEntity { diff --git a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/UserDAOTest.kt b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/UserDAOTest.kt index bafa6f5898d..e8c4ac6efa7 100644 --- a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/UserDAOTest.kt +++ b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/UserDAOTest.kt @@ -738,15 +738,7 @@ class UserDAOTest : BaseDatabaseTest() { fun givenAnExistingUser_whenPerformingPartialUpdate_thenChangedFieldIsUpdatedOthersAreUnchanged() = runTest(dispatcher) { // given val expectedName = "new name" - val update = PartialUserEntity( - name = expectedName, - handle = null, - email = null, - accentId = null, - previewAssetId = null, - completeAssetId = null, - supportedProtocols = null - ) + val update = PartialUserEntity(name = expectedName) db.userDAO.upsertUser(user1) // when