Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make interaction availability as extension function [WPB-3176] #2970

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.wire.kalium.logic.data.id.TeamId
import com.wire.kalium.logic.data.message.MessagePreview
import com.wire.kalium.logic.data.message.UnreadEventType
import com.wire.kalium.logic.data.mls.CipherSuite
import com.wire.kalium.logic.data.user.ConnectionState
import com.wire.kalium.logic.data.user.OtherUser
import com.wire.kalium.logic.data.user.User
import com.wire.kalium.logic.data.user.UserId
Expand Down Expand Up @@ -341,6 +342,57 @@ sealed class ConversationDetails(open val conversation: Conversation) {
)
}

fun ConversationDetails.interactionAvailability(): InteractionAvailability {
val availability = when (this) {
is ConversationDetails.Connection -> InteractionAvailability.DISABLED
is ConversationDetails.Group -> {
if (isSelfUserMember) InteractionAvailability.ENABLED
else InteractionAvailability.NOT_MEMBER
}

is ConversationDetails.OneOne -> when {
otherUser.defederated -> InteractionAvailability.DISABLED
otherUser.deleted -> InteractionAvailability.DELETED_USER
otherUser.connectionStatus == ConnectionState.BLOCKED -> InteractionAvailability.BLOCKED_USER
conversation.legalHoldStatus == Conversation.LegalHoldStatus.DEGRADED ->
InteractionAvailability.LEGAL_HOLD

else -> InteractionAvailability.ENABLED
}

is ConversationDetails.Self, is ConversationDetails.Team -> InteractionAvailability.DISABLED
}
return availability
}

enum class InteractionAvailability {
/**User is able to send messages and make calls */
ENABLED,

/**Self user is no longer conversation member */
NOT_MEMBER,

/**Other user is blocked by self user */
BLOCKED_USER,

/**Other team member or public user has been removed */
DELETED_USER,

/**
* This indicates that the conversation is using a protocol that self user does not support.
*/
UNSUPPORTED_PROTOCOL,

/**Conversation type doesn't support messaging */
DISABLED,

/**
* One of conversation members is under legal hold and self user is not able to interact with it.
* This applies to 1:1 conversations only when other member is a guest.
*/
LEGAL_HOLD
}

data class MembersInfo(val self: Conversation.Member, val otherMembers: List<Conversation.Member>)

data class MemberDetails(val user: User, val role: Conversation.Member.Role)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.conversation.ConversationDetails
import com.wire.kalium.logic.data.conversation.ConversationRepository
import com.wire.kalium.logic.data.conversation.InteractionAvailability
import com.wire.kalium.logic.data.conversation.interactionAvailability
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.message.MessageContent
import com.wire.kalium.logic.data.user.ConnectionState
import com.wire.kalium.logic.data.user.SelfUser
import com.wire.kalium.logic.data.user.SupportedProtocol
import com.wire.kalium.logic.data.user.UserRepository
Expand Down Expand Up @@ -65,24 +66,7 @@ class ObserveConversationInteractionAvailabilityUseCase internal constructor(
if (!isProtocolSupported) { // short-circuit to Unsupported Protocol if it's the case
return@fold IsInteractionAvailableResult.Success(InteractionAvailability.UNSUPPORTED_PROTOCOL)
}
val availability = when (conversationDetails) {
is ConversationDetails.Connection -> InteractionAvailability.DISABLED
is ConversationDetails.Group -> {
if (conversationDetails.isSelfUserMember) InteractionAvailability.ENABLED
else InteractionAvailability.NOT_MEMBER
}

is ConversationDetails.OneOne -> when {
conversationDetails.otherUser.defederated -> InteractionAvailability.DISABLED
conversationDetails.otherUser.deleted -> InteractionAvailability.DELETED_USER
conversationDetails.otherUser.connectionStatus == ConnectionState.BLOCKED -> InteractionAvailability.BLOCKED_USER
conversationDetails.conversation.legalHoldStatus == Conversation.LegalHoldStatus.DEGRADED ->
InteractionAvailability.LEGAL_HOLD
else -> InteractionAvailability.ENABLED
}

is ConversationDetails.Self, is ConversationDetails.Team -> InteractionAvailability.DISABLED
}
val availability = conversationDetails.interactionAvailability()
IsInteractionAvailableResult.Success(availability)
})
}
Expand Down Expand Up @@ -110,31 +94,3 @@ sealed class IsInteractionAvailableResult {
data class Success(val interactionAvailability: InteractionAvailability) : IsInteractionAvailableResult()
data class Failure(val coreFailure: CoreFailure) : IsInteractionAvailableResult()
}

enum class InteractionAvailability {
/**User is able to send messages and make calls */
ENABLED,

/**Self user is no longer conversation member */
NOT_MEMBER,

/**Other user is blocked by self user */
BLOCKED_USER,

/**Other team member or public user has been removed */
DELETED_USER,

/**
* This indicates that the conversation is using a protocol that self user does not support.
*/
UNSUPPORTED_PROTOCOL,

/**Conversation type doesn't support messaging */
DISABLED,

/**
* One of conversation members is under legal hold and self user is not able to interact with it.
* This applies to 1:1 conversations only when other member is a guest.
*/
LEGAL_HOLD
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package com.wire.kalium.logic.feature.conversation
import app.cash.turbine.test
import com.wire.kalium.logic.StorageFailure
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.conversation.InteractionAvailability
import com.wire.kalium.logic.data.user.ConnectionState
import com.wire.kalium.logic.data.user.SupportedProtocol
import com.wire.kalium.logic.framework.TestConversation
Expand Down
Loading