-
Notifications
You must be signed in to change notification settings - Fork 746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replyTo are not updated if the original message is edited #6404
Changes from 15 commits
e056fe9
12a1124
5442e70
8b041c8
3fbbdcd
019ffc6
6e73cda
3aa0ce7
9029dc1
dfc066b
5f2c3d7
9042ba3
7f4cfb9
573948f
14b8c37
d32b9fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ReplyTo are not updated if the original message is edited |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.room.timeline | |
|
||
import io.realm.OrderedCollectionChangeSet | ||
import io.realm.OrderedRealmCollectionChangeListener | ||
import io.realm.Realm | ||
import io.realm.RealmConfiguration | ||
import io.realm.RealmObjectChangeListener | ||
import io.realm.RealmQuery | ||
|
@@ -26,23 +27,34 @@ import io.realm.Sort | |
import kotlinx.coroutines.CompletableDeferred | ||
import org.matrix.android.sdk.api.extensions.orFalse | ||
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.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.TimelineEvent | ||
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.internal.database.mapper.EventMapper | ||
import org.matrix.android.sdk.internal.database.mapper.TimelineEventMapper | ||
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.TimelineEventEntity | ||
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.FetchThreadTimelineTask | ||
import org.matrix.android.sdk.internal.session.room.send.LocalEchoEventFactory | ||
import org.matrix.android.sdk.internal.session.sync.handler.room.ThreadsAwarenessHandler | ||
import timber.log.Timber | ||
import java.util.Collections | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
import java.util.concurrent.atomic.AtomicReference | ||
|
||
/** | ||
* This is a wrapper around a ChunkEntity in the database. | ||
|
@@ -66,6 +78,8 @@ internal class TimelineChunk( | |
private val initialEventId: String?, | ||
private val onBuiltEvents: (Boolean) -> Unit, | ||
private val onEventsDeleted: () -> Unit, | ||
private val realm: AtomicReference<Realm>, | ||
val localEchoEventFactory: LocalEchoEventFactory, | ||
) { | ||
|
||
private val isLastForward = AtomicBoolean(chunkEntity.isLastForward) | ||
|
@@ -411,9 +425,56 @@ internal class TimelineChunk( | |
private fun buildTimelineEvent(eventEntity: TimelineEventEntity) = timelineEventMapper.map( | ||
timelineEventEntity = eventEntity, | ||
buildReadReceipts = timelineSettings.buildReadReceipts | ||
).let { | ||
).let { timelineEvent -> | ||
// eventually enhance with ui echo? | ||
(uiEchoManager?.decorateEventWithReactionUiEcho(it) ?: it) | ||
uiEchoManager?.decorateEventWithReactionUiEcho(timelineEvent) | ||
|
||
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are missing the transient fields here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If i keep the transient fileds here, my message is not updated: the old version is keep. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because you are also copying the decrypted response :-) |
||
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 | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -595,7 +656,9 @@ internal class TimelineChunk( | |
lightweightSettingsStorage = lightweightSettingsStorage, | ||
initialEventId = null, | ||
onBuiltEvents = this.onBuiltEvents, | ||
onEventsDeleted = this.onEventsDeleted | ||
onEventsDeleted = this.onEventsDeleted, | ||
realm = realm, | ||
localEchoEventFactory = localEchoEventFactory | ||
) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use this in createReplyTextEvent