Add fallback support rendering proposed in MSC3676

This commit is contained in:
ariskotsomitopoulos 2022-03-14 16:04:08 +01:00
parent d894d8598c
commit d7c486c55e
5 changed files with 23 additions and 5 deletions

View File

@ -26,8 +26,8 @@ interface RelationContent {
val option: Int?
/**
* This flag indicates that the message should be displayed in the main
* timeline as a reply if needed
* This flag indicates that the message should be rendered as a reply
* fallback, when isFallingBack = false
*/
val isFallingBack: Boolean?
}

View File

@ -355,6 +355,7 @@ internal class LocalEchoEventFactory @Inject constructor(
RelationDefaultContent(
type = RelationType.THREAD,
eventId = it,
isFallingBack = true,
inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it))
)
}
@ -398,6 +399,7 @@ internal class LocalEchoEventFactory @Inject constructor(
RelationDefaultContent(
type = RelationType.THREAD,
eventId = it,
isFallingBack = true,
inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it))
)
}
@ -428,6 +430,7 @@ internal class LocalEchoEventFactory @Inject constructor(
RelationDefaultContent(
type = RelationType.THREAD,
eventId = it,
isFallingBack = true,
inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it))
)
}
@ -448,6 +451,7 @@ internal class LocalEchoEventFactory @Inject constructor(
RelationDefaultContent(
type = RelationType.THREAD,
eventId = it,
isFallingBack = true,
inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it))
)
}

View File

@ -162,7 +162,7 @@ internal class ThreadsAwarenessHandler @Inject constructor(
eventEntity: EventEntity? = null): String? {
event ?: return null
roomId ?: return null
if (lightweightSettingsStorage.areThreadMessagesEnabled()) return null
if (lightweightSettingsStorage.areThreadMessagesEnabled() && !isReplyEvent(event)) return null
handleRootThreadEventsIfNeeded(realm, roomId, eventEntity, event)
if (!isThreadEvent(event)) return null
val eventPayload = if (!event.isEncrypted()) {
@ -387,6 +387,16 @@ internal class ThreadsAwarenessHandler @Inject constructor(
private fun getPreviousEventOrRoot(event: Event): String? =
event.content.toModel<MessageRelationContent>()?.relatesTo?.inReplyTo?.eventId
/**
* Returns if we should html inject the current event.
*/
private fun isReplyEvent(event: Event): Boolean {
return isThreadEvent(event) && !isFallingBack(event) && getPreviousEventOrRoot(event) != null
}
private fun isFallingBack(event: Event): Boolean =
event.content.toModel<MessageRelationContent>()?.relatesTo?.isFallingBack == true
@Suppress("UNCHECKED_CAST")
private fun getValueFromPayload(payload: JsonDict?, key: String): String? {
val content = payload?.get("content") as? JsonDict

View File

@ -506,7 +506,10 @@ class TimelineViewModel @AssistedInject constructor(
private fun handleSendSticker(action: RoomDetailAction.SendSticker) {
val content = initialState.rootThreadEventId?.let {
action.stickerContent.copy(relatesTo = RelationDefaultContent(RelationType.THREAD, it))
action.stickerContent.copy(relatesTo = RelationDefaultContent(
type = RelationType.THREAD,
isFallingBack = true,
eventId = it))
} ?: action.stickerContent
room.sendEvent(EventType.STICKER, content.toContent())

View File

@ -40,7 +40,8 @@
android:id="@+id/additionalTopSpace"
android:layout_height="12dp"
android:layout_width="0dp"
android:layout_toEndOf="@id/messageStartGuideline" />
android:layout_toEndOf="@id/messageStartGuideline"
tools:ignore="MissingConstraints" />
<TextView
android:id="@+id/messageTimeView"