Skip to content

Commit

Permalink
Merge branch 'develop' into feat/database-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara committed Jan 13, 2025
2 parents 27f0900 + 4362a23 commit 882ee4e
Show file tree
Hide file tree
Showing 39 changed files with 970 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,17 @@ sealed class ConversationDetails(open val conversation: Conversation) {
override val conversation: Conversation,
val otherUser: OtherUser,
val userType: UserType,
val isFavorite: Boolean = false
val isFavorite: Boolean = false,
val folder: ConversationFolder? = null
) : ConversationDetails(conversation)

data class Group(
override val conversation: Conversation,
val hasOngoingCall: Boolean = false,
val isSelfUserMember: Boolean,
val selfRole: Conversation.Member.Role?,
val isFavorite: Boolean = false
val isFavorite: Boolean = false,
val folder: ConversationFolder? = null
// val isTeamAdmin: Boolean, TODO kubaz
) : ConversationDetails(conversation)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.wire.kalium.logic.data.id.QualifiedIdMapper
import com.wire.kalium.logic.data.message.Message
import com.wire.kalium.logic.data.message.MessageContent
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.feature.call.usecase.ConversationClientsInCallUpdater
import com.wire.kalium.logic.feature.call.usecase.CreateAndPersistRecentlyEndedCallMetadataUseCase
import com.wire.kalium.logic.feature.call.usecase.GetCallConversationTypeProvider
Expand All @@ -59,11 +58,10 @@ class CallManagerTest {
@Mock
private val calling = mock(Calling::class)

@Mock
private val callRepository = mock(CallRepository::class)
private val selfUserId = UserId(value = "selfUserId", domain = "selfDomain")

@Mock
private val userRepository = mock(UserRepository::class)
private val callRepository = mock(CallRepository::class)

@Mock
private val messageSender = mock(MessageSender::class)
Expand Down Expand Up @@ -120,7 +118,6 @@ class CallManagerTest {
callManagerImpl = CallManagerImpl(
calling = calling,
callRepository = callRepository,
userRepository = userRepository,
currentClientIdProvider = currentClientIdProvider,
selfConversationIdProvider = selfConversationIdProvider,
conversationRepository = conversationRepository,
Expand All @@ -137,7 +134,8 @@ class CallManagerTest {
kaliumConfigs = kaliumConfigs,
mediaManagerService = mediaManagerService,
flowManagerService = flowManagerService,
createAndPersistRecentlyEndedCallMetadata = createAndPersistRecentlyEndedCallMetadata
createAndPersistRecentlyEndedCallMetadata = createAndPersistRecentlyEndedCallMetadata,
selfUserId = selfUserId
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.wire.kalium.logic.data.id.FederatedIdMapper
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.id.QualifiedIdMapper
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.feature.call.usecase.ConversationClientsInCallUpdater
import com.wire.kalium.logic.feature.call.usecase.GetCallConversationTypeProvider
import com.wire.kalium.logic.feature.call.usecase.CreateAndPersistRecentlyEndedCallMetadataUseCase
Expand All @@ -44,7 +43,6 @@ actual class GlobalCallManager {
internal actual fun getCallManagerForClient(
userId: QualifiedID,
callRepository: CallRepository,
userRepository: UserRepository,
currentClientIdProvider: CurrentClientIdProvider,
selfConversationIdProvider: SelfConversationIdProvider,
conversationRepository: ConversationRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import com.wire.kalium.logic.data.id.QualifiedIdMapper
import com.wire.kalium.logic.data.message.Message
import com.wire.kalium.logic.data.message.MessageContent
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.feature.call.scenario.CallingMessageSender
import com.wire.kalium.logic.feature.call.scenario.OnActiveSpeakers
import com.wire.kalium.logic.feature.call.scenario.OnAnsweredCall
Expand Down Expand Up @@ -104,7 +103,6 @@ import java.util.Collections
class CallManagerImpl internal constructor(
private val calling: Calling,
private val callRepository: CallRepository,
private val userRepository: UserRepository,
private val currentClientIdProvider: CurrentClientIdProvider,
selfConversationIdProvider: SelfConversationIdProvider,
private val conversationRepository: ConversationRepository,
Expand All @@ -121,6 +119,7 @@ class CallManagerImpl internal constructor(
private val mediaManagerService: MediaManagerService,
private val flowManagerService: FlowManagerService,
private val createAndPersistRecentlyEndedCallMetadata: CreateAndPersistRecentlyEndedCallMetadataUseCase,
private val selfUserId: UserId,
private val json: Json = Json { ignoreUnknownKeys = true },
private val shouldRemoteMuteChecker: ShouldRemoteMuteChecker = ShouldRemoteMuteCheckerImpl(),
private val serverTimeHandler: ServerTimeHandler = ServerTimeHandlerImpl(),
Expand Down Expand Up @@ -153,11 +152,6 @@ class CallManagerImpl internal constructor(
it
})
}
private val userId: Deferred<UserId> = scope.async(start = CoroutineStart.LAZY) {
userRepository.observeSelfUser().first().id.also {
callingLogger.d("$TAG - userId ${it.toLogString()}")
}
}

@Suppress("UNUSED_ANONYMOUS_PARAMETER")
private val metricsHandler = MetricsHandler { conversationId: String, metricsJson: String, arg: Pointer? ->
Expand Down Expand Up @@ -186,7 +180,7 @@ class CallManagerImpl internal constructor(
}
joinAll(flowManagerStartJob, mediaManagerStartJob)
callingLogger.i("$TAG: Creating Handle")
val selfUserId = federatedIdMapper.parseToFederatedId(userId.await())
val selfUserId = federatedIdMapper.parseToFederatedId(selfUserId)
val selfClientId = clientId.await().value

val waitInitializationJob = Job()
Expand Down Expand Up @@ -254,7 +248,7 @@ class CallManagerImpl internal constructor(
val conversationMembers = conversationRepository.observeConversationMembers(message.conversationId).first()
val shouldRemoteMute = shouldRemoteMuteChecker.check(
senderUserId = message.senderUserId,
selfUserId = userId.await(),
selfUserId = selfUserId,
selfClientId = clientId.await().value,
targets = callingValue.targets,
conversationMembers = conversationMembers
Expand Down Expand Up @@ -306,7 +300,7 @@ class CallManagerImpl internal constructor(
isMuted = false,
isCameraOn = isCameraOn,
isCbrEnabled = isAudioCbr,
callerId = userId.await()
callerId = selfUserId
)

withCalling {
Expand Down Expand Up @@ -401,7 +395,7 @@ class CallManagerImpl internal constructor(
}
callingLogger.d("$TAG -> set test video to $logString")

val selfUserId = federatedIdMapper.parseToFederatedId(userId.await())
val selfUserId = federatedIdMapper.parseToFederatedId(selfUserId)
val selfClientId = clientId.await().value
val handle = deferredHandle.await()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.wire.kalium.logic.data.id.FederatedIdMapper
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.id.QualifiedIdMapper
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.feature.call.usecase.ConversationClientsInCallUpdater
import com.wire.kalium.logic.feature.call.usecase.GetCallConversationTypeProvider
import com.wire.kalium.logic.feature.call.usecase.CreateAndPersistRecentlyEndedCallMetadataUseCase
Expand Down Expand Up @@ -82,7 +81,6 @@ actual class GlobalCallManager(
internal actual fun getCallManagerForClient(
userId: QualifiedID,
callRepository: CallRepository,
userRepository: UserRepository,
currentClientIdProvider: CurrentClientIdProvider,
selfConversationIdProvider: SelfConversationIdProvider,
conversationRepository: ConversationRepository,
Expand All @@ -103,7 +101,7 @@ actual class GlobalCallManager(
CallManagerImpl(
calling = calling,
callRepository = callRepository,
userRepository = userRepository,
selfUserId = userId,
currentClientIdProvider = currentClientIdProvider,
selfConversationIdProvider = selfConversationIdProvider,
callMapper = callMapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,26 @@

package com.wire.kalium.logic.data.call

import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.data.id.CurrentClientIdProvider
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.functional.fold

internal interface CallingParticipantsOrder {
suspend fun reorderItems(participants: List<Participant>): List<Participant>
}

internal class CallingParticipantsOrderImpl(
private val userRepository: UserRepository,
private val currentClientIdProvider: CurrentClientIdProvider,
private val participantsFilter: ParticipantsFilter,
private val participantsOrderByName: ParticipantsOrderByName,
private val selfUserId: UserId
) : CallingParticipantsOrder {

override suspend fun reorderItems(participants: List<Participant>): List<Participant> {
return if (participants.isNotEmpty()) {
currentClientIdProvider().fold({
participants
}, { selfClientId ->
val selfUserId = userRepository.getSelfUser()?.id!!

val selfParticipant = participantsFilter.selfParticipant(participants, selfUserId, selfClientId.value)
val otherParticipants = participantsFilter.otherParticipants(participants, selfClientId.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ internal class ConversationMapperImpl(
activeOneOnOneConversationId = userActiveOneOnOneConversationId?.toModel()
),
userType = domainUserTypeMapper.fromUserTypeEntity(userType),
isFavorite = isFavorite
isFavorite = isFavorite,
folder = folderId?.let { ConversationFolder(it, folderName ?: "", type = FolderType.USER) },
)
}

Expand All @@ -273,7 +274,8 @@ internal class ConversationMapperImpl(
hasOngoingCall = callStatus != null, // todo: we can do better!
isSelfUserMember = isMember,
selfRole = selfRole?.let { conversationRoleMapper.fromDAO(it) },
isFavorite = isFavorite
isFavorite = isFavorite,
folder = folderId?.let { ConversationFolder(it, folderName ?: "", type = FolderType.USER) },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal interface ConversationFolderRepository {
suspend fun addConversationToFolder(conversationId: QualifiedID, folderId: String): Either<CoreFailure, Unit>
suspend fun removeConversationFromFolder(conversationId: QualifiedID, folderId: String): Either<CoreFailure, Unit>
suspend fun syncConversationFoldersFromLocal(): Either<CoreFailure, Unit>
suspend fun observeUserFolders(): Flow<Either<CoreFailure, List<ConversationFolder>>>
suspend fun observeFolders(): Flow<Either<CoreFailure, List<ConversationFolder>>>
}

internal class ConversationFolderDataSource internal constructor(
Expand Down Expand Up @@ -155,8 +155,8 @@ internal class ConversationFolderDataSource internal constructor(
}
}

override suspend fun observeUserFolders(): Flow<Either<CoreFailure, List<ConversationFolder>>> {
return conversationFolderDAO.observeUserFolders()
override suspend fun observeFolders(): Flow<Either<CoreFailure, List<ConversationFolder>>> {
return conversationFolderDAO.observeFolders()
.wrapStorageRequest()
.mapRight { folderEntities -> folderEntities.map { it.toModel() } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ internal class UserDataSource internal constructor(
private suspend fun updateSelfUserProviderAccountInfo(userDTO: SelfUserDTO): Either<StorageFailure, Unit> =
sessionRepository.updateSsoIdAndScimInfo(userDTO.id.toModel(), idMapper.toSsoId(userDTO.ssoID), userDTO.managedByDTO)

// TODO: race condition, if we request the same user (can happen for self) multiple times, we will fetch it multiple times
override suspend fun getKnownUser(userId: UserId): Flow<OtherUser?> =
userDAO.observeUserDetailsByQualifiedID(qualifiedID = userId.toDao())
.map { userEntity ->
Expand Down Expand Up @@ -416,6 +417,7 @@ internal class UserDataSource internal constructor(
else fetchUsersByIds(missingIds.map { it.toModel() }.toSet()).map { }
}

// TODO: this can cause many issues since it will
@OptIn(ExperimentalCoroutinesApi::class)
override suspend fun observeSelfUser(): Flow<SelfUser> {
return metadataDAO.valueByKeyFlow(SELF_USER_ID_KEY).onEach {
Expand Down Expand Up @@ -469,8 +471,9 @@ internal class UserDataSource internal constructor(
}

// TODO: replace the flow with selfUser and cache it
override suspend fun getSelfUser(): SelfUser? =
observeSelfUser().firstOrNull()
override suspend fun getSelfUser(): SelfUser? {
return observeSelfUser().firstOrNull()
}

override suspend fun observeAllKnownUsers(): Flow<Either<StorageFailure, List<OtherUser>>> {
val selfUserId = selfUserId.toDao()
Expand Down Expand Up @@ -658,7 +661,6 @@ internal class UserDataSource internal constructor(
CreateUserTeam(dto.teamId, dto.teamName)
}
.onSuccess {
kaliumLogger.d("Migrated user to team")
fetchSelfUser()
}
.onFailure { failure ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,6 @@ class UserSessionScope internal constructor(
globalCallManager.getCallManagerForClient(
userId = userId,
callRepository = callRepository,
userRepository = userRepository,
currentClientIdProvider = clientIdProvider,
conversationRepository = conversationRepository,
userConfigRepository = userConfigRepository,
Expand Down Expand Up @@ -2062,7 +2061,6 @@ class UserSessionScope internal constructor(
callManager = callManager,
callRepository = callRepository,
conversationRepository = conversationRepository,
userRepository = userRepository,
flowManagerService = flowManagerService,
mediaManagerService = mediaManagerService,
syncManager = syncManager,
Expand All @@ -2073,6 +2071,8 @@ class UserSessionScope internal constructor(
conversationClientsInCallUpdater = conversationClientsInCallUpdater,
kaliumConfigs = kaliumConfigs,
inCallReactionsRepository = inCallReactionsRepository,
selfUserId = userId,
userRepository = userRepository
)

val connection: ConnectionScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.wire.kalium.logic.data.call.ParticipantsOrderByNameImpl
import com.wire.kalium.logic.data.conversation.ConversationRepository
import com.wire.kalium.logic.data.id.CurrentClientIdProvider
import com.wire.kalium.logic.data.id.QualifiedIdMapper
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.feature.call.usecase.AnswerCallUseCase
import com.wire.kalium.logic.feature.call.usecase.AnswerCallUseCaseImpl
Expand Down Expand Up @@ -107,6 +108,7 @@ class CallsScope internal constructor(
private val getCallConversationType: GetCallConversationTypeProvider,
private val kaliumConfigs: KaliumConfigs,
private val inCallReactionsRepository: InCallReactionsRepository,
private val selfUserId: UserId,
internal val dispatcher: KaliumDispatcher = KaliumDispatcherImpl
) {

Expand All @@ -122,7 +124,7 @@ class CallsScope internal constructor(
get() = GetIncomingCallsUseCaseImpl(
callRepository = callRepository,
conversationRepository = conversationRepository,
userRepository = userRepository
userRepository = userRepository,
)
val observeOutgoingCall: ObserveOutgoingCallUseCase
get() = ObserveOutgoingCallUseCaseImpl(
Expand Down Expand Up @@ -211,10 +213,10 @@ class CallsScope internal constructor(

private val callingParticipantsOrder: CallingParticipantsOrder
get() = CallingParticipantsOrderImpl(
userRepository = userRepository,
currentClientIdProvider = currentClientIdProvider,
participantsFilter = ParticipantsFilterImpl(qualifiedIdMapper),
participantsOrderByName = ParticipantsOrderByNameImpl()
participantsOrderByName = ParticipantsOrderByNameImpl(),
selfUserId = selfUserId
)

val isLastCallClosed: IsLastCallClosedUseCase get() = IsLastCallClosedUseCaseImpl(callRepository)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import com.wire.kalium.logic.data.id.FederatedIdMapper
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.id.QualifiedIdMapper
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.data.id.CurrentClientIdProvider
import com.wire.kalium.logic.feature.call.usecase.ConversationClientsInCallUpdater
import com.wire.kalium.logic.feature.call.usecase.GetCallConversationTypeProvider
Expand All @@ -45,7 +44,6 @@ expect class GlobalCallManager {
internal fun getCallManagerForClient(
userId: QualifiedID,
callRepository: CallRepository,
userRepository: UserRepository,
currentClientIdProvider: CurrentClientIdProvider,
selfConversationIdProvider: SelfConversationIdProvider,
conversationRepository: ConversationRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ internal class GetIncomingCallsUseCaseImpl internal constructor(

@OptIn(ExperimentalCoroutinesApi::class)
private suspend fun observeIncomingCallsIfUserStatusAllows(): Flow<List<Call>> =
// TODO: do not refresh self form remote in this case and just get status from local
userRepository.observeSelfUser()
.flatMapLatest {

// if user is AWAY we don't show any IncomingCalls
if (it.availabilityStatus == UserAvailabilityStatus.AWAY) {
logger.d("$TAG; Ignoring possible calls based user's status")
Expand Down
Loading

0 comments on commit 882ee4e

Please sign in to comment.