Enhance edit to support new threads fallback

This commit is contained in:
ariskotsomitopoulos 2022-01-25 14:12:13 +02:00
parent fe88e81d4a
commit b1b27bdd0e
4 changed files with 22 additions and 5 deletions

View File

@ -29,6 +29,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent
import org.matrix.android.sdk.api.session.room.model.message.MessageStickerContent
import org.matrix.android.sdk.api.session.room.model.message.MessageType
import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent
import org.matrix.android.sdk.api.session.room.model.relation.shouldRenderInThread
import org.matrix.android.sdk.api.session.room.send.SendState
import org.matrix.android.sdk.api.session.threads.ThreadDetails
import org.matrix.android.sdk.api.util.ContentUtils
@ -376,7 +377,7 @@ fun Event.isReply(): Boolean {
}
fun Event.isReplyRenderedInThread(): Boolean {
return isReply() && getRelationContent()?.inReplyTo?.renderIn?.contains("m.thread") == true
return isReply() && getRelationContent()?.inReplyTo?.shouldRenderInThread() == true
}
fun Event.isThread(): Boolean = getRelationContentForType(RelationType.IO_THREAD)?.eventId != null

View File

@ -24,3 +24,5 @@ data class ReplyToContent(
@Json(name = "event_id") val eventId: String? = null,
@Json(name = "render_in") val renderIn: List<String>? = null
)
fun ReplyToContent.shouldRenderInThread(): Boolean = renderIn?.contains("m.thread") == true

View File

@ -64,7 +64,7 @@ import javax.inject.Inject
internal class EventRelationsAggregationProcessor @Inject constructor(
@UserId private val userId: String,
private val stateEventDataSource: StateEventDataSource
) : EventInsertLiveProcessor {
) : EventInsertLiveProcessor {
private val allowedTypes = listOf(
EventType.MESSAGE,

View File

@ -51,6 +51,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomAvatarContent
import org.matrix.android.sdk.api.session.room.model.RoomEncryptionAlgorithm
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
import org.matrix.android.sdk.api.session.room.model.message.MessageType
import org.matrix.android.sdk.api.session.room.model.relation.shouldRenderInThread
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
import org.matrix.android.sdk.api.session.room.send.UserDraft
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
@ -185,7 +186,7 @@ class MessageComposerViewModel @AssistedInject constructor(
is SendMode.Regular -> {
when (val slashCommandResult = CommandParser.parseSlashCommand(
textMessage = action.text,
isInThreadTimeline = state.isInThreadTimeline())) {
isInThreadTimeline = state.isInThreadTimeline())) {
is ParsedCommand.ErrorNotACommand -> {
// Send the text message to the room
if (state.rootThreadEventId != null) {
@ -259,7 +260,7 @@ class MessageComposerViewModel @AssistedInject constructor(
is ParsedCommand.UnignoreUser -> {
handleUnignoreSlashCommand(slashCommandResult)
}
is ParsedCommand.RemoveUser -> {
is ParsedCommand.RemoveUser -> {
handleRemoveSlashCommand(slashCommandResult)
}
is ParsedCommand.JoinRoom -> {
@ -449,7 +450,20 @@ class MessageComposerViewModel @AssistedInject constructor(
}
is SendMode.Edit -> {
// is original event a reply?
val inReplyTo = state.sendMode.timelineEvent.getRelationContent()?.inReplyTo?.eventId
val relationContent = state.sendMode.timelineEvent.getRelationContent()
val inReplyTo = if (state.rootThreadEventId != null) {
if (relationContent?.inReplyTo?.shouldRenderInThread() == true) {
// Reply within a thread event
relationContent.inReplyTo?.eventId
} else {
// Normal thread event
null
}
} else {
// Normal event
relationContent?.inReplyTo?.eventId
}
if (inReplyTo != null) {
// TODO check if same content?
room.getTimeLineEvent(inReplyTo)?.let {