diff --git a/CHANGES.md b/CHANGES.md index 7cffa1ff..7fcf6842 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ Changes in RiotX 0.2.1 (2019-XX-XX) Features: - Message Editing: View edit history (#121) - Rooms filtering (#304) + - Edit in encrypted room Improvements: - Handle click on redacted events: view source and create permalink diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/relation/RelationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/relation/RelationService.kt index da91ee70..0c4e1beb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/relation/RelationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/relation/RelationService.kt @@ -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 diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/timeline/TimelineEvent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/timeline/TimelineEvent.kt index 761c3961..044aa957 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/timeline/TimelineEvent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/timeline/TimelineEvent.kt @@ -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() ?: return null - val isReply = originalContent.isReply() + val isReply = originalContent.isReply() || root.content.toModel()?.relatesTo?.inReplyTo?.eventId != null val lastContent = getLastMessageContent() return if (isReply) { return extractUsefulTextFromReply(lastContent?.body ?: "") diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt index 025de462..183f2a6c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt @@ -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) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt index 40390d5d..c6b68647 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt @@ -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( diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt index a15eae5b..d38561fa 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt @@ -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.timeline.TimelineEvent 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.riotx.core.intent.getFilenameFromUri import im.vector.riotx.core.platform.VectorViewModel @@ -229,9 +230,12 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro //is original event a reply? val inReplyTo = state.sendMode.timelineEvent.root.getClearContent().toModel()?.relatesTo?.inReplyTo?.eventId + ?: state.sendMode.timelineEvent.root.content.toModel()?.relatesTo?.inReplyTo?.eventId if (inReplyTo != null) { //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 { val messageContent: MessageContent? = state.sendMode.timelineEvent.annotations?.editSummary?.aggregatedContent.toModel()