Skip to content
Open
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 @@ -105,56 +105,55 @@
else -> UIText.StringResource(R.string.username_unavailable_label)
}

private fun assetMessageResId(

Check failure on line 108 in app/src/main/kotlin/com/wire/android/mapper/MessagePreviewContentMapper.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 30 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=wireapp_wire-android&issues=AZq7JxOgC5wtdmLvHZuF&open=AZq7JxOgC5wtdmLvHZuF&pullRequest=4440
assetType: AssetType,
isSelfMessage: Boolean,
count: Int
): UIText {
return if (count > 1) {
val resId = when (assetType) {
AssetType.AUDIO -> if (isSelfMessage) R.string.last_message_self_user_shared_multiple_audio
else R.string.last_message_other_user_shared_multiple_audio

AssetType.IMAGE -> if (isSelfMessage) R.string.last_message_self_user_shared_multiple_image
else R.string.last_message_other_user_shared_multiple_image

AssetType.VIDEO -> if (isSelfMessage) R.string.last_message_self_user_shared_multiple_video
else R.string.last_message_other_user_shared_multiple_video

AssetType.GENERIC_ASSET -> if (isSelfMessage) R.string.last_message_self_user_shared_multiple_asset
else R.string.last_message_other_user_shared_multiple_asset
}
UIText.StringResource(resId, count)
} else {
val resId = when (assetType) {
AssetType.AUDIO -> if (isSelfMessage) R.string.last_message_self_user_shared_audio
else R.string.last_message_other_user_shared_audio

AssetType.IMAGE -> if (isSelfMessage) R.string.last_message_self_user_shared_image
else R.string.last_message_other_user_shared_image

AssetType.VIDEO -> if (isSelfMessage) R.string.last_message_self_user_shared_video
else R.string.last_message_other_user_shared_video

AssetType.GENERIC_ASSET -> if (isSelfMessage) R.string.last_message_self_user_shared_asset
else R.string.last_message_other_user_shared_asset
}
UIText.StringResource(resId)
}
}

@Suppress("LongMethod", "ComplexMethod", "NestedBlockDepth")
fun MessagePreview.uiLastMessageContent(): UILastMessageContent {
return when (content) {
is WithUser -> {
val userContent = (content as WithUser)
val userUIText = userContent.username.userUiText(isSelfMessage)
when ((userContent)) {
is WithUser.Asset -> when ((content as WithUser.Asset).type) {
AssetType.AUDIO ->
UILastMessageContent.SenderWithMessage(
userUIText,
UIText.StringResource(R.string.last_message_self_user_shared_audio)
)

AssetType.IMAGE ->
UILastMessageContent.SenderWithMessage(
userUIText,
UIText.StringResource(
if (isSelfMessage) {
R.string.last_message_self_user_shared_image
} else {
R.string.last_message_other_user_shared_image
}
)
)

AssetType.VIDEO ->
UILastMessageContent.SenderWithMessage(
userUIText,
UIText.StringResource(
if (isSelfMessage) {
R.string.last_message_self_user_shared_video
} else {
R.string.last_message_other_user_shared_video
}
)
)

AssetType.GENERIC_ASSET ->
UILastMessageContent.SenderWithMessage(
userUIText,
UIText.StringResource(
if (isSelfMessage) {
R.string.last_message_self_user_shared_asset
} else {
R.string.last_message_other_user_shared_asset
}
)
)
}
is WithUser.Asset -> UILastMessageContent.SenderWithMessage(
sender = userUIText,
message = assetMessageResId((content as WithUser.Asset).type, isSelfMessage, (content as WithUser.Asset).count)
)

is WithUser.ConversationNameChange -> UILastMessageContent.SenderWithMessage(
userUIText,
Expand Down Expand Up @@ -368,12 +367,33 @@
MessagePreviewContent.VerificationChanged.DegradedProteus ->
UILastMessageContent.VerificationChanged(R.string.last_message_conversations_verification_degraded_proteus)

is MessagePreviewContent.Draft -> UILastMessageContent.SenderWithMessage(
UIText.StringResource(R.string.label_draft),
(content as MessagePreviewContent.Draft).message.toUIText(),
separator = ":${MarkdownConstants.NON_BREAKING_SPACE}"
)
is MessagePreviewContent.Draft -> {
with(content as MessagePreviewContent.Draft) {
val messageUiText = if (attachmentsCount > 0) {
val pluralId = attachmentPlural(attachmentType)
UIText.PluralResource(pluralId, attachmentsCount, attachmentsCount)
} else {
message?.toUIText() ?: "".toUIText()
}

UILastMessageContent.SenderWithMessage(
sender = UIText.StringResource(R.string.label_draft),
message = messageUiText,
separator = ":${MarkdownConstants.NON_BREAKING_SPACE}"
)
}
}

Unknown -> UILastMessageContent.None
}
}

private fun attachmentPlural(type: String?): Int =
when {
type == null -> R.plurals.draft_files_count
"image/" in type -> R.plurals.draft_image_count
"video/" in type -> R.plurals.draft_video_count
"audio/" in type -> R.plurals.draft_audio_count
else -> R.plurals.draft_files_count
}

60 changes: 43 additions & 17 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@
<string name="label_and">and</string>
<string name="label_retry">Retry</string>
<string name="label_draft">*Draft*</string>
<plurals name="draft_files_count">
<item quantity="one">1 file</item>
<item quantity="other">%1$d files</item>
</plurals>
<plurals name="draft_image_count">
<item quantity="one">1 image</item>
<item quantity="other">%1$d images</item>
</plurals>
<plurals name="draft_video_count">
<item quantity="one">1 video</item>
<item quantity="other">%1$d videos</item>
</plurals>
<plurals name="draft_audio_count">
<item quantity="one">1 audio</item>
<item quantity="other">%1$d audios</item>
</plurals>

<!-- Content descriptions https://wearezeta.atlassian.net/wiki/spaces/AR/pages/122520039/Code+Style+Guideline#Content-description-strings -->
<string name="content_description_reveal_password">Show password</string>
<string name="content_description_hide_password">Hide password</string>
Expand Down Expand Up @@ -914,28 +931,37 @@
<item quantity="one">1 person was removed from the conversation</item>
<item quantity="other">%1$d people were removed from the conversation</item>
</plurals>
<string name="last_message_self_user_shared_asset">shared a file.</string>
<string name="last_message_other_user_shared_asset">shared a file.</string>
<string name="last_message_self_user_shared_image">shared an image.</string>
<string name="last_message_other_user_shared_image">shared an image.</string>
<string name="last_message_self_user_shared_video">shared a video.</string>
<string name="last_message_other_user_shared_video">shared a video.</string>
<string name="last_message_self_user_shared_audio">shared an audio message.</string>
<string name="last_message_other_user_shared_audio">shared an audio message.</string>
<string name="last_message_self_user_shared_location">shared a location.</string>
<string name="last_message_other_user_shared_location">shared a location.</string>
<string name="last_message_self_user_knock">pinged.</string>
<string name="last_message_other_user_knock">pinged.</string>
<string name="last_message_call">called.</string>
<!-- We are duplicating these strings for translators to provide more accurate translations-->
<string name="last_message_self_user_shared_asset">shared a file</string>
<string name="last_message_other_user_shared_asset">shared a file</string>
<string name="last_message_self_user_shared_multiple_asset">shared %1$s files</string>
<string name="last_message_other_user_shared_multiple_asset">shared %1$s files</string>
<string name="last_message_self_user_shared_image">shared an image</string>
<string name="last_message_other_user_shared_image">shared an image</string>
<string name="last_message_self_user_shared_multiple_image">shared %1$s images</string>
<string name="last_message_other_user_shared_multiple_image">shared %1$s images</string>
<string name="last_message_self_user_shared_video">shared a video</string>
<string name="last_message_other_user_shared_video">shared a video</string>
<string name="last_message_self_user_shared_multiple_video">shared %1$s videos</string>
<string name="last_message_other_user_shared_multiple_video">shared %1$s videos</string>
<string name="last_message_self_user_shared_audio">shared an audio message</string>
<string name="last_message_other_user_shared_audio">shared an audio message</string>
<string name="last_message_self_user_shared_multiple_audio">shared %1$s audio messages</string>
<string name="last_message_other_user_shared_multiple_audio">shared %1$s audio messages</string>
<string name="last_message_self_user_shared_location">shared a location</string>
<string name="last_message_other_user_shared_location">shared a location</string>
<string name="last_message_self_user_knock">pinged</string>
<string name="last_message_other_user_knock">pinged</string>
<string name="last_message_call">called</string>
<string name="last_message_mentioned">mentioned you</string>
<string name="last_message_replied">replied to you</string>
<string name="last_message_other_changed_conversation_name">changed conversation name</string>
<string name="last_message_self_changed_conversation_name">changed conversation name</string>
<string name="last_message_calling">%1$s calling...</string>
<string name="last_message_self_user_joined_conversation">joined the conversation.</string>
<string name="last_message_self_user_left_conversation">left the conversation.</string>
<string name="last_message_other_user_joined_conversation">joined the conversation.</string>
<string name="last_message_other_user_left_conversation">left the conversation.</string>
<string name="last_message_self_user_joined_conversation">joined the conversation</string>
<string name="last_message_self_user_left_conversation">left the conversation</string>
<string name="last_message_other_user_joined_conversation">joined the conversation</string>
<string name="last_message_other_user_left_conversation">left the conversation</string>
<string name="last_message_verified_conversation_proteus">All device fingerprints are verified (Proteus)</string>
<string name="last_message_verified_conversation_mls">All devices are verified (End-to-end Identity)</string>
<string name="last_message_conversations_verification_degraded_mls">Conversation is no longer verified</string>
Expand Down
2 changes: 1 addition & 1 deletion kalium
Submodule kalium updated 106 files