From c6fd625761464d8f35fc69b8ffebdb9b485a76af Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 16 Jul 2019 14:38:49 +0200 Subject: [PATCH] code review --- .../android/api/session/room/model/message/MessageContent.kt | 5 +++++ .../api/session/room/model/relation/RelationService.kt | 4 +++- .../android/api/session/room/timeline/TimelineEvent.kt | 5 +++-- .../java/im/vector/matrix/android/api/util/ContentUtils.kt | 4 +++- .../internal/session/room/send/LocalEchoEventFactory.kt | 4 ++-- .../room/detail/timeline/action/ViewEditHistoryViewModel.kt | 3 ++- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageContent.kt index c45e47fcc4..bd32a75a47 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/message/MessageContent.kt @@ -25,4 +25,9 @@ interface MessageContent { val body: String val relatesTo: RelationDefaultContent? val newContent: Content? +} + + +fun MessageContent?.isReply(): Boolean { + return this?.relatesTo?.inReplyTo != null } \ No newline at end of file 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 bfc569e10b..da91ee70be 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 @@ -84,7 +84,9 @@ 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 targetEventId 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 originalEventId the event id 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 */ 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 251fe3d3f5..761c39618f 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 @@ -21,8 +21,9 @@ import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary 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.internal.session.room.send.extractUsefulTextFromReply +import im.vector.matrix.android.api.util.ContentUtils.extractUsefulTextFromReply /** * This data class is a wrapper around an Event. It allows to get useful data in the context of a timeline. @@ -93,7 +94,7 @@ fun TimelineEvent.getLastMessageContent(): MessageContent? = annotations?.editSu fun TimelineEvent.getTextEditableContent(): String? { val originalContent = root.getClearContent().toModel() ?: return null - val isReply = originalContent.relatesTo?.inReplyTo != null + val isReply = originalContent.isReply() val lastContent = getLastMessageContent() return if (isReply) { return extractUsefulTextFromReply(lastContent?.body ?: "") diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/util/ContentUtils.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/util/ContentUtils.kt index 0a395deeda..ad17d26b20 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/util/ContentUtils.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/util/ContentUtils.kt @@ -38,7 +38,9 @@ object ContentUtils { fun extractUsefulTextFromHtmlReply(repliedBody: String): String { if (repliedBody.startsWith("")) { - return repliedBody.substring(repliedBody.lastIndexOf("") + "".length).trim() + val closingTagIndex = repliedBody.lastIndexOf("") + if (closingTagIndex != -1) + return repliedBody.substring(closingTagIndex + "".length).trim() } return repliedBody } 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 fe039341c2..51aed8a749 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 @@ -334,8 +334,8 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials formattedText = content.formattedBody } } - val isReply = content.relatesTo?.inReplyTo?.eventId != null || - originalContent?.relatesTo?.inReplyTo?.eventId != null + val isReply = content.isReply() || + originalContent.isReply() return if (isReply) TextContent(content.body, formattedText).removeInReplyFallbacks() else diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/ViewEditHistoryViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/ViewEditHistoryViewModel.kt index bda46d46fb..576ef5e91a 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/ViewEditHistoryViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/ViewEditHistoryViewModel.kt @@ -23,6 +23,7 @@ import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.toModel 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.riotx.core.platform.VectorViewModel import im.vector.riotx.features.home.room.detail.timeline.helper.TimelineDateFormatter @@ -83,7 +84,7 @@ class ViewEditHistoryViewModel @AssistedInject constructor(@Assisted var originalIsReply = false room.getTimeLineEvent(eventId)?.let { withOriginal.add(it.root) - originalIsReply = it.root.getClearContent().toModel()?.relatesTo?.inReplyTo?.eventId != null + originalIsReply = it.root.getClearContent().toModel().isReply() } setState { copy(