Revert "replyTo are not updated if the original message is edited (#6404)"
This reverts commit 99a906fe9b
.
This commit is contained in:
parent
0fcf7c7079
commit
e9f5208efd
|
@ -1 +0,0 @@
|
||||||
ReplyTo are not updated if the original message is edited
|
|
|
@ -574,13 +574,17 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
return clock.epochMillis()
|
return clock.epochMillis()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createReplyTextContent(
|
/**
|
||||||
|
* Creates a reply to a regular timeline Event or a thread Event if needed.
|
||||||
|
*/
|
||||||
|
fun createReplyTextEvent(
|
||||||
|
roomId: String,
|
||||||
eventReplied: TimelineEvent,
|
eventReplied: TimelineEvent,
|
||||||
replyText: CharSequence,
|
replyText: CharSequence,
|
||||||
autoMarkdown: Boolean,
|
autoMarkdown: Boolean,
|
||||||
rootThreadEventId: String? = null,
|
rootThreadEventId: String? = null,
|
||||||
showInThread: Boolean
|
showInThread: Boolean
|
||||||
): MessageContent? {
|
): Event? {
|
||||||
// Fallbacks and event representation
|
// Fallbacks and event representation
|
||||||
// TODO Add error/warning logs when any of this is null
|
// TODO Add error/warning logs when any of this is null
|
||||||
val permalink = permalinkFactory.createPermalink(eventReplied.root, false) ?: return null
|
val permalink = permalinkFactory.createPermalink(eventReplied.root, false) ?: return null
|
||||||
|
@ -606,7 +610,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
val replyFallback = buildReplyFallback(body, userId, replyText.toString())
|
val replyFallback = buildReplyFallback(body, userId, replyText.toString())
|
||||||
|
|
||||||
val eventId = eventReplied.root.eventId ?: return null
|
val eventId = eventReplied.root.eventId ?: return null
|
||||||
return MessageTextContent(
|
val content = MessageTextContent(
|
||||||
msgType = MessageType.MSGTYPE_TEXT,
|
msgType = MessageType.MSGTYPE_TEXT,
|
||||||
format = MessageFormat.FORMAT_MATRIX_HTML,
|
format = MessageFormat.FORMAT_MATRIX_HTML,
|
||||||
body = replyFallback,
|
body = replyFallback,
|
||||||
|
@ -617,23 +621,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
showInThread = showInThread
|
showInThread = showInThread
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
return createMessageEvent(roomId, content)
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a reply to a regular timeline Event or a thread Event if needed.
|
|
||||||
*/
|
|
||||||
fun createReplyTextEvent(
|
|
||||||
roomId: String,
|
|
||||||
eventReplied: TimelineEvent,
|
|
||||||
replyText: CharSequence,
|
|
||||||
autoMarkdown: Boolean,
|
|
||||||
rootThreadEventId: String? = null,
|
|
||||||
showInThread: Boolean,
|
|
||||||
): Event? {
|
|
||||||
val content = createReplyTextContent(eventReplied, replyText, autoMarkdown, rootThreadEventId, showInThread)
|
|
||||||
return content?.let {
|
|
||||||
createMessageEvent(roomId, it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -694,7 +682,7 @@ internal class LocalEchoEventFactory @Inject constructor(
|
||||||
* In case of an edit of a reply the last content is not
|
* In case of an edit of a reply the last content is not
|
||||||
* himself a reply, but it will contain the fallbacks, so we have to trim them.
|
* himself a reply, but it will contain the fallbacks, so we have to trim them.
|
||||||
*/
|
*/
|
||||||
fun bodyForReply(content: MessageContent?, isReply: Boolean): TextContent {
|
private fun bodyForReply(content: MessageContent?, isReply: Boolean): TextContent {
|
||||||
when (content?.msgType) {
|
when (content?.msgType) {
|
||||||
MessageType.MSGTYPE_EMOTE,
|
MessageType.MSGTYPE_EMOTE,
|
||||||
MessageType.MSGTYPE_TEXT,
|
MessageType.MSGTYPE_TEXT,
|
||||||
|
|
|
@ -42,7 +42,6 @@ import org.matrix.android.sdk.api.settings.LightweightSettingsStorage
|
||||||
import org.matrix.android.sdk.internal.database.mapper.TimelineEventMapper
|
import org.matrix.android.sdk.internal.database.mapper.TimelineEventMapper
|
||||||
import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask
|
import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask
|
||||||
import org.matrix.android.sdk.internal.session.room.relation.threads.FetchThreadTimelineTask
|
import org.matrix.android.sdk.internal.session.room.relation.threads.FetchThreadTimelineTask
|
||||||
import org.matrix.android.sdk.internal.session.room.send.LocalEchoEventFactory
|
|
||||||
import org.matrix.android.sdk.internal.session.room.state.StateEventDataSource
|
import org.matrix.android.sdk.internal.session.room.state.StateEventDataSource
|
||||||
import org.matrix.android.sdk.internal.session.sync.handler.room.ReadReceiptHandler
|
import org.matrix.android.sdk.internal.session.sync.handler.room.ReadReceiptHandler
|
||||||
import org.matrix.android.sdk.internal.session.sync.handler.room.ThreadsAwarenessHandler
|
import org.matrix.android.sdk.internal.session.sync.handler.room.ThreadsAwarenessHandler
|
||||||
|
@ -64,7 +63,6 @@ internal class DefaultTimeline(
|
||||||
private val settings: TimelineSettings,
|
private val settings: TimelineSettings,
|
||||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||||
private val clock: Clock,
|
private val clock: Clock,
|
||||||
localEchoEventFactory: LocalEchoEventFactory,
|
|
||||||
stateEventDataSource: StateEventDataSource,
|
stateEventDataSource: StateEventDataSource,
|
||||||
paginationTask: PaginationTask,
|
paginationTask: PaginationTask,
|
||||||
getEventTask: GetContextOfEventTask,
|
getEventTask: GetContextOfEventTask,
|
||||||
|
@ -116,7 +114,6 @@ internal class DefaultTimeline(
|
||||||
onNewTimelineEvents = this::onNewTimelineEvents,
|
onNewTimelineEvents = this::onNewTimelineEvents,
|
||||||
stateEventDataSource = stateEventDataSource,
|
stateEventDataSource = stateEventDataSource,
|
||||||
matrixCoroutineDispatchers = coroutineDispatchers,
|
matrixCoroutineDispatchers = coroutineDispatchers,
|
||||||
localEchoEventFactory = localEchoEventFactory
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private var strategy: LoadTimelineStrategy = buildStrategy(LoadTimelineStrategy.Mode.Live)
|
private var strategy: LoadTimelineStrategy = buildStrategy(LoadTimelineStrategy.Mode.Live)
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.matrix.android.sdk.internal.database.mapper.TimelineEventMapper
|
||||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||||
import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask
|
import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask
|
||||||
import org.matrix.android.sdk.internal.session.room.relation.threads.FetchThreadTimelineTask
|
import org.matrix.android.sdk.internal.session.room.relation.threads.FetchThreadTimelineTask
|
||||||
import org.matrix.android.sdk.internal.session.room.send.LocalEchoEventFactory
|
|
||||||
import org.matrix.android.sdk.internal.session.room.state.StateEventDataSource
|
import org.matrix.android.sdk.internal.session.room.state.StateEventDataSource
|
||||||
import org.matrix.android.sdk.internal.session.sync.handler.room.ReadReceiptHandler
|
import org.matrix.android.sdk.internal.session.sync.handler.room.ReadReceiptHandler
|
||||||
import org.matrix.android.sdk.internal.session.sync.handler.room.ThreadsAwarenessHandler
|
import org.matrix.android.sdk.internal.session.sync.handler.room.ThreadsAwarenessHandler
|
||||||
|
@ -56,7 +55,6 @@ internal class DefaultTimelineService @AssistedInject constructor(
|
||||||
private val timelineEventDataSource: TimelineEventDataSource,
|
private val timelineEventDataSource: TimelineEventDataSource,
|
||||||
private val clock: Clock,
|
private val clock: Clock,
|
||||||
private val stateEventDataSource: StateEventDataSource,
|
private val stateEventDataSource: StateEventDataSource,
|
||||||
private val localEchoEventFactory: LocalEchoEventFactory
|
|
||||||
) : TimelineService {
|
) : TimelineService {
|
||||||
|
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
|
@ -84,7 +82,6 @@ internal class DefaultTimelineService @AssistedInject constructor(
|
||||||
lightweightSettingsStorage = lightweightSettingsStorage,
|
lightweightSettingsStorage = lightweightSettingsStorage,
|
||||||
clock = clock,
|
clock = clock,
|
||||||
stateEventDataSource = stateEventDataSource,
|
stateEventDataSource = stateEventDataSource,
|
||||||
localEchoEventFactory = localEchoEventFactory
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,6 @@ import org.matrix.android.sdk.internal.database.query.findAllIncludingEvents
|
||||||
import org.matrix.android.sdk.internal.database.query.findLastForwardChunkOfThread
|
import org.matrix.android.sdk.internal.database.query.findLastForwardChunkOfThread
|
||||||
import org.matrix.android.sdk.internal.database.query.where
|
import org.matrix.android.sdk.internal.database.query.where
|
||||||
import org.matrix.android.sdk.internal.session.room.relation.threads.FetchThreadTimelineTask
|
import org.matrix.android.sdk.internal.session.room.relation.threads.FetchThreadTimelineTask
|
||||||
import org.matrix.android.sdk.internal.session.room.send.LocalEchoEventFactory
|
|
||||||
import org.matrix.android.sdk.internal.session.room.state.StateEventDataSource
|
import org.matrix.android.sdk.internal.session.room.state.StateEventDataSource
|
||||||
import org.matrix.android.sdk.internal.session.sync.handler.room.ThreadsAwarenessHandler
|
import org.matrix.android.sdk.internal.session.sync.handler.room.ThreadsAwarenessHandler
|
||||||
import org.matrix.android.sdk.internal.util.time.Clock
|
import org.matrix.android.sdk.internal.util.time.Clock
|
||||||
|
@ -107,7 +106,6 @@ internal class LoadTimelineStrategy constructor(
|
||||||
val onNewTimelineEvents: (List<String>) -> Unit,
|
val onNewTimelineEvents: (List<String>) -> Unit,
|
||||||
val stateEventDataSource: StateEventDataSource,
|
val stateEventDataSource: StateEventDataSource,
|
||||||
val matrixCoroutineDispatchers: MatrixCoroutineDispatchers,
|
val matrixCoroutineDispatchers: MatrixCoroutineDispatchers,
|
||||||
val localEchoEventFactory: LocalEchoEventFactory
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private var getContextLatch: CompletableDeferred<Unit>? = null
|
private var getContextLatch: CompletableDeferred<Unit>? = null
|
||||||
|
@ -343,8 +341,6 @@ internal class LoadTimelineStrategy constructor(
|
||||||
initialEventId = mode.originEventId(),
|
initialEventId = mode.originEventId(),
|
||||||
onBuiltEvents = dependencies.onEventsUpdated,
|
onBuiltEvents = dependencies.onEventsUpdated,
|
||||||
onEventsDeleted = dependencies.onEventsDeleted,
|
onEventsDeleted = dependencies.onEventsDeleted,
|
||||||
realm = dependencies.realm,
|
|
||||||
localEchoEventFactory = dependencies.localEchoEventFactory
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.room.timeline
|
||||||
|
|
||||||
import io.realm.OrderedCollectionChangeSet
|
import io.realm.OrderedCollectionChangeSet
|
||||||
import io.realm.OrderedRealmCollectionChangeListener
|
import io.realm.OrderedRealmCollectionChangeListener
|
||||||
import io.realm.Realm
|
|
||||||
import io.realm.RealmConfiguration
|
import io.realm.RealmConfiguration
|
||||||
import io.realm.RealmObjectChangeListener
|
import io.realm.RealmObjectChangeListener
|
||||||
import io.realm.RealmQuery
|
import io.realm.RealmQuery
|
||||||
|
@ -27,18 +26,10 @@ import io.realm.Sort
|
||||||
import kotlinx.coroutines.CompletableDeferred
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.api.session.events.model.Event
|
|
||||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||||
import org.matrix.android.sdk.api.session.events.model.UnsignedData
|
|
||||||
import org.matrix.android.sdk.api.session.events.model.content.EncryptedEventContent
|
|
||||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
|
||||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
|
||||||
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
|
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.Timeline
|
import org.matrix.android.sdk.api.session.room.timeline.Timeline
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings
|
import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
|
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.isReply
|
|
||||||
import org.matrix.android.sdk.api.settings.LightweightSettingsStorage
|
import org.matrix.android.sdk.api.settings.LightweightSettingsStorage
|
||||||
import org.matrix.android.sdk.internal.database.mapper.EventMapper
|
import org.matrix.android.sdk.internal.database.mapper.EventMapper
|
||||||
import org.matrix.android.sdk.internal.database.mapper.TimelineEventMapper
|
import org.matrix.android.sdk.internal.database.mapper.TimelineEventMapper
|
||||||
|
@ -46,15 +37,12 @@ import org.matrix.android.sdk.internal.database.model.ChunkEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.ChunkEntityFields
|
import org.matrix.android.sdk.internal.database.model.ChunkEntityFields
|
||||||
import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
|
import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
|
||||||
import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields
|
import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields
|
||||||
import org.matrix.android.sdk.internal.database.query.where
|
|
||||||
import org.matrix.android.sdk.internal.session.room.relation.threads.DefaultFetchThreadTimelineTask
|
import org.matrix.android.sdk.internal.session.room.relation.threads.DefaultFetchThreadTimelineTask
|
||||||
import org.matrix.android.sdk.internal.session.room.relation.threads.FetchThreadTimelineTask
|
import org.matrix.android.sdk.internal.session.room.relation.threads.FetchThreadTimelineTask
|
||||||
import org.matrix.android.sdk.internal.session.room.send.LocalEchoEventFactory
|
|
||||||
import org.matrix.android.sdk.internal.session.sync.handler.room.ThreadsAwarenessHandler
|
import org.matrix.android.sdk.internal.session.sync.handler.room.ThreadsAwarenessHandler
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import java.util.concurrent.atomic.AtomicReference
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a wrapper around a ChunkEntity in the database.
|
* This is a wrapper around a ChunkEntity in the database.
|
||||||
|
@ -78,8 +66,6 @@ internal class TimelineChunk(
|
||||||
private val initialEventId: String?,
|
private val initialEventId: String?,
|
||||||
private val onBuiltEvents: (Boolean) -> Unit,
|
private val onBuiltEvents: (Boolean) -> Unit,
|
||||||
private val onEventsDeleted: () -> Unit,
|
private val onEventsDeleted: () -> Unit,
|
||||||
private val realm: AtomicReference<Realm>,
|
|
||||||
val localEchoEventFactory: LocalEchoEventFactory,
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val isLastForward = AtomicBoolean(chunkEntity.isLastForward)
|
private val isLastForward = AtomicBoolean(chunkEntity.isLastForward)
|
||||||
|
@ -425,56 +411,9 @@ internal class TimelineChunk(
|
||||||
private fun buildTimelineEvent(eventEntity: TimelineEventEntity) = timelineEventMapper.map(
|
private fun buildTimelineEvent(eventEntity: TimelineEventEntity) = timelineEventMapper.map(
|
||||||
timelineEventEntity = eventEntity,
|
timelineEventEntity = eventEntity,
|
||||||
buildReadReceipts = timelineSettings.buildReadReceipts
|
buildReadReceipts = timelineSettings.buildReadReceipts
|
||||||
).let { timelineEvent ->
|
).let {
|
||||||
// eventually enhance with ui echo?
|
// eventually enhance with ui echo?
|
||||||
uiEchoManager?.decorateEventWithReactionUiEcho(timelineEvent)
|
(uiEchoManager?.decorateEventWithReactionUiEcho(it) ?: it)
|
||||||
|
|
||||||
if (timelineEvent.isReply()) {
|
|
||||||
createNewEncryptedRepliedEvent(timelineEvent)?.let { newEvent ->
|
|
||||||
timelineEvent.copy(root = newEvent)
|
|
||||||
} ?: timelineEvent
|
|
||||||
} else timelineEvent
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createNewEncryptedRepliedEvent(currentTimelineEvent: TimelineEvent): Event? {
|
|
||||||
val relatesEventId = if (currentTimelineEvent.isEncrypted()) {
|
|
||||||
currentTimelineEvent.root.content.toModel<EncryptedEventContent>()?.relatesTo?.inReplyTo?.eventId
|
|
||||||
} else {
|
|
||||||
currentTimelineEvent.root.content.toModel<MessageContent>()?.relatesTo?.inReplyTo?.eventId
|
|
||||||
}
|
|
||||||
return relatesEventId?.let { eventId ->
|
|
||||||
val timeLineEventEntity = TimelineEventEntity.where(
|
|
||||||
realm.get(),
|
|
||||||
roomId,
|
|
||||||
eventId
|
|
||||||
).findFirst()
|
|
||||||
|
|
||||||
val replyText = localEchoEventFactory
|
|
||||||
.bodyForReply(currentTimelineEvent.getLastMessageContent(), true).formattedText ?: ""
|
|
||||||
|
|
||||||
timeLineEventEntity?.let { timelineEventEntity ->
|
|
||||||
val newContent = localEchoEventFactory.createReplyTextContent(
|
|
||||||
timelineEventMapper.map(timelineEventEntity),
|
|
||||||
replyText,
|
|
||||||
false,
|
|
||||||
showInThread = false
|
|
||||||
).toContent()
|
|
||||||
val event = currentTimelineEvent.root
|
|
||||||
Event(
|
|
||||||
roomId = event.roomId,
|
|
||||||
originServerTs = event.originServerTs,
|
|
||||||
senderId = event.senderId,
|
|
||||||
eventId = currentTimelineEvent.eventId,
|
|
||||||
type = EventType.MESSAGE,
|
|
||||||
content = newContent,
|
|
||||||
unsignedData = UnsignedData(age = null, transactionId = currentTimelineEvent.eventId),
|
|
||||||
).apply {
|
|
||||||
this.sendState = event.sendState
|
|
||||||
this.ageLocalTs = event.ageLocalTs
|
|
||||||
this.threadDetails = event.threadDetails
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -641,9 +580,7 @@ internal class TimelineChunk(
|
||||||
lightweightSettingsStorage = lightweightSettingsStorage,
|
lightweightSettingsStorage = lightweightSettingsStorage,
|
||||||
initialEventId = null,
|
initialEventId = null,
|
||||||
onBuiltEvents = this.onBuiltEvents,
|
onBuiltEvents = this.onBuiltEvents,
|
||||||
onEventsDeleted = this.onEventsDeleted,
|
onEventsDeleted = this.onEventsDeleted
|
||||||
realm = realm,
|
|
||||||
localEchoEventFactory = localEchoEventFactory
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue