Add fallback support rendering proposed in MSC3676
This commit is contained in:
parent
d894d8598c
commit
d7c486c55e
|
@ -26,8 +26,8 @@ interface RelationContent {
|
||||||
val option: Int?
|
val option: Int?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This flag indicates that the message should be displayed in the main
|
* This flag indicates that the message should be rendered as a reply
|
||||||
* timeline as a reply if needed
|
* fallback, when isFallingBack = false
|
||||||
*/
|
*/
|
||||||
val isFallingBack: Boolean?
|
val isFallingBack: Boolean?
|
||||||
}
|
}
|
||||||
|
|
|
@ -355,6 +355,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
RelationDefaultContent(
|
RelationDefaultContent(
|
||||||
type = RelationType.THREAD,
|
type = RelationType.THREAD,
|
||||||
eventId = it,
|
eventId = it,
|
||||||
|
isFallingBack = true,
|
||||||
inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it))
|
inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -398,6 +399,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
RelationDefaultContent(
|
RelationDefaultContent(
|
||||||
type = RelationType.THREAD,
|
type = RelationType.THREAD,
|
||||||
eventId = it,
|
eventId = it,
|
||||||
|
isFallingBack = true,
|
||||||
inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it))
|
inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -428,6 +430,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
RelationDefaultContent(
|
RelationDefaultContent(
|
||||||
type = RelationType.THREAD,
|
type = RelationType.THREAD,
|
||||||
eventId = it,
|
eventId = it,
|
||||||
|
isFallingBack = true,
|
||||||
inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it))
|
inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -448,6 +451,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
RelationDefaultContent(
|
RelationDefaultContent(
|
||||||
type = RelationType.THREAD,
|
type = RelationType.THREAD,
|
||||||
eventId = it,
|
eventId = it,
|
||||||
|
isFallingBack = true,
|
||||||
inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it))
|
inReplyTo = ReplyToContent(eventId = localEchoRepository.getLatestThreadEvent(it))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ internal class ThreadsAwarenessHandler @Inject constructor(
|
||||||
eventEntity: EventEntity? = null): String? {
|
eventEntity: EventEntity? = null): String? {
|
||||||
event ?: return null
|
event ?: return null
|
||||||
roomId ?: return null
|
roomId ?: return null
|
||||||
if (lightweightSettingsStorage.areThreadMessagesEnabled()) return null
|
if (lightweightSettingsStorage.areThreadMessagesEnabled() && !isReplyEvent(event)) return null
|
||||||
handleRootThreadEventsIfNeeded(realm, roomId, eventEntity, event)
|
handleRootThreadEventsIfNeeded(realm, roomId, eventEntity, event)
|
||||||
if (!isThreadEvent(event)) return null
|
if (!isThreadEvent(event)) return null
|
||||||
val eventPayload = if (!event.isEncrypted()) {
|
val eventPayload = if (!event.isEncrypted()) {
|
||||||
|
@ -387,6 +387,16 @@ internal class ThreadsAwarenessHandler @Inject constructor(
|
||||||
private fun getPreviousEventOrRoot(event: Event): String? =
|
private fun getPreviousEventOrRoot(event: Event): String? =
|
||||||
event.content.toModel<MessageRelationContent>()?.relatesTo?.inReplyTo?.eventId
|
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")
|
@Suppress("UNCHECKED_CAST")
|
||||||
private fun getValueFromPayload(payload: JsonDict?, key: String): String? {
|
private fun getValueFromPayload(payload: JsonDict?, key: String): String? {
|
||||||
val content = payload?.get("content") as? JsonDict
|
val content = payload?.get("content") as? JsonDict
|
||||||
|
|
|
@ -506,7 +506,10 @@ class TimelineViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
private fun handleSendSticker(action: RoomDetailAction.SendSticker) {
|
private fun handleSendSticker(action: RoomDetailAction.SendSticker) {
|
||||||
val content = initialState.rootThreadEventId?.let {
|
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
|
} ?: action.stickerContent
|
||||||
|
|
||||||
room.sendEvent(EventType.STICKER, content.toContent())
|
room.sendEvent(EventType.STICKER, content.toContent())
|
||||||
|
|
|
@ -40,7 +40,8 @@
|
||||||
android:id="@+id/additionalTopSpace"
|
android:id="@+id/additionalTopSpace"
|
||||||
android:layout_height="12dp"
|
android:layout_height="12dp"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_toEndOf="@id/messageStartGuideline" />
|
android:layout_toEndOf="@id/messageStartGuideline"
|
||||||
|
tools:ignore="MissingConstraints" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/messageTimeView"
|
android:id="@+id/messageTimeView"
|
||||||
|
|
Loading…
Reference in New Issue