forked from GitHub-Mirror/riotX-android
Fix / edit reply was quoting wrong text
+ e2e reply of edit
This commit is contained in:
@ -85,14 +85,12 @@ interface RelationService {
|
||||
* Edit a reply. This is a special case because replies contains fallback text as a prefix.
|
||||
* This method will take the new body (stripped from fallbacks) and re-add them before sending.
|
||||
* @param replyToEdit The event to edit
|
||||
* @param originalSenderId the sender of the message that this reply (being edited) is relating to
|
||||
* @param originalEventId the event id that this reply (being edited) is relating to
|
||||
* @param originalTimelineEvent the message that this reply (being edited) is relating to
|
||||
* @param newBodyText The edited body (stripped from in reply to content)
|
||||
* @param compatibilityBodyText The text that will appear on clients that don't support yet edition
|
||||
*/
|
||||
fun editReply(replyToEdit: TimelineEvent,
|
||||
originalSenderId: String?,
|
||||
originalEventId : String,
|
||||
originalTimelineEvent: TimelineEvent,
|
||||
newBodyText: String,
|
||||
compatibilityBodyText: String = "* $newBodyText"): Cancelable
|
||||
|
||||
|
@ -24,6 +24,7 @@ import im.vector.matrix.android.api.session.room.model.message.MessageContent
|
||||
import im.vector.matrix.android.api.session.room.model.message.isReply
|
||||
import im.vector.matrix.android.api.session.room.send.SendState
|
||||
import im.vector.matrix.android.api.util.ContentUtils.extractUsefulTextFromReply
|
||||
import im.vector.matrix.android.internal.crypto.model.event.EncryptedEventContent
|
||||
|
||||
/**
|
||||
* This data class is a wrapper around an Event. It allows to get useful data in the context of a timeline.
|
||||
@ -94,7 +95,7 @@ fun TimelineEvent.getLastMessageContent(): MessageContent? = annotations?.editSu
|
||||
|
||||
fun TimelineEvent.getTextEditableContent(): String? {
|
||||
val originalContent = root.getClearContent().toModel<MessageContent>() ?: return null
|
||||
val isReply = originalContent.isReply()
|
||||
val isReply = originalContent.isReply() || root.content.toModel<EncryptedEventContent>()?.relatesTo?.inReplyTo?.eventId != null
|
||||
val lastContent = getLastMessageContent()
|
||||
return if (isReply) {
|
||||
return extractUsefulTextFromReply(lastContent?.body ?: "")
|
||||
|
@ -142,14 +142,13 @@ internal class DefaultRelationService @Inject constructor(private val context: C
|
||||
}
|
||||
|
||||
override fun editReply(replyToEdit: TimelineEvent,
|
||||
originalSenderId: String?,
|
||||
originalEventId: String,
|
||||
originalEvent: TimelineEvent,
|
||||
newBodyText: String,
|
||||
compatibilityBodyText: String): Cancelable {
|
||||
val event = eventFactory
|
||||
.createReplaceTextOfReply(roomId,
|
||||
replyToEdit,
|
||||
originalSenderId, originalEventId,
|
||||
originalEvent,
|
||||
newBodyText, true, MessageType.MSGTYPE_TEXT, compatibilityBodyText)
|
||||
.also {
|
||||
saveLocalEcho(it)
|
||||
|
@ -105,28 +105,28 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials
|
||||
}
|
||||
|
||||
fun createReplaceTextOfReply(roomId: String, eventReplaced: TimelineEvent,
|
||||
originalSenderId: String?,
|
||||
originalEventId: String,
|
||||
originalEvent: TimelineEvent,
|
||||
newBodyText: String,
|
||||
newBodyAutoMarkdown: Boolean,
|
||||
msgType: String,
|
||||
compatibilityText: String): Event {
|
||||
val permalink = PermalinkFactory.createPermalink(roomId, originalEventId)
|
||||
val userLink = originalSenderId?.let { PermalinkFactory.createPermalink(it) } ?: ""
|
||||
val permalink = PermalinkFactory.createPermalink(roomId, originalEvent.root.eventId ?: "")
|
||||
val userLink = originalEvent.root.senderId?.let { PermalinkFactory.createPermalink(it) }
|
||||
?: ""
|
||||
|
||||
val body = bodyForReply(eventReplaced.getLastMessageContent(), eventReplaced.root.getClearContent().toModel())
|
||||
val body = bodyForReply(originalEvent.getLastMessageContent(), originalEvent.root.getClearContent().toModel())
|
||||
val replyFormatted = REPLY_PATTERN.format(
|
||||
permalink,
|
||||
stringProvider.getString(R.string.message_reply_to_prefix),
|
||||
userLink,
|
||||
originalSenderId,
|
||||
originalEvent.senderName ?: originalEvent.root.senderId,
|
||||
body.takeFormatted(),
|
||||
createTextContent(newBodyText, newBodyAutoMarkdown).takeFormatted()
|
||||
)
|
||||
//
|
||||
// > <@alice:example.org> This is the original body
|
||||
//
|
||||
val replyFallback = buildReplyFallback(body, originalSenderId, newBodyText)
|
||||
val replyFallback = buildReplyFallback(body, originalEvent.root.senderId ?: "", newBodyText)
|
||||
|
||||
return createEvent(roomId,
|
||||
MessageTextContent(
|
||||
|
Reference in New Issue
Block a user