Skip to content

Commit

Permalink
feat: handle legal hold system messages [WPB-4779] (#2505)
Browse files Browse the repository at this point in the history
  • Loading branch information
saleniuk authored Dec 12, 2023
1 parent a963b92 commit ebcf86d
Show file tree
Hide file tree
Showing 16 changed files with 315 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class MessageMapper @Inject constructor(
is Message.System -> {
when (val content = message.content) {
is MessageContent.MemberChange -> content.members
is MessageContent.LegalHold.ForMembers -> content.members
else -> listOf()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class SystemMessageContentMapper @Inject constructor(
is MessageContent.FederationStopped -> mapFederationMessage(content)
is MessageContent.ConversationProtocolChanged -> mapConversationProtocolChanged(content)
is MessageContent.ConversationStartedUnverifiedWarning -> mapConversationCreatedUnverifiedWarning()
is MessageContent.LegalHold -> mapLegalHoldMessage(content, message.senderUserId, members)
}

private fun mapConversationCreated(senderUserId: UserId, date: String, userList: List<User>): UIMessageContent.SystemMessage {
Expand Down Expand Up @@ -276,6 +277,38 @@ class SystemMessageContentMapper @Inject constructor(
else -> UIText.StringResource(messageResourceProvider.memberNameDeleted)
}

private fun mapLegalHoldMessage(
content: MessageContent.LegalHold,
senderUserId: UserId,
userList: List<User>
): UIMessageContent.SystemMessage {

fun handleLegalHoldForMembers(
members: List<UserId>,
self: () -> UIMessageContent.SystemMessage.LegalHold,
others: (List<UIText>) -> UIMessageContent.SystemMessage.LegalHold
): UIMessageContent.SystemMessage.LegalHold =
if (members.size == 1 && senderUserId == members.first()) self()
else others(members.map { mapMemberName(user = userList.findUser(userId = it), type = SelfNameType.ResourceLowercase) })

return when (content) {
MessageContent.LegalHold.ForConversation.Disabled -> UIMessageContent.SystemMessage.LegalHold.Disabled.Conversation
MessageContent.LegalHold.ForConversation.Enabled -> UIMessageContent.SystemMessage.LegalHold.Enabled.Conversation

is MessageContent.LegalHold.ForMembers.Disabled -> handleLegalHoldForMembers(
members = content.members,
self = { UIMessageContent.SystemMessage.LegalHold.Disabled.Self },
others = { UIMessageContent.SystemMessage.LegalHold.Disabled.Others(it) }
)

is MessageContent.LegalHold.ForMembers.Enabled -> handleLegalHoldForMembers(
members = content.members,
self = { UIMessageContent.SystemMessage.LegalHold.Enabled.Self },
others = { UIMessageContent.SystemMessage.LegalHold.Enabled.Others(it) }
)
}
}

enum class SelfNameType {
ResourceLowercase, ResourceTitleCase, NameOrDeleted
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,30 @@

package com.wire.android.ui.common

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.res.painterResource
import com.wire.android.R
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.util.ui.PreviewMultipleThemes

@Composable
fun LegalHoldIndicator(modifier: Modifier = Modifier) {
Box(
Icon(
painter = painterResource(id = R.drawable.ic_legal_hold),
contentDescription = null,
tint = MaterialTheme.wireColorScheme.error,
modifier = modifier,
contentAlignment = Alignment.Center
) {
Box(
modifier = Modifier
.size(12.dp)
.clip(CircleShape)
.background(MaterialTheme.colorScheme.errorContainer)
)
Box(
modifier = Modifier
.size(6.dp)
.clip(CircleShape)
.background(MaterialTheme.colorScheme.error)
)
}
)
}

@Preview
@PreviewMultipleThemes
@Composable
fun PreviewLegalHoldIndicator() {
LegalHoldIndicator()
WireTheme {
LegalHoldIndicator()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import com.wire.kalium.logic.data.call.Call
import com.wire.kalium.logic.data.user.LegalHoldStatus
import com.wire.kalium.logic.data.sync.SyncState
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldRequestUseCaseResult
import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldRequestUseCase
import com.wire.kalium.logic.feature.session.CurrentSessionResult
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down Expand Up @@ -82,7 +82,7 @@ class CommonTopAppBarViewModel @Inject constructor(
observeLegalHoldRequest() // TODO combine with legal hold status
.map { legalHoldRequestResult ->
when (legalHoldRequestResult) {
is ObserveLegalHoldRequestUseCaseResult.ObserveLegalHoldRequestAvailable -> LegalHoldStatus.PENDING
is ObserveLegalHoldRequestUseCase.Result.LegalHoldRequestAvailable -> LegalHoldStatus.PENDING
else -> LegalHoldStatus.DISABLED
}
}
Expand Down
Loading

0 comments on commit ebcf86d

Please sign in to comment.