Properly format lastMessage when it belongs to a poll. (#1387)
Takes care of properly formatting a room's last message when it belongs to a poll. NB: Polls still aren't exposed as a room's `last_message` from the rust SDK, so this code won't actually run yet. This will happen after integrating rust SDK version 0.1.57 which includes: https://github.com/matrix-org/matrix-rust-sdk/pull/2580
This commit is contained in:
parent
0c10432f9b
commit
e4c78a2489
4 changed files with 50 additions and 3 deletions
|
|
@ -95,7 +95,10 @@ class DefaultRoomLastMessageFormatter @Inject constructor(
|
|||
is StateContent -> {
|
||||
stateContentFormatter.format(content, senderDisplayName, isOutgoing, RenderingMode.RoomList)
|
||||
}
|
||||
is PollContent, // TODO Polls: handle last message
|
||||
is PollContent -> {
|
||||
val message = sp.getString(CommonStrings.common_poll_summary, content.question)
|
||||
prefixIfNeeded(message, senderDisplayName, isDmRoom)
|
||||
}
|
||||
is FailedToParseMessageLikeContent, is FailedToParseStateContent, is UnknownContent -> {
|
||||
prefixIfNeeded(sp.getString(CommonStrings.common_unsupported_event), senderDisplayName, isDmRoom)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ import io.element.android.libraries.matrix.api.timeline.item.event.UnknownMessag
|
|||
import io.element.android.libraries.matrix.api.timeline.item.event.VideoMessageType
|
||||
import io.element.android.libraries.matrix.test.A_USER_ID
|
||||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||
import io.element.android.libraries.matrix.test.room.aPollContent
|
||||
import io.element.android.libraries.matrix.test.room.aProfileChangeMessageContent
|
||||
import io.element.android.libraries.matrix.test.room.anEventTimelineItem
|
||||
import io.element.android.services.toolbox.impl.strings.AndroidStringProvider
|
||||
|
|
@ -58,6 +59,7 @@ import org.robolectric.RobolectricTestRunner
|
|||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@Suppress("LargeClass")
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class DefaultRoomLastMessageFormatterTests {
|
||||
|
||||
|
|
@ -153,7 +155,7 @@ class DefaultRoomLastMessageFormatterTests {
|
|||
fun `Message contents`() {
|
||||
val body = "Shared body"
|
||||
fun createMessageContent(type: MessageType): MessageContent {
|
||||
return MessageContent(body, null, false, false,type)
|
||||
return MessageContent(body, null, false, false, type)
|
||||
}
|
||||
|
||||
val sharedContentMessagesTypes = arrayOf(
|
||||
|
|
@ -764,6 +766,34 @@ class DefaultRoomLastMessageFormatterTests {
|
|||
|
||||
// endregion
|
||||
|
||||
// region Polls
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "en")
|
||||
fun `Computes last message for poll in DM`() {
|
||||
val pollContent = aPollContent()
|
||||
|
||||
val mineContentEvent = createRoomEvent(sentByYou = true, senderDisplayName = "Alice", content = pollContent)
|
||||
Truth.assertThat(formatter.format(mineContentEvent, true)).isEqualTo("Poll: Do you like polls?")
|
||||
|
||||
val contentEvent = createRoomEvent(sentByYou = false, senderDisplayName = "Bob", content = pollContent)
|
||||
Truth.assertThat(formatter.format(contentEvent, true)).isEqualTo("Poll: Do you like polls?")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "en")
|
||||
fun `Computes last message for poll in room`() {
|
||||
val pollContent = aPollContent()
|
||||
|
||||
val mineContentEvent = createRoomEvent(sentByYou = true, senderDisplayName = "Alice", content = pollContent)
|
||||
Truth.assertThat(formatter.format(mineContentEvent, false).toString()).isEqualTo("Alice: Poll: Do you like polls?")
|
||||
|
||||
val contentEvent = createRoomEvent(sentByYou = false, senderDisplayName = "Bob", content = pollContent)
|
||||
Truth.assertThat(formatter.format(contentEvent, false).toString()).isEqualTo("Bob: Poll: Do you like polls?")
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
private fun createRoomEvent(sentByYou: Boolean, senderDisplayName: String?, content: EventContent): EventTimelineItem {
|
||||
val sender = if (sentByYou) A_USER_ID else UserId("@someone_else:domain")
|
||||
val profile = ProfileTimelineDetails.Ready(senderDisplayName, false, null)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue