Skip to content

Commit

Permalink
chore: default selfUser when creator field is missing (#2022)
Browse files Browse the repository at this point in the history
  • Loading branch information
typfel authored Aug 31, 2023
1 parent 38b1e5c commit fea30f3
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal class ConversationGroupRepositoryImpl(
private val newGroupConversationSystemMessagesCreator: Lazy<NewGroupConversationSystemMessagesCreator>,
private val selfUserId: UserId,
private val teamIdProvider: SelfTeamIdProvider,
private val conversationMapper: ConversationMapper = MapperProvider.conversationMapper(),
private val conversationMapper: ConversationMapper = MapperProvider.conversationMapper(selfUserId),
private val eventMapper: EventMapper = MapperProvider.eventMapper(),
private val protocolInfoMapper: ProtocolInfoMapper = MapperProvider.protocolInfoMapper(),
) : ConversationGroupRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ interface ConversationMapper {

@Suppress("TooManyFunctions", "LongParameterList")
internal class ConversationMapperImpl(
private val selfUserId: UserId,
private val idMapper: IdMapper,
private val conversationStatusMapper: ConversationStatusMapper,
private val protocolInfoMapper: ProtocolInfoMapper,
Expand All @@ -106,7 +107,7 @@ internal class ConversationMapperImpl(
mutedStatus = conversationStatusMapper.fromMutedStatusApiToDaoModel(apiModel.members.self.otrMutedStatus),
mutedTime = apiModel.members.self.otrMutedRef?.let { Instant.parse(it) }?.toEpochMilliseconds() ?: 0,
removedBy = null,
creatorId = apiModel.creator,
creatorId = apiModel.creator ?: selfUserId.value, // NOTE mls 1-1 does not have the creator field set.
lastReadDate = Instant.UNIX_FIRST_DATE,
lastNotificationDate = null,
lastModifiedDate = apiModel.lastEventTime.toInstant(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ internal class ConversationDataSource internal constructor(
private val clientApi: ClientApi,
private val conversationMetaDataDAO: ConversationMetaDataDAO,
private val idMapper: IdMapper = MapperProvider.idMapper(),
private val conversationMapper: ConversationMapper = MapperProvider.conversationMapper(),
private val conversationMapper: ConversationMapper = MapperProvider.conversationMapper(selfUserId),
private val memberMapper: MemberMapper = MapperProvider.memberMapper(),
private val conversationStatusMapper: ConversationStatusMapper = MapperProvider.conversationStatusMapper(),
private val conversationRoleMapper: ConversationRoleMapper = MapperProvider.conversationRoleMapper(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private fun CoreFailure.getStrategy(

@Suppress("TooManyFunctions", "LongParameterList")
internal class MLSConversationDataSource(
private val selfUserId: UserId,
private val keyPackageRepository: KeyPackageRepository,
private val mlsClientProvider: MLSClientProvider,
private val mlsMessageApi: MLSMessageApi,
Expand All @@ -143,7 +144,7 @@ internal class MLSConversationDataSource(
private val epochsFlow: MutableSharedFlow<GroupID>,
private val proposalTimersFlow: MutableSharedFlow<ProposalTimer>,
private val idMapper: IdMapper = MapperProvider.idMapper(),
private val conversationMapper: ConversationMapper = MapperProvider.conversationMapper(),
private val conversationMapper: ConversationMapper = MapperProvider.conversationMapper(selfUserId),
private val mlsPublicKeysMapper: MLSPublicKeysMapper = MapperProvider.mlsPublicKeyMapper(),
private val mlsCommitBundleMapper: MLSCommitBundleMapper = MapperProvider.mlsCommitBundleMapper()
) : MLSConversationRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal class NewGroupConversationSystemMessagesCreatorImpl(

persistReadReceiptSystemMessage(
conversationId = conversation.id.toModel(),
creatorId = qualifiedIdMapper.fromStringToQualifiedID(conversation.creator),
creatorId = conversation.creator?.let { qualifiedIdMapper.fromStringToQualifiedID(it) } ?: selfUserId,
receiptMode = conversation.receiptMode == ReceiptMode.ENABLED
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ internal object MapperProvider {
)

fun memberMapper(): MemberMapper = MemberMapperImpl(idMapper(), conversationRoleMapper())
fun conversationMapper(): ConversationMapper =
fun conversationMapper(selfUserId: UserId): ConversationMapper =
ConversationMapperImpl(
selfUserId,
idMapper(),
ConversationStatusMapperImpl(idMapper()),
ProtocolInfoMapperImpl(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ class UserSessionScope internal constructor(

private val mlsConversationRepository: MLSConversationRepository
get() = MLSConversationDataSource(
userId,
keyPackageRepository,
mlsClientProvider,
authenticatedNetworkContainer.mlsMessageApi,
Expand Down Expand Up @@ -1373,7 +1374,7 @@ class UserSessionScope internal constructor(
this
)

val migration get() = MigrationScope(userStorage.database)
val migration get() = MigrationScope(userId, userStorage.database)
val debug: DebugScope
get() = DebugScope(
messageRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ interface RestoreWebBackupUseCase {
@Suppress("TooManyFunctions", "LongParameterList", "NestedBlockDepth")
internal class RestoreWebBackupUseCaseImpl(
private val kaliumFileSystem: KaliumFileSystem,
private val userId: UserId,
private val selfUserId: UserId,
private val persistMigratedMessages: PersistMigratedMessagesUseCase,
private val restartSlowSyncProcessForRecovery: RestartSlowSyncProcessForRecoveryUseCase,
private val migrationDAO: MigrationDAO,
private val dispatchers: KaliumDispatcher = KaliumDispatcherImpl,
private val conversationMapper: ConversationMapper = MapperProvider.conversationMapper()
private val conversationMapper: ConversationMapper = MapperProvider.conversationMapper(selfUserId)
) : RestoreWebBackupUseCase {

override suspend operator fun invoke(backupRootPath: Path, metadata: BackupMetadata): RestoreBackupResult =
Expand Down Expand Up @@ -100,7 +100,7 @@ internal class RestoreWebBackupUseCaseImpl(
while (iterator.hasNext()) {
try {
val webConversation = iterator.next()
val migratedConversation = webConversation.toConversation(userId)
val migratedConversation = webConversation.toConversation(selfUserId)
if (migratedConversation != null) {
migratedConversations.add(migratedConversation)
}
Expand Down Expand Up @@ -128,7 +128,7 @@ internal class RestoreWebBackupUseCaseImpl(
while (iterator.hasNext()) {
try {
val webContent = iterator.next()
val migratedMessage = webContent.toMigratedMessage(userId.domain)
val migratedMessage = webContent.toMigratedMessage(selfUserId.domain)
if (migratedMessage != null) {
migratedMessagesBatch.add(migratedMessage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.wire.kalium.logger.KaliumLogger.Companion.ApplicationFlow.CONVERSATIO
import com.wire.kalium.logic.StorageFailure
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.conversation.ConversationMapper
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.di.MapperProvider
import com.wire.kalium.logic.kaliumLogger
import com.wire.kalium.logic.wrapStorageRequest
Expand All @@ -46,8 +47,9 @@ fun interface PersistMigratedConversationUseCase {
}

internal class PersistMigratedConversationUseCaseImpl(
private val selfUserId: UserId,
private val migrationDAO: MigrationDAO,
private val conversationMapper: ConversationMapper = MapperProvider.conversationMapper()
private val conversationMapper: ConversationMapper = MapperProvider.conversationMapper(selfUserId)
) : PersistMigratedConversationUseCase {

val logger by lazy { kaliumLogger.withFeatureId(CONVERSATIONS) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@

package com.wire.kalium.logic.feature.migration

import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.conversation.PersistMigratedConversationUseCase
import com.wire.kalium.logic.feature.conversation.PersistMigratedConversationUseCaseImpl
import com.wire.kalium.persistence.db.UserDatabaseBuilder

class MigrationScope(
private val selfUserId: UserId,
private val userDatabase: UserDatabaseBuilder
) {

val persistMigratedConversation: PersistMigratedConversationUseCase
get() = PersistMigratedConversationUseCaseImpl(userDatabase.migrationDAO)
get() = PersistMigratedConversationUseCaseImpl(selfUserId, userDatabase.migrationDAO)

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.wire.kalium.logic.data.id.IdMapper
import com.wire.kalium.logic.data.id.TeamId
import com.wire.kalium.logic.data.user.AvailabilityStatusMapper
import com.wire.kalium.logic.data.user.type.DomainUserTypeMapper
import com.wire.kalium.logic.framework.TestUser
import com.wire.kalium.network.api.base.authenticated.conversation.ConvProtocol
import com.wire.kalium.network.api.base.authenticated.conversation.ConversationMemberDTO
import com.wire.kalium.network.api.base.authenticated.conversation.ConversationMembersResponse
Expand Down Expand Up @@ -74,6 +75,7 @@ class ConversationMapperTest {
@BeforeTest
fun setup() {
conversationMapper = ConversationMapperImpl(
TestUser.SELF.id,
idMapper,
conversationStatusMapper,
protocolInfoMapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ class MLSConversationRepositoryTest {
}

fun arrange() = this to MLSConversationDataSource(
TestUser.SELF.id,
keyPackageRepository,
mlsClientProvider,
mlsMessageApi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class RestoreWebBackupUseCaseTest {

fun arrange() = this to RestoreWebBackupUseCaseImpl(
kaliumFileSystem = fakeFileSystem,
userId = selfUserId,
selfUserId = selfUserId,
migrationDAO = migrationDAO,
persistMigratedMessages = persistMigratedMessagesUseCase,
restartSlowSyncProcessForRecovery = restartSlowSyncProcessForRecoveryUseCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import kotlinx.serialization.encoding.Encoder
@Serializable
data class ConversationResponse(
@SerialName("creator")
val creator: String,
val creator: String?,

@SerialName("members")
val members: ConversationMembersResponse,
Expand Down

0 comments on commit fea30f3

Please sign in to comment.