From 3625c462f0612b8d47629970c5b3f0bb94492ba4 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 12 Jul 2019 13:51:05 +0200 Subject: [PATCH 1/2] Click on redacted event --- CHANGES.md | 2 +- .../riotx/core/extensions/TimelineEvent.kt | 2 +- .../timeline/action/MessageMenuViewModel.kt | 82 ++++++++++--------- .../timeline/factory/MessageItemFactory.kt | 8 ++ 4 files changed, 52 insertions(+), 42 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3d9ce454..2b212934 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Features: - Improvements: - - + - Handle click on redacted events: view source and create permalink Other changes: - diff --git a/vector/src/main/java/im/vector/riotx/core/extensions/TimelineEvent.kt b/vector/src/main/java/im/vector/riotx/core/extensions/TimelineEvent.kt index c82631c0..db171300 100644 --- a/vector/src/main/java/im/vector/riotx/core/extensions/TimelineEvent.kt +++ b/vector/src/main/java/im/vector/riotx/core/extensions/TimelineEvent.kt @@ -21,5 +21,5 @@ import im.vector.matrix.android.api.session.room.timeline.TimelineEvent fun TimelineEvent.canReact(): Boolean { // Only event of type Event.EVENT_TYPE_MESSAGE are supported for the moment - return root.getClearType() == EventType.MESSAGE && sendState.isSent() + return root.getClearType() == EventType.MESSAGE && sendState.isSent() && !root.isRedacted() } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt index 21f5da52..b49731d9 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt @@ -126,51 +126,53 @@ class MessageMenuViewModel @AssistedInject constructor(@Assisted initialState: M } //TODO is downloading attachement? - if (event.canReact()) { - this.add(SimpleAction(ACTION_ADD_REACTION, R.string.message_add_reaction, R.drawable.ic_add_reaction, eventId)) - } - if (canCopy(type)) { - //TODO copy images? html? see ClipBoard - this.add(SimpleAction(ACTION_COPY, R.string.copy, R.drawable.ic_copy, messageContent!!.body)) - } - - if (canReply(event, messageContent)) { - this.add(SimpleAction(ACTION_REPLY, R.string.reply, R.drawable.ic_reply, eventId)) - } - - if (canEdit(event, session.sessionParams.credentials.userId)) { - this.add(SimpleAction(ACTION_EDIT, R.string.edit, R.drawable.ic_edit, eventId)) - } - - if (canRedact(event, session.sessionParams.credentials.userId)) { - this.add(SimpleAction(ACTION_DELETE, R.string.delete, R.drawable.ic_delete, eventId)) - } - - if (canQuote(event, messageContent)) { - this.add(SimpleAction(ACTION_QUOTE, R.string.quote, R.drawable.ic_quote, eventId)) - } - - if (canViewReactions(event)) { - this.add(SimpleAction(ACTION_VIEW_REACTIONS, R.string.message_view_reaction, R.drawable.ic_view_reactions, informationData)) - } - - if (canShare(type)) { - if (messageContent is MessageImageContent) { - this.add( - SimpleAction(ACTION_SHARE, - R.string.share, R.drawable.ic_share, - session.contentUrlResolver().resolveFullSize(messageContent.url)) - ) + if (!event.root.isRedacted()) { + if (event.canReact()) { + this.add(SimpleAction(ACTION_ADD_REACTION, R.string.message_add_reaction, R.drawable.ic_add_reaction, eventId)) + } + if (canCopy(type)) { + //TODO copy images? html? see ClipBoard + this.add(SimpleAction(ACTION_COPY, R.string.copy, R.drawable.ic_copy, messageContent!!.body)) + } + + if (canReply(event, messageContent)) { + this.add(SimpleAction(ACTION_REPLY, R.string.reply, R.drawable.ic_reply, eventId)) + } + + if (canEdit(event, session.sessionParams.credentials.userId)) { + this.add(SimpleAction(ACTION_EDIT, R.string.edit, R.drawable.ic_edit, eventId)) + } + + if (canRedact(event, session.sessionParams.credentials.userId)) { + this.add(SimpleAction(ACTION_DELETE, R.string.delete, R.drawable.ic_delete, eventId)) + } + + if (canQuote(event, messageContent)) { + this.add(SimpleAction(ACTION_QUOTE, R.string.quote, R.drawable.ic_quote, eventId)) + } + + if (canViewReactions(event)) { + this.add(SimpleAction(ACTION_VIEW_REACTIONS, R.string.message_view_reaction, R.drawable.ic_view_reactions, informationData)) + } + + if (canShare(type)) { + if (messageContent is MessageImageContent) { + this.add( + SimpleAction(ACTION_SHARE, + R.string.share, R.drawable.ic_share, + session.contentUrlResolver().resolveFullSize(messageContent.url)) + ) + } + //TODO } - //TODO - } - if (event.sendState == SendState.SENT) { + if (event.sendState == SendState.SENT) { - //TODO Can be redacted + //TODO Can be redacted - //TODO sent by me or sufficient power level + //TODO sent by me or sufficient power level + } } this.add(SimpleAction(VIEW_SOURCE, R.string.view_source, R.drawable.ic_view_source, event.root.toContentStringWithIndent())) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt index d8f1c602..3f5c41bf 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -417,6 +417,14 @@ class MessageItemFactory @Inject constructor( .informationData(informationData) .highlighted(highlight) .avatarCallback(callback) + .cellClickListener( + DebouncedClickListener(View.OnClickListener { view -> + callback?.onEventCellClicked(informationData, null, view) + })) + .longClickListener { view -> + return@longClickListener callback?.onEventLongClicked(informationData, null, view) + ?: false + } } private fun linkifyBody(body: CharSequence, callback: TimelineEventController.Callback?): CharSequence { From 34d14eb3046a8ec40c3e56e6f3fb26ee404d2826 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 12 Jul 2019 12:46:02 +0200 Subject: [PATCH 2/2] Fix regression on permalink click --- CHANGES.md | 2 +- .../im/vector/matrix/android/api/permalinks/MatrixLinkify.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 2b212934..411a6c83 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ Other changes: - Bugfix: - - + - Fix regression on permalink click Translations: - diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/MatrixLinkify.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/MatrixLinkify.kt index cfe5a051..fb3dbcc2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/MatrixLinkify.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/MatrixLinkify.kt @@ -42,7 +42,7 @@ object MatrixLinkify { hasMatch = true val startPos = match.range.first if (startPos == 0 || text[startPos - 1] != '/') { - val endPos = match.range.last + val endPos = match.range.last + 1 val url = text.substring(match.range) val span = MatrixPermalinkSpan(url, callback) spannable.setSpan(span, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) @@ -51,5 +51,5 @@ object MatrixLinkify { } return hasMatch } - + } \ No newline at end of file