Skip to content
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.
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 @@ -93,7 +93,7 @@ internal fun DialogScreenDialogs(
editing = state.editing != null,
editingBody = state.editing?.text.orEmpty(),
replyBody = state.replyTo?.let {
it.text ?: stringResource(R.string.dialog_media_photo)
it.text ?: replyMediaFallbackLabel(it.mediaKind)
},
pendingAttach = state.pendingAttach,
hasFailed = state.messages.any { it.failed },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,18 @@ internal fun replyQuoteAuthor(
else -> null
}

internal fun replyMediaLabelRes(kind: String?): Int = when (kind) {
"photo" -> R.string.dialog_reply_photo
"video" -> R.string.dialog_reply_video
"sticker", "sticker_animated" -> R.string.dialog_reply_sticker
"gif" -> R.string.dialog_reply_gif
"document" -> R.string.dialog_reply_document
"audio" -> R.string.dialog_media_audio
"voice" -> R.string.dialog_media_voice
"video_note" -> R.string.dialog_media_video_note
else -> R.string.dialog_replying
}

@Composable
private fun replyMediaFallbackLabel(kind: String?): String = stringResource(
when (kind) {
"photo" -> R.string.dialog_reply_photo
"video" -> R.string.dialog_reply_video
"sticker", "sticker_animated" -> R.string.dialog_reply_sticker
"gif" -> R.string.dialog_reply_gif
"document" -> R.string.dialog_reply_document
else -> R.string.dialog_replying
},
)
internal fun replyMediaFallbackLabel(kind: String?): String =
stringResource(replyMediaLabelRes(kind))
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.monogram.feature.dialog.ui

import org.junit.Assert.assertEquals
import org.junit.Test
import org.monogram.feature.dialog.R

class MessageReplyQuoteTest {
@Test
fun mediaKindsThatHadNoLabelMapToTheirOwnLabel() {
assertEquals(R.string.dialog_media_audio, replyMediaLabelRes("audio"))
assertEquals(R.string.dialog_media_voice, replyMediaLabelRes("voice"))
assertEquals(R.string.dialog_media_video_note, replyMediaLabelRes("video_note"))
}

@Test
fun kindsThatAlreadyHadALabelKeepIt() {
assertEquals(R.string.dialog_reply_photo, replyMediaLabelRes("photo"))
assertEquals(R.string.dialog_reply_video, replyMediaLabelRes("video"))
assertEquals(R.string.dialog_reply_sticker, replyMediaLabelRes("sticker"))
assertEquals(R.string.dialog_reply_sticker, replyMediaLabelRes("sticker_animated"))
assertEquals(R.string.dialog_reply_gif, replyMediaLabelRes("gif"))
assertEquals(R.string.dialog_reply_document, replyMediaLabelRes("document"))
}

@Test
fun unknownAndMissingKindsFallBackToTheGenericLabel() {
assertEquals(R.string.dialog_replying, replyMediaLabelRes(null))
assertEquals(R.string.dialog_replying, replyMediaLabelRes(""))
assertEquals(R.string.dialog_replying, replyMediaLabelRes("contact"))
}
}