Skip to content

Commit

Permalink
Merge branch 'develop' into mention-while-typing
Browse files Browse the repository at this point in the history
  • Loading branch information
ohassine authored Dec 2, 2024
2 parents 5ebe739 + e399e5b commit ac8f978
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.wire.android.di.KaliumCoreLogic
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.search.FederatedSearchParser
import com.wire.kalium.logic.feature.search.IsFederationSearchAllowedUseCase
import com.wire.kalium.logic.feature.search.SearchByHandleUseCase
import com.wire.kalium.logic.feature.search.SearchScope
import com.wire.kalium.logic.feature.search.SearchUsersUseCase
Expand Down Expand Up @@ -53,4 +54,9 @@ class SearchModule {
@ViewModelScoped
@Provides
fun provideFederatedSearchParser(searchScope: SearchScope): FederatedSearchParser = searchScope.federatedSearchParser

@ViewModelScoped
@Provides
fun provideIsFederationSearchAllowedUseCase(searchScope: SearchScope): IsFederationSearchAllowedUseCase =
searchScope.isFederationSearchAllowedUseCase
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,13 @@ import com.wire.android.mapper.ContactMapper
import com.wire.android.ui.home.newconversation.model.Contact
import com.wire.android.ui.navArgs
import com.wire.android.util.EMPTY
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.user.SupportedProtocol
import com.wire.kalium.logic.feature.auth.ValidateUserHandleResult
import com.wire.kalium.logic.feature.auth.ValidateUserHandleUseCase
import com.wire.kalium.logic.feature.conversation.GetConversationProtocolInfoUseCase
import com.wire.kalium.logic.feature.search.FederatedSearchParser
import com.wire.kalium.logic.feature.search.IsFederationSearchAllowedUseCase
import com.wire.kalium.logic.feature.search.SearchByHandleUseCase
import com.wire.kalium.logic.feature.search.SearchUserResult
import com.wire.kalium.logic.feature.search.SearchUsersUseCase
import com.wire.kalium.logic.feature.user.GetDefaultProtocolUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.ImmutableSet
Expand All @@ -59,8 +56,7 @@ class SearchUserViewModel @Inject constructor(
private val contactMapper: ContactMapper,
private val federatedSearchParser: FederatedSearchParser,
private val validateUserHandle: ValidateUserHandleUseCase,
private val getDefaultProtocol: GetDefaultProtocolUseCase,
private val getConversationProtocolInfo: GetConversationProtocolInfoUseCase,
private val isFederationSearchAllowed: IsFederationSearchAllowedUseCase,
savedStateHandle: SavedStateHandle
) : ViewModel() {

Expand All @@ -78,17 +74,7 @@ class SearchUserViewModel @Inject constructor(

init {
viewModelScope.launch {
val isProteusTeam = getDefaultProtocol() == SupportedProtocol.PROTEUS

val isOtherDomainAllowed: Boolean = addMembersSearchNavArgs?.conversationId?.let { conversationId ->
when (val result = getConversationProtocolInfo(conversationId)) {
is GetConversationProtocolInfoUseCase.Result.Failure -> !isProteusTeam

is GetConversationProtocolInfoUseCase.Result.Success ->
!isProteusTeam && result.protocolInfo !is Conversation.ProtocolInfo.Proteus
}
} ?: !isProteusTeam

val isOtherDomainAllowed = isFederationSearchAllowed(addMembersSearchNavArgs?.conversationId)
state = state.copy(isOtherDomainAllowed = isOtherDomainAllowed)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ import com.wire.kalium.logic.data.id.GroupID
import com.wire.kalium.logic.data.mls.CipherSuite
import com.wire.kalium.logic.data.publicuser.model.UserSearchDetails
import com.wire.kalium.logic.data.user.ConnectionState
import com.wire.kalium.logic.data.user.SupportedProtocol
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.type.UserType
import com.wire.kalium.logic.feature.auth.ValidateUserHandleResult
import com.wire.kalium.logic.feature.auth.ValidateUserHandleUseCase
import com.wire.kalium.logic.feature.conversation.GetConversationProtocolInfoUseCase
import com.wire.kalium.logic.feature.search.FederatedSearchParser
import com.wire.kalium.logic.feature.search.IsFederationSearchAllowedUseCase
import com.wire.kalium.logic.feature.search.SearchByHandleUseCase
import com.wire.kalium.logic.feature.search.SearchUserResult
import com.wire.kalium.logic.feature.search.SearchUsersUseCase
import com.wire.kalium.logic.feature.user.GetDefaultProtocolUseCase
import io.mockk.MockKAnnotations
import io.mockk.coEvery
import io.mockk.coVerify
Expand Down Expand Up @@ -138,10 +136,9 @@ class SearchUserViewModelTest {
fun `given Proteus conversation and MLS team, when calling the searchUseCase, then otherDomain is not allowed`() =
runTest {
val conversationId = ConversationId("id", "domain")
val (arrangement, viewModel) = Arrangement()
val (_, viewModel) = Arrangement()
.withAddMembersSearchNavArgs(AddMembersSearchNavArgs(conversationId, true))
.withConversationProtocolInfo(GetConversationProtocolInfoUseCase.Result.Success(Conversation.ProtocolInfo.Proteus))
.withDefaultProtocol(SupportedProtocol.MLS)
.withIsFederationSearchAllowedResult(false)
.withIsValidHandleResult(ValidateUserHandleResult.Valid(""))
.withFederatedSearchParserResult(
FederatedSearchParser.Result(
Expand All @@ -164,10 +161,9 @@ class SearchUserViewModelTest {
fun `given MLS conversation and Proteus team, when calling the searchUseCase, then otherDomain is not allowed`() =
runTest {
val conversationId = ConversationId("id", "domain")
val (arrangement, viewModel) = Arrangement()
val (_, viewModel) = Arrangement()
.withAddMembersSearchNavArgs(AddMembersSearchNavArgs(conversationId, true))
.withConversationProtocolInfo(GetConversationProtocolInfoUseCase.Result.Success(mlsProtocol))
.withDefaultProtocol(SupportedProtocol.PROTEUS)
.withIsFederationSearchAllowedResult(false)
.withIsValidHandleResult(ValidateUserHandleResult.Valid(""))
.withFederatedSearchParserResult(
FederatedSearchParser.Result(
Expand All @@ -190,10 +186,9 @@ class SearchUserViewModelTest {
fun `given MLS conversation and MLS team, when calling the searchUseCase, then otherDomain is allowed`() =
runTest {
val conversationId = ConversationId("id", "domain")
val (arrangement, viewModel) = Arrangement()
val (_, viewModel) = Arrangement()
.withAddMembersSearchNavArgs(AddMembersSearchNavArgs(conversationId, true))
.withConversationProtocolInfo(GetConversationProtocolInfoUseCase.Result.Success(mlsProtocol))
.withDefaultProtocol(SupportedProtocol.MLS)
.withIsFederationSearchAllowedResult(true)
.withIsValidHandleResult(ValidateUserHandleResult.Valid(""))
.withFederatedSearchParserResult(
FederatedSearchParser.Result(
Expand Down Expand Up @@ -360,21 +355,15 @@ class SearchUserViewModelTest {
lateinit var searchByHandleUseCase: SearchByHandleUseCase

@MockK
lateinit var getDefaultProtocolUseCase: GetDefaultProtocolUseCase

@MockK
lateinit var getConversationProtocolInfo: GetConversationProtocolInfoUseCase
lateinit var isFederationSearchAllowedUseCase: IsFederationSearchAllowedUseCase

init {
MockKAnnotations.init(this, relaxUnitFun = true)
every { contactMapper.fromSearchUserResult(any()) } answers {
val user = args.get(0) as UserSearchDetails
fromSearchUserResult(user)
}
every { getDefaultProtocolUseCase() } returns SupportedProtocol.PROTEUS
coEvery {
getConversationProtocolInfo(any())
} returns GetConversationProtocolInfoUseCase.Result.Success(Conversation.ProtocolInfo.Proteus)
withIsFederationSearchAllowedResult(false)
}

fun fromSearchUserResult(user: UserSearchDetails): Contact {
Expand Down Expand Up @@ -427,12 +416,8 @@ class SearchUserViewModelTest {
coEvery { searchByHandleUseCase(any(), any(), any()) } returns result
}

suspend fun withConversationProtocolInfo(result: GetConversationProtocolInfoUseCase.Result) = apply {
coEvery { getConversationProtocolInfo(any()) } returns result
}

fun withDefaultProtocol(protocol: SupportedProtocol) = apply {
every { getDefaultProtocolUseCase() } returns protocol
fun withIsFederationSearchAllowedResult(isAllowed: Boolean = true) = apply {
coEvery { isFederationSearchAllowedUseCase(any()) } returns isAllowed
}

private lateinit var searchUserViewModel: SearchUserViewModel
Expand All @@ -444,8 +429,7 @@ class SearchUserViewModelTest {
contactMapper = contactMapper,
federatedSearchParser = federatedSearchParser,
validateUserHandle = validateUserHandle,
getConversationProtocolInfo = getConversationProtocolInfo,
getDefaultProtocol = getDefaultProtocolUseCase,
isFederationSearchAllowed = isFederationSearchAllowedUseCase,
savedStateHandle = savedStateHandle
)
}.run {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mockk = "1.13.10"
okio = "3.9.0"
turbine = "1.2.0"
robolectric = "4.12.1"
hamcrest = "2.2"
hamcrest = "3.0"

[plugins]
# 3rd Party plugins
Expand Down

0 comments on commit ac8f978

Please sign in to comment.