Skip to content

Commit

Permalink
feat(mls): reevaluate protocol on client demand
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorhugods committed Nov 30, 2023
1 parent 732b5cf commit ee601cc
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,8 @@ class UserSessionScope internal constructor(
userStorage,
userPropertyRepository,
oneOnOneResolver,
this
this,
userScopedLogger
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.wire.kalium.logic.feature.conversation

import co.touchlab.stately.collections.ConcurrentMutableMap
import com.wire.kalium.logger.KaliumLogger
import com.wire.kalium.logic.cache.SelfConversationIdProvider
import com.wire.kalium.logic.configuration.server.ServerConfigRepository
import com.wire.kalium.logic.data.connection.ConnectionRepository
Expand Down Expand Up @@ -92,7 +93,8 @@ class ConversationScope internal constructor(
private val userStorage: UserStorage,
userPropertyRepository: UserPropertyRepository,
private val oneOnOneResolver: OneOnOneResolver,
private val scope: CoroutineScope
private val scope: CoroutineScope,
private val kaliumLogger: KaliumLogger
) {

val getSelfTeamUseCase: GetSelfTeamUseCase
Expand Down Expand Up @@ -125,6 +127,13 @@ class ConversationScope internal constructor(
val observeConversationDetails: ObserveConversationDetailsUseCase
get() = ObserveConversationDetailsUseCase(conversationRepository)

val notifyConversationIsOpen: NotifyConversationIsOpenUseCase
get() = NotifyConversationIsOpenUseCaseImpl(
oneOnOneResolver,
conversationRepository,
kaliumLogger
)

val observeIsSelfUserMemberUseCase: ObserveIsSelfUserMemberUseCase
get() = ObserveIsSelfUserMemberUseCaseImpl(conversationRepository, selfUserId)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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.feature.conversation

import com.wire.kalium.logic.framework.TestConversationDetails
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.kaliumLogger
import com.wire.kalium.logic.util.arrangement.mls.OneOnOneResolverArrangement
import com.wire.kalium.logic.util.arrangement.mls.OneOnOneResolverArrangementImpl
import com.wire.kalium.logic.util.arrangement.repository.ConversationRepositoryArrangement
import com.wire.kalium.logic.util.arrangement.repository.ConversationRepositoryArrangementImpl
import io.mockative.any
import io.mockative.eq
import io.mockative.once
import io.mockative.verify
import kotlinx.coroutines.test.runTest
import kotlin.test.Test

class NotifyConversationIsOpenUseCaseTest {

@Test
fun givenConversationId_whenInvoking_thenShouldGetDetailsFromRepository() = runTest {
val details = TestConversationDetails.CONVERSATION_GROUP
val (arrangement, notifyConversationIsOpenUseCase) = arrange {
withObserveConversationDetailsByIdReturning(
Either.Right(details)
)
}
notifyConversationIsOpenUseCase.invoke(details.conversation.id)

verify(arrangement.conversationRepository)
.suspendFunction(arrangement.conversationRepository::observeConversationDetailsById)
.with(eq(details.conversation.id))
.wasInvoked(exactly = once)
}

@Test
fun givenGroupConversationId_whenInvoking_thenShouldNotUseResolver() = runTest {
val details = TestConversationDetails.CONVERSATION_GROUP
val (arrangement, notifyConversationIsOpenUseCase) = arrange {
withObserveConversationDetailsByIdReturning(
Either.Right(details)
)
}
notifyConversationIsOpenUseCase.invoke(details.conversation.id)

verify(arrangement.oneOnOneResolver)
.suspendFunction(arrangement.oneOnOneResolver::resolveOneOnOneConversationWithUser)
.with(any())
.wasNotInvoked()
}

@Test
fun givenOneOnOneConversationId_whenInvoking_thenShouldResolveProtocolForUser() = runTest {
val details = TestConversationDetails.CONVERSATION_ONE_ONE
val (arrangement, notifyConversationIsOpenUseCase) = arrange {
withObserveConversationDetailsByIdReturning(
Either.Right(details)
)
withResolveOneOnOneConversationWithUserReturning(
Either.Right(details.conversation.id)
)
}
notifyConversationIsOpenUseCase.invoke(details.conversation.id)

verify(arrangement.oneOnOneResolver)
.suspendFunction(arrangement.oneOnOneResolver::resolveOneOnOneConversationWithUser)
.with(eq(details.otherUser))
.wasInvoked(exactly = once)
}

private class Arrangement(
private val configure: Arrangement.() -> Unit
) : OneOnOneResolverArrangement by OneOnOneResolverArrangementImpl(),
ConversationRepositoryArrangement by ConversationRepositoryArrangementImpl() {
fun arrange(): Pair<Arrangement, NotifyConversationIsOpenUseCase> = run {
configure()
this@Arrangement to NotifyConversationIsOpenUseCaseImpl(
oneOnOneResolver = oneOnOneResolver,
conversationRepository = conversationRepository,
kaliumLogger = kaliumLogger
)
}
}

private companion object {
fun arrange(configure: Arrangement.() -> Unit) = Arrangement(configure).arrange()
}
}

0 comments on commit ee601cc

Please sign in to comment.