Skip to content

Commit

Permalink
fix: hide LH indicators on conversations when self user is under LH […
Browse files Browse the repository at this point in the history
…WPB-6391] (#3637)
  • Loading branch information
saleniuk authored Nov 20, 2024
1 parent 9d6d30d commit d40175e
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun ConversationDetailsWithEvents.toConversationItem(
groupName = conversationDetails.conversation.name.orEmpty(),
conversationId = conversationDetails.conversation.id,
mutedStatus = conversationDetails.conversation.mutedStatus,
isLegalHold = conversationDetails.conversation.legalHoldStatus.showLegalHoldIndicator(),
showLegalHoldIndicator = conversationDetails.conversation.legalHoldStatus.showLegalHoldIndicator(),
lastMessageContent = lastMessage.toUIPreview(unreadEventCount),
badgeEventType = parseConversationEventType(
mutedStatus = conversationDetails.conversation.mutedStatus,
Expand Down Expand Up @@ -83,7 +83,7 @@ fun ConversationDetailsWithEvents.toConversationItem(
),
conversationId = conversationDetails.conversation.id,
mutedStatus = conversationDetails.conversation.mutedStatus,
isLegalHold = conversationDetails.conversation.legalHoldStatus.showLegalHoldIndicator(),
showLegalHoldIndicator = conversationDetails.conversation.legalHoldStatus.showLegalHoldIndicator(),
lastMessageContent = lastMessage.toUIPreview(unreadEventCount),
badgeEventType = parsePrivateConversationEventType(
conversationDetails.otherUser.connectionStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class MessageMapper @Inject constructor(
is SelfUser, null -> Membership.None
},
connectionState = getConnectionState(sender),
isLegalHold = sender?.isUnderLegalHold == true,
showLegalHoldIndicator = sender?.isUnderLegalHold == true,
messageTime = MessageTime(message.date),
messageStatus = getMessageStatus(message),
messageId = message.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fun rememberConversationSheetState(
protocol = Conversation.ProtocolInfo.Proteus,
mlsVerificationStatus = Conversation.VerificationStatus.VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.VERIFIED,
isUnderLegalHold = isLegalHold
isUnderLegalHold = showLegalHoldIndicator
)
}
}
Expand All @@ -102,7 +102,7 @@ fun rememberConversationSheetState(
protocol = Conversation.ProtocolInfo.Proteus,
mlsVerificationStatus = Conversation.VerificationStatus.VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.VERIFIED,
isUnderLegalHold = isLegalHold
isUnderLegalHold = showLegalHoldIndicator
)
}
}
Expand All @@ -122,7 +122,7 @@ fun rememberConversationSheetState(
protocol = Conversation.ProtocolInfo.Proteus,
mlsVerificationStatus = Conversation.VerificationStatus.VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.VERIFIED,
isUnderLegalHold = isLegalHold
isUnderLegalHold = showLegalHoldIndicator
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ private fun MessageAuthorRow(messageHeader: MessageHeader) {
startPadding = dimensions().spacing6x,
isDeleted = isSenderDeleted
)
if (isLegalHold) {
if (showLegalHoldIndicator) {
LegalHoldIndicator(modifier = Modifier.padding(start = dimensions().spacing6x))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ val mockMessageTime = MessageTime(Instant.fromEpochSeconds(MOCK_TIME_IN_SECONDS)
val mockHeader = MessageHeader(
username = UIText.DynamicString("John Doe"),
membership = Membership.Guest,
isLegalHold = true,
showLegalHoldIndicator = true,
messageTime = mockMessageTime,
messageStatus = MessageStatus(
flowStatus = MessageFlowStatus.Sent,
Expand Down Expand Up @@ -307,7 +307,7 @@ fun mockAssetMessage(assetId: String = "asset1", messageId: String = "msg1") = U
header = MessageHeader(
username = UIText.DynamicString("John Doe"),
membership = Membership.Guest,
isLegalHold = true,
showLegalHoldIndicator = true,
messageTime = mockMessageTime,
messageStatus = MessageStatus(
flowStatus = MessageFlowStatus.Sent,
Expand Down Expand Up @@ -337,7 +337,7 @@ fun mockAssetAudioMessage(assetId: String = "asset1", messageId: String = "msg1"
header = MessageHeader(
username = UIText.DynamicString("John Doe"),
membership = Membership.Guest,
isLegalHold = true,
showLegalHoldIndicator = true,
messageTime = mockMessageTime,
messageStatus = MessageStatus(
flowStatus = MessageFlowStatus.Sent,
Expand Down Expand Up @@ -396,7 +396,7 @@ fun mockedImageUIMessage(
header = MessageHeader(
username = UIText.DynamicString("John Doe"),
membership = Membership.External,
isLegalHold = false,
showLegalHoldIndicator = false,
messageTime = mockMessageTime,
messageStatus = messageStatus,
messageId = messageId,
Expand All @@ -417,7 +417,7 @@ fun getMockedMessages(): List<UIMessage> = listOf(
header = MessageHeader(
username = UIText.DynamicString("John Doe"),
membership = Membership.Guest,
isLegalHold = true,
showLegalHoldIndicator = true,
messageTime = mockMessageTime,
messageStatus = MessageStatus(
flowStatus = MessageFlowStatus.Sent,
Expand Down Expand Up @@ -447,7 +447,7 @@ fun getMockedMessages(): List<UIMessage> = listOf(
header = MessageHeader(
username = UIText.DynamicString("John Doe"),
membership = Membership.Guest,
isLegalHold = true,
showLegalHoldIndicator = true,
messageTime = mockMessageTime,
messageStatus = MessageStatus(
flowStatus = MessageFlowStatus.Delivered, isDeleted = true,
Expand All @@ -468,7 +468,7 @@ fun getMockedMessages(): List<UIMessage> = listOf(
header = MessageHeader(
username = UIText.DynamicString("John Doe"),
membership = Membership.External,
isLegalHold = false,
showLegalHoldIndicator = false,
messageTime = mockMessageTime,
messageStatus = MessageStatus(
flowStatus = MessageFlowStatus.Sent,
Expand All @@ -490,7 +490,7 @@ fun getMockedMessages(): List<UIMessage> = listOf(
header = MessageHeader(
username = UIText.DynamicString("John Doe"),
membership = Membership.External,
isLegalHold = false,
showLegalHoldIndicator = false,
messageTime = mockMessageTime,
messageStatus = MessageStatus(
flowStatus = MessageFlowStatus.Sent,
Expand All @@ -512,7 +512,7 @@ fun getMockedMessages(): List<UIMessage> = listOf(
header = MessageHeader(
username = UIText.DynamicString("John Doe"),
membership = Membership.External,
isLegalHold = false,
showLegalHoldIndicator = false,
messageTime = mockMessageTime,
messageStatus = MessageStatus(
flowStatus = MessageFlowStatus.Delivered,
Expand Down Expand Up @@ -543,7 +543,7 @@ fun getMockedMessages(): List<UIMessage> = listOf(
header = MessageHeader(
username = UIText.DynamicString("John Doe"),
membership = Membership.External,
isLegalHold = false,
showLegalHoldIndicator = false,
messageTime = mockMessageTime,
messageStatus = MessageStatus(
flowStatus = MessageFlowStatus.Sent,
Expand All @@ -565,7 +565,7 @@ fun getMockedMessages(): List<UIMessage> = listOf(
header = MessageHeader(
username = UIText.DynamicString("John Doe"),
membership = Membership.External,
isLegalHold = false,
showLegalHoldIndicator = false,
messageTime = mockMessageTime,
messageStatus = MessageStatus(
flowStatus = MessageFlowStatus.Sent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ sealed interface UIMessage {
data class MessageHeader(
val username: UIText,
val membership: Membership,
val isLegalHold: Boolean,
val showLegalHoldIndicator: Boolean,
val messageTime: MessageTime,
val messageStatus: MessageStatus,
val messageId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.insertSeparators
import androidx.paging.map
import com.wire.android.BuildConfig
import com.wire.android.appLogger
import com.wire.android.di.CurrentAccount
Expand Down Expand Up @@ -64,6 +65,8 @@ import com.wire.kalium.logic.feature.conversation.RefreshConversationsWithoutMet
import com.wire.kalium.logic.feature.conversation.RemoveMemberFromConversationUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationArchivedStatusUseCase
import com.wire.kalium.logic.feature.conversation.UpdateConversationMutedStatusUseCase
import com.wire.kalium.logic.feature.legalhold.LegalHoldStateForSelfUser
import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldStateForSelfUserUseCase
import com.wire.kalium.logic.feature.publicuser.RefreshUsersWithoutMetadataUseCase
import com.wire.kalium.logic.feature.team.DeleteTeamConversationUseCase
import com.wire.kalium.logic.feature.team.Result
Expand All @@ -78,6 +81,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emptyFlow
Expand Down Expand Up @@ -121,6 +125,7 @@ class ConversationListViewModelPreview(
@HiltViewModel(assistedFactory = ConversationListViewModelImpl.Factory::class)
class ConversationListViewModelImpl @AssistedInject constructor(
@Assisted val conversationsSource: ConversationsSource,
@Assisted private val usePagination: Boolean = BuildConfig.PAGINATED_CONVERSATION_LIST_ENABLED,
dispatcher: DispatcherProvider,
private val updateConversationMutedStatus: UpdateConversationMutedStatusUseCase,
private val getConversationsPaginated: GetConversationsFromSearchUseCase,
Expand All @@ -133,14 +138,18 @@ class ConversationListViewModelImpl @AssistedInject constructor(
private val refreshUsersWithoutMetadata: RefreshUsersWithoutMetadataUseCase,
private val refreshConversationsWithoutMetadata: RefreshConversationsWithoutMetadataUseCase,
private val updateConversationArchivedStatus: UpdateConversationArchivedStatusUseCase,
private val observeLegalHoldStateForSelfUser: ObserveLegalHoldStateForSelfUserUseCase,
@CurrentAccount val currentAccount: UserId,
private val wireSessionImageLoader: WireSessionImageLoader,
private val userTypeMapper: UserTypeMapper,
) : ConversationListViewModel, ViewModel() {

@AssistedFactory
interface Factory {
fun create(conversationsSource: ConversationsSource): ConversationListViewModelImpl
fun create(
conversationsSource: ConversationsSource,
usePagination: Boolean = BuildConfig.PAGINATED_CONVERSATION_LIST_ENABLED,
): ConversationListViewModelImpl
}

private val _infoMessage = MutableSharedFlow<SnackBarMessage>()
Expand Down Expand Up @@ -173,7 +182,11 @@ class ConversationListViewModelImpl @AssistedInject constructor(
conversationFilter = conversationsSource.toFilter(),
onlyInteractionEnabled = false,
newActivitiesOnTop = containsNewActivitiesSection,
).map {
).combine(observeLegalHoldStateForSelfUser()) { conversations, selfUserLegalHoldStatus ->
conversations.map {
it.hideIndicatorForSelfUserUnderLegalHold(selfUserLegalHoldStatus)
}
}.map {
it.insertSeparators { before, after ->
when {
// do not add separators if the list shouldn't show conversations grouped into different folders
Expand All @@ -200,7 +213,7 @@ class ConversationListViewModelImpl @AssistedInject constructor(

private var notPaginatedConversationListState by mutableStateOf(ConversationListState.NotPaginated())
override val conversationListState: ConversationListState
get() = if (BuildConfig.PAGINATED_CONVERSATION_LIST_ENABLED) {
get() = if (usePagination) {
ConversationListState.Paginated(
conversations = conversationsPaginatedFlow,
domain = currentAccount.domain
Expand All @@ -210,7 +223,7 @@ class ConversationListViewModelImpl @AssistedInject constructor(
}

init {
if (!BuildConfig.PAGINATED_CONVERSATION_LIST_ENABLED) {
if (!usePagination) {
viewModelScope.launch {
searchQueryFlow
.debounce { if (it.isEmpty()) 0L else DEFAULT_SEARCH_QUERY_DEBOUNCE }
Expand All @@ -220,13 +233,13 @@ class ConversationListViewModelImpl @AssistedInject constructor(
observeConversationListDetailsWithEvents(
fromArchive = conversationsSource == ConversationsSource.ARCHIVE,
conversationFilter = conversationsSource.toFilter()
).map {
it.map { conversationDetails ->
).combine(observeLegalHoldStateForSelfUser()) { conversations, selfUserLegalHoldStatus ->
conversations.map { conversationDetails ->
conversationDetails.toConversationItem(
wireSessionImageLoader = wireSessionImageLoader,
userTypeMapper = userTypeMapper,
searchQuery = searchQuery,
)
).hideIndicatorForSelfUserUnderLegalHold(selfUserLegalHoldStatus)
} to searchQuery
}
}
Expand Down Expand Up @@ -438,6 +451,19 @@ private fun ConversationsSource.toFilter(): ConversationFilter = when (this) {
ConversationsSource.ONE_ON_ONE -> ConversationFilter.ONE_ON_ONE
}

private fun ConversationItem.hideIndicatorForSelfUserUnderLegalHold(selfUserLegalHoldStatus: LegalHoldStateForSelfUser) =
// if self user is under legal hold then we shouldn't show legal hold indicator next to every conversation
// the indication is shown in the header of the conversation list for self user in that case and it's enough
when (selfUserLegalHoldStatus) {
is LegalHoldStateForSelfUser.Enabled -> when (this) {
is ConversationItem.ConnectionConversation -> this.copy(showLegalHoldIndicator = false)
is ConversationItem.GroupConversation -> this.copy(showLegalHoldIndicator = false)
is ConversationItem.PrivateConversation -> this.copy(showLegalHoldIndicator = false)
}

else -> this
}

@Suppress("ComplexMethod")
private fun List<ConversationItem>.withFolders(source: ConversationsSource): Map<ConversationFolder, List<ConversationItem>> {
return when (source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private fun GeneralConversationItem(
title = {
ConversationTitle(
name = groupName.ifEmpty { stringResource(id = R.string.member_name_deleted_label) },
isLegalHold = conversation.isLegalHold,
showLegalHoldIndicator = conversation.showLegalHoldIndicator,
searchQuery = searchQuery
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun ConversationTitle(
name: String,
searchQuery: String,
modifier: Modifier = Modifier,
isLegalHold: Boolean = false,
showLegalHoldIndicator: Boolean = false,
badges: @Composable () -> Unit = {}
) {
Row(
Expand All @@ -57,7 +57,7 @@ fun ConversationTitle(
HighlightName(name = name, searchQuery = searchQuery)
}
badges()
if (isLegalHold) {
if (showLegalHoldIndicator) {
Spacer(modifier = Modifier.width(6.dp))
LegalHoldIndicator()
}
Expand All @@ -67,5 +67,5 @@ fun ConversationTitle(
@Preview(widthDp = 200)
@Composable
fun PreviewConversationTitle() {
ConversationTitle("very very loooooooooooong name", searchQuery = "test", isLegalHold = true)
ConversationTitle("very very loooooooooooong name", searchQuery = "test", showLegalHoldIndicator = true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun UserLabel(
with(userInfoLabel) {
ConversationTitle(
name = if (unavailable) stringResource(id = R.string.username_unavailable_label) else labelName,
isLegalHold = isLegalHold,
showLegalHoldIndicator = showLegalHoldIndicator,
modifier = modifier,
badges = {
if (membership.hasLabel()) {
Expand All @@ -54,7 +54,7 @@ fun UserLabel(

data class UserInfoLabel(
val labelName: String,
val isLegalHold: Boolean,
val showLegalHoldIndicator: Boolean,
val membership: Membership,
val unavailable: Boolean = false,
val proteusVerificationStatus: Conversation.VerificationStatus? = null,
Expand Down
Loading

0 comments on commit d40175e

Please sign in to comment.