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

feat: support new reason value on conversation leave event #2536

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@

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

Check warning on line 183 in app/src/main/kotlin/com/wire/android/mapper/SystemMessageContentMapper.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/mapper/SystemMessageContentMapper.kt#L183

Added line #L183 was not covered by tests

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

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

Check warning on line 248 in app/src/main/kotlin/com/wire/android/mapper/SystemMessageContentMapper.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/mapper/SystemMessageContentMapper.kt#L246-L248

Added lines #L246 - L248 were not covered by tests
)
}
}

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 @@

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.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 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(

Check warning on line 296 in app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt#L296

Added line #L296 was not covered by tests
@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
)

Check warning on line 308 in app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt#L301-L308

Added lines #L301 - L308 were not covered by tests

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 @@
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

Check warning on line 352 in app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt#L345-L352

Added lines #L345 - L352 were not covered by tests
)

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

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 @@
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

Check warning on line 410 in app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt#L404-L410

Added lines #L404 - L410 were not covered by tests
)

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 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) {

Check warning on line 543 in app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt#L542-L543

Added lines #L542 - L543 were not covered by tests

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

Check warning on line 545 in app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt#L545

Added line #L545 was not covered by tests

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) {

Check warning on line 552 in app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt#L552

Added line #L552 was not covered by tests

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

Check warning on line 554 in app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt#L554

Added line #L554 was not covered by tests

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