Skip to content

Commit

Permalink
feat: support new reason value on conversation leave event (#2536)
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara authored Dec 18, 2023
1 parent bf53877 commit aaa2d87
Show file tree
Hide file tree
Showing 47 changed files with 349 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ fun MessagePreview.uiLastMessageContent(): UILastMessageContent {
UILastMessageContent.TextMessage(MessageBody(previewMessageContent))
}

is WithUser.MembersRemoved -> {
val membersRemovedContent = (content as WithUser.MembersRemoved)
val isSelfRemoved = membersRemovedContent.isSelfUserRemoved
val otherUsersSize = membersRemovedContent.otherUserIdList.size
is WithUser.ConversationMembersRemoved -> {
val conversationMembersRemovedContent = (content as WithUser.ConversationMembersRemoved)
val isSelfRemoved = conversationMembersRemovedContent.isSelfUserRemoved
val otherUsersSize = conversationMembersRemovedContent.otherUserIdList.size

val previewMessageContent = when {
isSelfMessage && otherUsersSize > 0 -> {
Expand All @@ -234,6 +234,14 @@ fun MessagePreview.uiLastMessageContent(): UILastMessageContent {
UILastMessageContent.TextMessage(MessageBody(previewMessageContent))
}

is WithUser.TeamMembersRemoved -> {
val teamMembersRemovedContent = (content as WithUser.TeamMembersRemoved)
val previewMessageContent =
UIText.PluralResource(R.plurals.last_message_team_member_removed, teamMembersRemovedContent.otherUserIdList.size)

UILastMessageContent.TextMessage(MessageBody(previewMessageContent))
}

is WithUser.MentionedSelf -> UILastMessageContent.SenderWithMessage(
userUIText,
UIText.StringResource(R.string.last_message_mentioned)
Expand All @@ -244,7 +252,7 @@ fun MessagePreview.uiLastMessageContent(): UILastMessageContent {
UIText.StringResource(R.string.last_message_replied)
)

is WithUser.TeamMemberRemoved -> UILastMessageContent.None // TODO
is WithUser.TeamMemberRemoved -> UILastMessageContent.None
is WithUser.Text -> UILastMessageContent.SenderWithMessage(
sender = userUIText,
message = (content as WithUser.Text).messageBody.let { UIText.DynamicString(it) },
Expand Down Expand Up @@ -319,12 +327,16 @@ fun MessagePreview.uiLastMessageContent(): UILastMessageContent {
MessagePreviewContent.CryptoSessionReset -> UILastMessageContent.None
MessagePreviewContent.VerificationChanged.VerifiedMls ->
UILastMessageContent.VerificationChanged(R.string.last_message_verified_conversation_mls)

MessagePreviewContent.VerificationChanged.VerifiedProteus ->
UILastMessageContent.VerificationChanged(R.string.last_message_verified_conversation_proteus)

MessagePreviewContent.VerificationChanged.DegradedMls ->
UILastMessageContent.VerificationChanged(R.string.last_message_conversations_verification_degraded_mls)

MessagePreviewContent.VerificationChanged.DegradedProteus ->
UILastMessageContent.VerificationChanged(R.string.last_message_conversations_verification_degraded_proteus)

Unknown -> UILastMessageContent.None
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class SystemMessageContentMapper @Inject constructor(

private fun mapTeamMemberRemovedMessage(
content: MessageContent.TeamMemberRemoved
): UIMessageContent.SystemMessage = UIMessageContent.SystemMessage.TeamMemberRemoved(content)
): UIMessageContent.SystemMessage = UIMessageContent.SystemMessage.TeamMemberRemoved_Legacy(content)

private fun mapConversationRenamedMessage(
senderUserId: UserId,
Expand Down Expand Up @@ -242,6 +242,11 @@ class SystemMessageContentMapper @Inject constructor(
is MemberChange.FederationRemoved -> UIMessageContent.SystemMessage.FederationMemberRemoved(
memberNames = memberNameList
)

is MemberChange.RemovedFromTeam -> UIMessageContent.SystemMessage.TeamMemberRemoved(
author = authorName,
memberNames = memberNameList
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.CustomTabsHelper
import com.wire.android.util.ui.LocalizedStringResource
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.android.util.ui.UIText
import com.wire.android.util.ui.markdownBold
Expand Down Expand Up @@ -126,16 +127,16 @@ fun SystemMessageItem(
contentAlignment = Alignment.TopEnd
) {
if (message.messageContent.iconResId != null) {
Image(
painter = painterResource(id = message.messageContent.iconResId),
contentDescription = null,
colorFilter = getColorFilter(message.messageContent),
modifier = Modifier.size(
if (message.messageContent.isSmallIcon) dimensions().systemMessageIconSize
else dimensions().systemMessageIconLargeSize
),
contentScale = ContentScale.Crop
)
Image(
painter = painterResource(id = message.messageContent.iconResId),
contentDescription = null,
colorFilter = getColorFilter(message.messageContent),
modifier = Modifier.size(
if (message.messageContent.isSmallIcon) dimensions().systemMessageIconSize
else dimensions().systemMessageIconLargeSize
),
contentScale = ContentScale.Crop
)
}
}
Spacer(Modifier.width(dimensions().messageItemHorizontalPadding - fullAvatarOuterPadding))
Expand Down Expand Up @@ -187,7 +188,7 @@ fun SystemMessageItem(
modifier = Modifier.defaultMinSize(minHeight = dimensions().spacing20x),
text = fullAnnotatedString,
onClick = { offset ->
fullAnnotatedString.getStringAnnotations(TAG_LEARN_MORE, offset, offset,)
fullAnnotatedString.getStringAnnotations(TAG_LEARN_MORE, offset, offset)
.firstOrNull()?.let { result -> CustomTabsHelper.launchUrl(context, result.item) }
},
style = MaterialTheme.wireTypography.body02,
Expand Down Expand Up @@ -256,7 +257,7 @@ private fun getColorFilter(message: SystemMessage): ColorFilter? {
is SystemMessage.MemberRemoved,
is SystemMessage.CryptoSessionReset,
is SystemMessage.RenamedConversation,
is SystemMessage.TeamMemberRemoved,
is SystemMessage.TeamMemberRemoved_Legacy,
is SystemMessage.ConversationReceiptModeChanged,
is SystemMessage.HistoryLost,
is SystemMessage.HistoryLostProtocolChanged,
Expand All @@ -269,6 +270,7 @@ private fun getColorFilter(message: SystemMessage): ColorFilter? {
is SystemMessage.FederationMemberRemoved,
is SystemMessage.FederationStopped,
is SystemMessage.ConversationMessageCreatedUnverifiedWarning,
is SystemMessage.TeamMemberRemoved,
is SystemMessage.MLSWrongEpochWarning -> ColorFilter.tint(colorsScheme().onBackground)
}
}
Expand Down Expand Up @@ -548,7 +550,7 @@ private val SystemMessage.expandable
is SystemMessage.MemberLeft -> false
is SystemMessage.MissedCall -> false
is SystemMessage.RenamedConversation -> false
is SystemMessage.TeamMemberRemoved -> false
is SystemMessage.TeamMemberRemoved_Legacy -> false
is SystemMessage.CryptoSessionReset -> false
is SystemMessage.NewConversationReceiptMode -> false
is SystemMessage.ConversationReceiptModeChanged -> false
Expand All @@ -567,6 +569,7 @@ private val SystemMessage.expandable
is SystemMessage.FederationStopped -> false
is SystemMessage.ConversationMessageCreatedUnverifiedWarning -> false
is SystemMessage.LegalHold -> false
is SystemMessage.TeamMemberRemoved -> this.memberNames.size > EXPANDABLE_THRESHOLD
}

private fun List<String>.toUserNamesListMarkdownString(res: Resources): String = when {
Expand Down Expand Up @@ -594,7 +597,7 @@ private fun List<UIText>.limitUserNamesList(
.plus(res.getQuantityString(quantityString, moreCount, moreCount))
}

@Suppress("LongParameterList", "SpreadOperator", "ComplexMethod")
@Suppress("LongParameterList", "SpreadOperator", "ComplexMethod", "LongMethod")
fun SystemMessage.annotatedString(
res: Resources,
expanded: Boolean,
Expand All @@ -618,6 +621,11 @@ fun SystemMessage.annotatedString(
memberNames.limitUserNamesList(res, expanded).toUserNamesListMarkdownString(res)
)

is SystemMessage.TeamMemberRemoved -> arrayOf(
author.asString(res).markdownBold(),
memberNames.limitUserNamesList(res, expanded).toUserNamesListMarkdownString(res)
)

is SystemMessage.FederationMemberRemoved ->
arrayOf(
memberNames.limitUserNamesList(res, expanded).toUserNamesListMarkdownString(res)
Expand All @@ -627,14 +635,14 @@ fun SystemMessage.annotatedString(
is SystemMessage.MemberLeft -> arrayOf(author.asString(res).markdownBold())
is SystemMessage.MissedCall -> arrayOf(author.asString(res).markdownBold())
is SystemMessage.RenamedConversation -> arrayOf(author.asString(res).markdownBold(), content.conversationName.markdownBold())
is SystemMessage.TeamMemberRemoved -> arrayOf(content.userName.markdownBold())
is SystemMessage.CryptoSessionReset -> arrayOf(author.asString(res).markdownBold())
is SystemMessage.NewConversationReceiptMode -> arrayOf(receiptMode.asString(res).markdownBold())
is SystemMessage.ConversationReceiptModeChanged -> arrayOf(
author.asString(res).markdownBold(),
receiptMode.asString(res).markdownBold()
)

is SystemMessage.TeamMemberRemoved_Legacy -> arrayOf(content.userName)
is SystemMessage.Knock -> arrayOf(author.asString(res).markdownBold())
is SystemMessage.HistoryLost -> arrayOf()
is SystemMessage.MLSWrongEpochWarning -> arrayOf()
Expand Down Expand Up @@ -664,7 +672,19 @@ fun SystemMessage.annotatedString(
arrayOf(memberNames.limitUserNamesList(res, true).toUserNamesListMarkdownString(res))
} ?: arrayOf()
}
val markdownString = res.getString(stringResId, *markdownArgs)
val markdownString = when (stringResId) {
is LocalizedStringResource.PluralResource -> res.getQuantityString(
(stringResId as LocalizedStringResource.PluralResource).id,
(stringResId as LocalizedStringResource.PluralResource).quantity,
*markdownArgs
)

is LocalizedStringResource.StringResource -> res.getString(
(stringResId as LocalizedStringResource.StringResource).id,
*markdownArgs
)
}

return markdownText(markdownString, normalStyle, boldStyle, normalColor, boldColor, errorColor, isErrorString)
}

Expand Down Expand Up @@ -699,7 +719,18 @@ private fun SystemMessage.MemberFailedToAdd.toFailedToAddMarkdownText(
if (isMultipleUsersFailure) failedToAddAnnotatedText.append("\n\n")
failedToAddAnnotatedText.append(
markdownText(
res.getString(stringResId, memberNames.limitUserNamesList(res, true).toUserNamesListMarkdownString(res)),
when (stringResId) {
is LocalizedStringResource.PluralResource -> res.getQuantityString(
stringResId.id,
stringResId.quantity,
stringResId.formatArgs
)

is LocalizedStringResource.StringResource -> res.getString(
stringResId.id,
memberNames.limitUserNamesList(res, true).toUserNamesListMarkdownString(res)
)
},
normalStyle,
boldStyle,
normalColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.wire.android.ui.home.conversations.model

import android.content.res.Resources
import androidx.annotation.DrawableRes
import androidx.annotation.PluralsRes
import androidx.annotation.StringRes
import androidx.compose.runtime.Stable
import com.wire.android.R
Expand All @@ -30,6 +31,7 @@ import com.wire.android.model.UserAvatarData
import com.wire.android.ui.home.conversationslist.model.Membership
import com.wire.android.ui.home.messagecomposer.SelfDeletionDuration
import com.wire.android.util.Copyable
import com.wire.android.util.ui.LocalizedStringResource
import com.wire.android.util.ui.UIText
import com.wire.android.util.uiMessageDateTime
import com.wire.kalium.logic.data.conversation.ClientId
Expand Down Expand Up @@ -279,11 +281,32 @@ sealed class UIMessageContent {

sealed class SystemMessage(
@DrawableRes val iconResId: Int?,
@StringRes open val stringResId: Int,
open val stringResId: LocalizedStringResource,
@StringRes val learnMoreResId: Int? = null,
val isSmallIcon: Boolean = true,
) : UIMessageContent() {

constructor(
@DrawableRes iconResId: Int?,
@StringRes stringResId: Int,
isSmallIcon: Boolean = true,
@StringRes learnMoreResId: Int? = null
) : this(iconResId, LocalizedStringResource.StringResource(stringResId), learnMoreResId, isSmallIcon)

constructor(
@DrawableRes iconResId: Int?,
@PluralsRes stringResId: Int,
quantity: Int,
formatArgs: List<UIText>,
isSmallIcon: Boolean = true,
@StringRes learnMoreResId: Int? = null
) : this(
iconResId,
LocalizedStringResource.PluralResource(stringResId, quantity, formatArgs.toTypedArray()),
learnMoreResId,
isSmallIcon
)

data class Knock(val author: UIText, val isSelfTriggered: Boolean) : SystemMessage(
R.drawable.ic_ping,
if (isSelfTriggered) R.string.label_system_message_self_user_knock else R.string.label_system_message_other_user_knock
Expand Down Expand Up @@ -319,6 +342,16 @@ sealed class UIMessageContent {
if (isSelfTriggered) R.string.label_system_message_removed_by_self else R.string.label_system_message_removed_by_other
)

data class TeamMemberRemoved(
val author: UIText,
val memberNames: List<UIText>,
) : SystemMessage(
R.drawable.ic_minus,
R.plurals.label_system_message_team_member_left,
quantity = memberNames.size,
formatArgs = memberNames
)

data class MemberLeft(
val author: UIText,
val isSelfTriggered: Boolean = false
Expand Down Expand Up @@ -356,7 +389,7 @@ sealed class UIMessageContent {

sealed class MissedCall(
open val author: UIText,
@StringRes override val stringResId: Int
@StringRes stringResId: Int
) : SystemMessage(R.drawable.ic_call_end, stringResId) {

data class YouCalled(override val author: UIText) : MissedCall(author, R.string.label_system_message_you_called)
Expand All @@ -366,8 +399,16 @@ sealed class UIMessageContent {
data class RenamedConversation(val author: UIText, val content: MessageContent.ConversationRenamed) :
SystemMessage(R.drawable.ic_edit, R.string.label_system_message_renamed_the_conversation)

data class TeamMemberRemoved(val content: MessageContent.TeamMemberRemoved) :
SystemMessage(R.drawable.ic_minus, R.string.label_system_message_team_member_left)
@Deprecated("Use TeamMemberRemoved")
@Suppress("ClassNaming")
data class TeamMemberRemoved_Legacy(val content: MessageContent.TeamMemberRemoved) :
SystemMessage(
R.drawable.ic_minus,
R.plurals.label_system_message_team_member_left,
quantity = 0,
formatArgs = emptyList(),
true
)

data class CryptoSessionReset(val author: UIText) :
SystemMessage(R.drawable.ic_info, R.string.label_system_message_session_reset)
Expand Down Expand Up @@ -493,18 +534,25 @@ sealed class UIMessageContent {
)

sealed class LegalHold(
@StringRes stringResId: Int,
stringResId: LocalizedStringResource.StringResource,
@StringRes learnMoreResId: Int? = null,
open val memberNames: List<UIText>? = null,
) : SystemMessage(R.drawable.ic_legal_hold, stringResId, learnMoreResId) {

sealed class Enabled(@StringRes override val stringResId: Int) : LegalHold(stringResId, R.string.url_legal_hold_learn_more) {
sealed class Enabled(override val stringResId: LocalizedStringResource.StringResource) :
LegalHold(stringResId, R.string.url_legal_hold_learn_more) {

constructor(@StringRes stringResId: Int) : this(LocalizedStringResource.StringResource(stringResId))

data object Self : Enabled(R.string.legal_hold_system_message_enabled_self)
data class Others(override val memberNames: List<UIText>) : Enabled(R.string.legal_hold_system_message_enabled_others)
data object Conversation : Enabled(R.string.legal_hold_system_message_enabled_conversation)
}

sealed class Disabled(@StringRes override val stringResId: Int) : LegalHold(stringResId, null) {
sealed class Disabled(override val stringResId: LocalizedStringResource.StringResource) : LegalHold(stringResId, null) {

constructor(@StringRes stringResId: Int) : this(LocalizedStringResource.StringResource(stringResId))

data object Self : Disabled(R.string.legal_hold_system_message_disabled_self)
data class Others(override val memberNames: List<UIText>) : Disabled(R.string.legal_hold_system_message_disabled_others)
data object Conversation : Disabled(R.string.legal_hold_system_message_disabled_conversation)
Expand Down
Loading

0 comments on commit aaa2d87

Please sign in to comment.