From 19c7de687e2fe83ce95ec17dbc4192b1c8f9b076 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 10 Jul 2019 11:51:09 +0200 Subject: [PATCH 1/2] We can react on e2e room text event --- .../room/detail/timeline/action/MessageActionsBottomSheet.kt | 4 ++-- .../room/detail/timeline/action/MessageActionsViewModel.kt | 2 +- .../home/room/detail/timeline/action/QuickReactionFragment.kt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt index 1b39b1b7..f8f5fe3e 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt @@ -104,8 +104,8 @@ class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment() { } quickReactionFragment.interactionListener = object : QuickReactionFragment.InteractionListener { - override fun didQuickReactWith(clikedOn: String, add: Boolean, eventId: String) { - actionHandlerModel.fireAction(MessageMenuViewModel.ACTION_QUICK_REACT, Triple(eventId, clikedOn, add)) + override fun didQuickReactWith(clickedOn: String, add: Boolean, eventId: String) { + actionHandlerModel.fireAction(MessageMenuViewModel.ACTION_QUICK_REACT, Triple(eventId, clickedOn, add)) dismiss() } } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt index 161a8cc5..bf79aa09 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt @@ -52,7 +52,7 @@ data class MessageActionState( fun time(): String? = timelineEvent()?.root?.originServerTs?.let { dateFormat.format(Date(it)) } ?: "" - fun canReact(): Boolean = timelineEvent()?.root?.type == EventType.MESSAGE && timelineEvent()?.sendState?.isSent() == true + fun canReact(): Boolean = timelineEvent()?.root?.getClearType() == EventType.MESSAGE && timelineEvent()?.sendState?.isSent() == true fun messageBody(eventHtmlRenderer: EventHtmlRenderer?, noticeEventFormatter: NoticeEventFormatter?): CharSequence? { return when (timelineEvent()?.root?.getClearType()) { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/QuickReactionFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/QuickReactionFragment.kt index fb731ce2..c549bb42 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/QuickReactionFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/QuickReactionFragment.kt @@ -76,7 +76,7 @@ class QuickReactionFragment : VectorBaseFragment() { } interface InteractionListener { - fun didQuickReactWith(clikedOn: String, add: Boolean, eventId: String) + fun didQuickReactWith(clickedOn: String, add: Boolean, eventId: String) } companion object { From e6409d4c60a7c7d9d90a5909baa881bb164f0d18 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 10 Jul 2019 12:10:55 +0200 Subject: [PATCH 2/2] Create a common canReact() method --- .../session/room/timeline/TimelineEvent.kt | 1 - .../riotx/core/extensions/TimelineEvent.kt | 25 +++++++++++++++++++ .../action/MessageActionsViewModel.kt | 3 ++- .../timeline/action/MessageMenuViewModel.kt | 14 +++-------- 4 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 vector/src/main/java/im/vector/riotx/core/extensions/TimelineEvent.kt 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 1e1de79a..3341d87e 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 @@ -16,7 +16,6 @@ package im.vector.matrix.android.api.session.room.timeline -import im.vector.matrix.android.api.session.events.model.Content import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary 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 new file mode 100644 index 00000000..c82631c0 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/core/extensions/TimelineEvent.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.core.extensions + +import im.vector.matrix.android.api.session.events.model.EventType +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() +} diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt index bf79aa09..cab2cbb6 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt @@ -27,6 +27,7 @@ import im.vector.matrix.android.api.session.room.model.message.MessageTextConten import im.vector.matrix.android.api.session.room.model.message.MessageType import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.rx.RxRoom +import im.vector.riotx.core.extensions.canReact import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.features.home.room.detail.timeline.format.NoticeEventFormatter import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData @@ -52,7 +53,7 @@ data class MessageActionState( fun time(): String? = timelineEvent()?.root?.originServerTs?.let { dateFormat.format(Date(it)) } ?: "" - fun canReact(): Boolean = timelineEvent()?.root?.getClearType() == EventType.MESSAGE && timelineEvent()?.sendState?.isSent() == true + fun canReact() = timelineEvent()?.canReact() == true fun messageBody(eventHtmlRenderer: EventHtmlRenderer?, noticeEventFormatter: NoticeEventFormatter?): CharSequence? { return when (timelineEvent()?.root?.getClearType()) { 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 5b77cef7..21f5da52 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 @@ -20,22 +20,19 @@ import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.events.model.EventType -import im.vector.matrix.android.api.session.events.model.toContent 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.MessageImageContent import im.vector.matrix.android.api.session.room.model.message.MessageType import im.vector.matrix.android.api.session.room.send.SendState import im.vector.matrix.android.api.session.room.timeline.TimelineEvent -import im.vector.matrix.android.internal.crypto.algorithms.olm.OlmDecryptionResult -import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.matrix.rx.RxRoom import im.vector.riotx.R +import im.vector.riotx.core.extensions.canReact import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.resources.StringProvider import im.vector.riotx.core.utils.isSingleEmoji import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData -import org.json.JSONObject data class SimpleAction(val uid: String, val titleRes: Int, val iconResId: Int?, val data: Any? = null) @@ -129,7 +126,7 @@ class MessageMenuViewModel @AssistedInject constructor(@Assisted initialState: M } //TODO is downloading attachement? - if (canReact(event, messageContent)) { + if (event.canReact()) { this.add(SimpleAction(ACTION_ADD_REACTION, R.string.message_add_reaction, R.drawable.ic_add_reaction, eventId)) } if (canCopy(type)) { @@ -176,7 +173,7 @@ class MessageMenuViewModel @AssistedInject constructor(@Assisted initialState: M //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())) + this.add(SimpleAction(VIEW_SOURCE, R.string.view_source, R.drawable.ic_view_source, event.root.toContentStringWithIndent())) if (event.isEncrypted()) { val decryptedContent = event.root.toClearContentStringWithIndent() ?: stringProvider.getString(R.string.encryption_information_decryption_error) @@ -209,11 +206,6 @@ class MessageMenuViewModel @AssistedInject constructor(@Assisted initialState: M } } - private fun canReact(event: TimelineEvent, messageContent: MessageContent?): Boolean { - //Only event of type Event.EVENT_TYPE_MESSAGE are supported for the moment - return event.root.getClearType() == EventType.MESSAGE - } - private fun canQuote(event: TimelineEvent, messageContent: MessageContent?): Boolean { //Only event of type Event.EVENT_TYPE_MESSAGE are supported for the moment if (event.root.getClearType() != EventType.MESSAGE) return false