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 e0aea32afbf..2c9ceb576c3 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 @@ -38,7 +38,7 @@ import kotlinx.datetime.toInstant interface ConnectionMapper { fun fromApiToDao(state: ConnectionDTO): ConnectionEntity fun fromDaoToModel(connection: ConnectionEntity): Connection - fun fromDaoToConversationDetails(connection: ConnectionEntity): ConversationDetails + fun fromDaoToConversationDetails(connection: ConnectionEntity): ConversationDetails.Connection fun fromApiToModel(state: ConnectionDTO): Connection fun modelToDao(state: Connection): ConnectionEntity } @@ -72,7 +72,9 @@ internal class ConnectionMapperImpl( ) } - override fun fromDaoToConversationDetails(connection: ConnectionEntity): ConversationDetails = with(connection) { + override fun fromDaoToConversationDetails( + connection: ConnectionEntity + ): ConversationDetails.Connection = with(connection) { ConversationDetails.Connection( conversationId = qualifiedConversationId.toModel(), otherUser = otherUser?.let { userMapper.fromUserDetailsEntityToOtherUser(it) }, diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionRepository.kt index 86296755c16..8866395dbf1 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/connection/ConnectionRepository.kt @@ -70,7 +70,7 @@ interface ConnectionRepository { suspend fun getConnections(): Either>> suspend fun insertConnectionFromEvent(event: Event.User.NewConnection): Either suspend fun observeConnectionList(): Flow> - suspend fun observeConnectionRequestList(): Flow> + suspend fun observeConnectionRequestList(): Flow> suspend fun observeConnectionRequestsForNotification(): Flow> suspend fun setConnectionAsNotified(userId: UserId) suspend fun setAllConnectionsAsNotified() @@ -155,7 +155,7 @@ internal class ConnectionDataSource( observeConnectionRequestList() } - override suspend fun observeConnectionRequestList(): Flow> { + override suspend fun observeConnectionRequestList(): Flow> { return connectionDAO.getConnectionRequests().map { connections -> connections .map { connection -> diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/connection/ObserveConnectionListUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/connection/ObservePendingConnectionRequestsUseCase.kt similarity index 61% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/connection/ObserveConnectionListUseCase.kt rename to logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/connection/ObservePendingConnectionRequestsUseCase.kt index 415b9655286..2f47e02560f 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/connection/ObserveConnectionListUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/connection/ObservePendingConnectionRequestsUseCase.kt @@ -25,36 +25,41 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.map +@Deprecated( + "Name is misleading and will be removed in the future", + ReplaceWith("ObservePendingConnectionRequestsUseCase") +) +typealias ObserveConnectionListUseCase = ObservePendingConnectionRequestsUseCase + /** - * Use Case that listen to any user connection changes + * Use Case that lists the current pending connection requests. + * + * Only connections that are [ConnectionState.PENDING] or [ConnectionState.SENT] are returned. + * + * @see ConnectionState */ -fun interface ObserveConnectionListUseCase { +fun interface ObservePendingConnectionRequestsUseCase { /** - * Use case [ObserveConnectionListUseCase] operation + * Use case [ObservePendingConnectionRequestsUseCase] operation * - * @return a [Flow>] containing all current connections + * @return a [Flow] with a list of [ConversationDetails] containing all current connections */ - suspend operator fun invoke(): Flow> + suspend operator fun invoke(): Flow> } -internal class ObserveConnectionListUseCaseImpl internal constructor( +internal class ObservePendingConnectionRequestsUseCaseImpl internal constructor( private val connectionRepository: ConnectionRepository, -) : ObserveConnectionListUseCase { +) : ObservePendingConnectionRequestsUseCase { - override suspend operator fun invoke(): Flow> { + override suspend operator fun invoke(): Flow> { return connectionRepository.observeConnectionRequestList() .map { conversationDetails -> /** Ignored connections are filtered because they should not be visible * in conversation list */ - conversationDetails - .filter { - when (it) { - is ConversationDetails.Connection -> it.connection.status != ConnectionState.IGNORED - else -> false - } - } - } - .distinctUntilChanged() + conversationDetails.filter { + it.connection.status != ConnectionState.IGNORED + } + }.distinctUntilChanged() } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/ConversationScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/ConversationScope.kt index fe8f47ec6aa..105fd62efff 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/ConversationScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conversation/ConversationScope.kt @@ -44,7 +44,8 @@ import com.wire.kalium.logic.di.UserStorage import com.wire.kalium.logic.feature.connection.MarkConnectionRequestAsNotifiedUseCase import com.wire.kalium.logic.feature.connection.MarkConnectionRequestAsNotifiedUseCaseImpl import com.wire.kalium.logic.feature.connection.ObserveConnectionListUseCase -import com.wire.kalium.logic.feature.connection.ObserveConnectionListUseCaseImpl +import com.wire.kalium.logic.feature.connection.ObservePendingConnectionRequestsUseCase +import com.wire.kalium.logic.feature.connection.ObservePendingConnectionRequestsUseCaseImpl import com.wire.kalium.logic.feature.conversation.guestroomlink.CanCreatePasswordProtectedLinksUseCase import com.wire.kalium.logic.feature.conversation.guestroomlink.GenerateGuestRoomLinkUseCase import com.wire.kalium.logic.feature.conversation.guestroomlink.GenerateGuestRoomLinkUseCaseImpl @@ -171,8 +172,15 @@ class ConversationScope internal constructor( val updateConversationArchivedStatus: UpdateConversationArchivedStatusUseCase get() = UpdateConversationArchivedStatusUseCaseImpl(conversationRepository) + @Deprecated( + "Name is misleading, and this field will be removed", + ReplaceWith("observePendingConnectionRequests") + ) val observeConnectionList: ObserveConnectionListUseCase - get() = ObserveConnectionListUseCaseImpl(connectionRepository) + get() = observePendingConnectionRequests + + val observePendingConnectionRequests: ObservePendingConnectionRequestsUseCase + get() = ObservePendingConnectionRequestsUseCaseImpl(connectionRepository) val markConnectionRequestAsNotified: MarkConnectionRequestAsNotifiedUseCase get() = MarkConnectionRequestAsNotifiedUseCaseImpl(connectionRepository)