mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 09:25:49 +03:00
Fix / edit reply was quoting wrong text
+ e2e reply of edit
This commit is contained in:
parent
077396a832
commit
7d41352918
6 changed files with 19 additions and 16 deletions
|
@ -4,6 +4,7 @@ Changes in RiotX 0.2.1 (2019-XX-XX)
|
||||||
Features:
|
Features:
|
||||||
- Message Editing: View edit history (#121)
|
- Message Editing: View edit history (#121)
|
||||||
- Rooms filtering (#304)
|
- Rooms filtering (#304)
|
||||||
|
- Edit in encrypted room
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
- Handle click on redacted events: view source and create permalink
|
- Handle click on redacted events: view source and create permalink
|
||||||
|
|
|
@ -85,14 +85,12 @@ interface RelationService {
|
||||||
* Edit a reply. This is a special case because replies contains fallback text as a prefix.
|
* 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.
|
* This method will take the new body (stripped from fallbacks) and re-add them before sending.
|
||||||
* @param replyToEdit The event to edit
|
* @param replyToEdit The event to edit
|
||||||
* @param originalSenderId the sender of the message that this reply (being edited) is relating to
|
* @param originalTimelineEvent the message that this reply (being edited) is relating to
|
||||||
* @param originalEventId the event id that this reply (being edited) is relating to
|
|
||||||
* @param newBodyText The edited body (stripped from in reply to content)
|
* @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
|
* @param compatibilityBodyText The text that will appear on clients that don't support yet edition
|
||||||
*/
|
*/
|
||||||
fun editReply(replyToEdit: TimelineEvent,
|
fun editReply(replyToEdit: TimelineEvent,
|
||||||
originalSenderId: String?,
|
originalTimelineEvent: TimelineEvent,
|
||||||
originalEventId : String,
|
|
||||||
newBodyText: String,
|
newBodyText: String,
|
||||||
compatibilityBodyText: String = "* $newBodyText"): Cancelable
|
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.model.message.isReply
|
||||||
import im.vector.matrix.android.api.session.room.send.SendState
|
import im.vector.matrix.android.api.session.room.send.SendState
|
||||||
import im.vector.matrix.android.api.util.ContentUtils.extractUsefulTextFromReply
|
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.
|
* 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? {
|
fun TimelineEvent.getTextEditableContent(): String? {
|
||||||
val originalContent = root.getClearContent().toModel<MessageContent>() ?: return null
|
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()
|
val lastContent = getLastMessageContent()
|
||||||
return if (isReply) {
|
return if (isReply) {
|
||||||
return extractUsefulTextFromReply(lastContent?.body ?: "")
|
return extractUsefulTextFromReply(lastContent?.body ?: "")
|
||||||
|
|
|
@ -142,14 +142,13 @@ internal class DefaultRelationService @Inject constructor(private val context: C
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun editReply(replyToEdit: TimelineEvent,
|
override fun editReply(replyToEdit: TimelineEvent,
|
||||||
originalSenderId: String?,
|
originalEvent: TimelineEvent,
|
||||||
originalEventId: String,
|
|
||||||
newBodyText: String,
|
newBodyText: String,
|
||||||
compatibilityBodyText: String): Cancelable {
|
compatibilityBodyText: String): Cancelable {
|
||||||
val event = eventFactory
|
val event = eventFactory
|
||||||
.createReplaceTextOfReply(roomId,
|
.createReplaceTextOfReply(roomId,
|
||||||
replyToEdit,
|
replyToEdit,
|
||||||
originalSenderId, originalEventId,
|
originalEvent,
|
||||||
newBodyText, true, MessageType.MSGTYPE_TEXT, compatibilityBodyText)
|
newBodyText, true, MessageType.MSGTYPE_TEXT, compatibilityBodyText)
|
||||||
.also {
|
.also {
|
||||||
saveLocalEcho(it)
|
saveLocalEcho(it)
|
||||||
|
|
|
@ -105,28 +105,28 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createReplaceTextOfReply(roomId: String, eventReplaced: TimelineEvent,
|
fun createReplaceTextOfReply(roomId: String, eventReplaced: TimelineEvent,
|
||||||
originalSenderId: String?,
|
originalEvent: TimelineEvent,
|
||||||
originalEventId: String,
|
|
||||||
newBodyText: String,
|
newBodyText: String,
|
||||||
newBodyAutoMarkdown: Boolean,
|
newBodyAutoMarkdown: Boolean,
|
||||||
msgType: String,
|
msgType: String,
|
||||||
compatibilityText: String): Event {
|
compatibilityText: String): Event {
|
||||||
val permalink = PermalinkFactory.createPermalink(roomId, originalEventId)
|
val permalink = PermalinkFactory.createPermalink(roomId, originalEvent.root.eventId ?: "")
|
||||||
val userLink = originalSenderId?.let { PermalinkFactory.createPermalink(it) } ?: ""
|
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(
|
val replyFormatted = REPLY_PATTERN.format(
|
||||||
permalink,
|
permalink,
|
||||||
stringProvider.getString(R.string.message_reply_to_prefix),
|
stringProvider.getString(R.string.message_reply_to_prefix),
|
||||||
userLink,
|
userLink,
|
||||||
originalSenderId,
|
originalEvent.senderName ?: originalEvent.root.senderId,
|
||||||
body.takeFormatted(),
|
body.takeFormatted(),
|
||||||
createTextContent(newBodyText, newBodyAutoMarkdown).takeFormatted()
|
createTextContent(newBodyText, newBodyAutoMarkdown).takeFormatted()
|
||||||
)
|
)
|
||||||
//
|
//
|
||||||
// > <@alice:example.org> This is the original body
|
// > <@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,
|
return createEvent(roomId,
|
||||||
MessageTextContent(
|
MessageTextContent(
|
||||||
|
|
|
@ -38,6 +38,7 @@ import im.vector.matrix.android.api.session.room.model.message.MessageType
|
||||||
import im.vector.matrix.android.api.session.room.model.message.getFileUrl
|
import im.vector.matrix.android.api.session.room.model.message.getFileUrl
|
||||||
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||||
import im.vector.matrix.android.internal.crypto.attachments.toElementToDecrypt
|
import im.vector.matrix.android.internal.crypto.attachments.toElementToDecrypt
|
||||||
|
import im.vector.matrix.android.internal.crypto.model.event.EncryptedEventContent
|
||||||
import im.vector.matrix.rx.rx
|
import im.vector.matrix.rx.rx
|
||||||
import im.vector.riotx.core.intent.getFilenameFromUri
|
import im.vector.riotx.core.intent.getFilenameFromUri
|
||||||
import im.vector.riotx.core.platform.VectorViewModel
|
import im.vector.riotx.core.platform.VectorViewModel
|
||||||
|
@ -229,9 +230,12 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
|
||||||
|
|
||||||
//is original event a reply?
|
//is original event a reply?
|
||||||
val inReplyTo = state.sendMode.timelineEvent.root.getClearContent().toModel<MessageContent>()?.relatesTo?.inReplyTo?.eventId
|
val inReplyTo = state.sendMode.timelineEvent.root.getClearContent().toModel<MessageContent>()?.relatesTo?.inReplyTo?.eventId
|
||||||
|
?: state.sendMode.timelineEvent.root.content.toModel<EncryptedEventContent>()?.relatesTo?.inReplyTo?.eventId
|
||||||
if (inReplyTo != null) {
|
if (inReplyTo != null) {
|
||||||
//TODO check if same content?
|
//TODO check if same content?
|
||||||
room.editReply(state.sendMode.timelineEvent, room.getTimeLineEvent(inReplyTo)?.root?.senderId, inReplyTo, action.text)
|
room.getTimeLineEvent(inReplyTo)?.let {
|
||||||
|
room.editReply(state.sendMode.timelineEvent, it, action.text)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
val messageContent: MessageContent? =
|
val messageContent: MessageContent? =
|
||||||
state.sendMode.timelineEvent.annotations?.editSummary?.aggregatedContent.toModel()
|
state.sendMode.timelineEvent.annotations?.editSummary?.aggregatedContent.toModel()
|
||||||
|
|
Loading…
Reference in a new issue