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 c6a58eeec1..5af5183dfa 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 @@ -50,21 +50,19 @@ interface RelationService { /** * Sends a reaction (emoji) to the targetedEvent. - * @param reaction the reaction (preferably emoji) * @param targetEventId the id of the event being reacted + * @param reaction the reaction (preferably emoji) */ - fun sendReaction(reaction: String, - targetEventId: String): Cancelable + fun sendReaction(targetEventId: String, + reaction: String): Cancelable /** * Undo a reaction (emoji) to the targetedEvent. - * @param reaction the reaction (preferably emoji) * @param targetEventId the id of the event being reacted - * @param myUserId used to know if a reaction event was made by the user + * @param reaction the reaction (preferably emoji) */ - fun undoReaction(reaction: String, - targetEventId: String, - myUserId: String) // : Cancelable + fun undoReaction(targetEventId: String, + reaction: String): Cancelable /** * Edit a text message body. Limited to "m.text" contentType @@ -92,7 +90,7 @@ interface RelationService { compatibilityBodyText: String = "* $newBodyText"): Cancelable /** - * Get's the edit history of the given event + * Get the edit history of the given event */ fun fetchEditHistory(eventId: String, callback: MatrixCallback>) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt index a66d50dfad..51c3527042 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/keysbackup/KeysBackup.kt @@ -50,6 +50,7 @@ import im.vector.matrix.android.internal.crypto.model.OlmInboundGroupSessionWrap import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.store.db.model.KeysBackupDataEntity import im.vector.matrix.android.internal.di.MoshiProvider +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.extensions.foldToCallback import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.task.Task @@ -77,6 +78,7 @@ import kotlin.random.Random @SessionScope internal class KeysBackup @Inject constructor( + @UserId private val userId: String, private val credentials: Credentials, private val cryptoStore: IMXCryptoStore, private val olmDevice: MXOlmDevice, @@ -375,8 +377,6 @@ internal class KeysBackup @Inject constructor( */ @WorkerThread private fun getKeysBackupTrustBg(keysBackupVersion: KeysVersionResult): KeysBackupVersionTrust { - val myUserId = credentials.userId - val keysBackupVersionTrust = KeysBackupVersionTrust() val authData = keysBackupVersion.getAuthDataAsMegolmBackupAuthData() @@ -388,7 +388,7 @@ internal class KeysBackup @Inject constructor( return keysBackupVersionTrust } - val mySigs = authData.signatures?.get(myUserId) + val mySigs = authData.signatures?.get(userId) if (mySigs.isNullOrEmpty()) { Timber.v("getKeysBackupTrust: Ignoring key backup because it lacks any signatures from this user") return keysBackupVersionTrust @@ -403,7 +403,7 @@ internal class KeysBackup @Inject constructor( } if (deviceId != null) { - val device = cryptoStore.getUserDevice(deviceId, myUserId) + val device = cryptoStore.getUserDevice(deviceId, userId) var isSignatureValid = false if (device == null) { @@ -450,10 +450,8 @@ internal class KeysBackup @Inject constructor( } else { GlobalScope.launch(coroutineDispatchers.main) { val updateKeysBackupVersionBody = withContext(coroutineDispatchers.crypto) { - val myUserId = credentials.userId - // Get current signatures, or create an empty set - val myUserSignatures = authData.signatures?.get(myUserId)?.toMutableMap() + val myUserSignatures = authData.signatures?.get(userId)?.toMutableMap() ?: HashMap() if (trust) { @@ -462,7 +460,7 @@ internal class KeysBackup @Inject constructor( val deviceSignatures = objectSigner.signObject(canonicalJson) - deviceSignatures[myUserId]?.forEach { entry -> + deviceSignatures[userId]?.forEach { entry -> myUserSignatures[entry.key] = entry.value } } else { @@ -478,7 +476,7 @@ internal class KeysBackup @Inject constructor( val newMegolmBackupAuthData = authData.copy() val newSignatures = newMegolmBackupAuthData.signatures!!.toMutableMap() - newSignatures[myUserId] = myUserSignatures + newSignatures[userId] = myUserSignatures newMegolmBackupAuthData.signatures = newSignatures @@ -1411,5 +1409,5 @@ internal class KeysBackup @Inject constructor( * DEBUG INFO * ========================================================================================== */ - override fun toString() = "KeysBackup for ${credentials.userId}" + override fun toString() = "KeysBackup for $userId" } 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 6abc7ed60e..68669171c7 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 @@ -65,7 +65,7 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv fun create(roomId: String): RelationService } - override fun sendReaction(reaction: String, targetEventId: String): Cancelable { + override fun sendReaction(targetEventId: String, reaction: String): Cancelable { val event = eventFactory.createReactionEvent(roomId, targetEventId, reaction) .also { saveLocalEcho(it) @@ -75,13 +75,13 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv return CancelableWork(context, sendRelationWork.id) } - override fun undoReaction(reaction: String, targetEventId: String, myUserId: String)/*: Cancelable*/ { + override fun undoReaction(targetEventId: String, reaction: String): Cancelable { val params = FindReactionEventForUndoTask.Params( roomId, targetEventId, - reaction, - myUserId + reaction ) + // TODO We should avoid using MatrixCallback internally val callback = object : MatrixCallback { override fun onSuccess(data: FindReactionEventForUndoTask.Result) { if (data.redactEventId == null) { @@ -89,7 +89,6 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv // TODO? } data.redactEventId?.let { toRedact -> - val redactEvent = eventFactory.createRedactEvent(roomId, toRedact, null).also { saveLocalEcho(it) } @@ -99,7 +98,7 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv } } } - findReactionEventForUndoTask + return findReactionEventForUndoTask .configureWith(params) { this.retryCount = Int.MAX_VALUE this.callback = callback diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/FindReactionEventForUndoTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/FindReactionEventForUndoTask.kt index 997ed18492..d1abf93c21 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/FindReactionEventForUndoTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/FindReactionEventForUndoTask.kt @@ -20,6 +20,7 @@ import im.vector.matrix.android.internal.database.model.EventAnnotationsSummaryE import im.vector.matrix.android.internal.database.model.EventEntity import im.vector.matrix.android.internal.database.model.ReactionAggregatedSummaryEntityFields import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.task.Task import io.realm.Realm import javax.inject.Inject @@ -29,8 +30,7 @@ internal interface FindReactionEventForUndoTask : Task - getReactionToRedact(realm, params.reaction, params.eventId, params.myUserId)?.eventId + getReactionToRedact(realm, params.reaction, params.eventId)?.eventId } return FindReactionEventForUndoTask.Result(eventId) } - private fun getReactionToRedact(realm: Realm, reaction: String, eventId: String, userId: String): EventEntity? { + private fun getReactionToRedact(realm: Realm, reaction: String, eventId: String): EventEntity? { val summary = EventAnnotationsSummaryEntity.where(realm, eventId).findFirst() if (summary != null) { summary.reactionsSummary.where() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/UpdateQuickReactionTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/UpdateQuickReactionTask.kt index e4b71c0d42..6ec316e9a4 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/UpdateQuickReactionTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/UpdateQuickReactionTask.kt @@ -20,6 +20,7 @@ import im.vector.matrix.android.internal.database.model.EventAnnotationsSummaryE import im.vector.matrix.android.internal.database.model.EventEntity import im.vector.matrix.android.internal.database.model.ReactionAggregatedSummaryEntityFields import im.vector.matrix.android.internal.database.query.where +import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.task.Task import io.realm.Realm import javax.inject.Inject @@ -30,8 +31,7 @@ internal interface UpdateQuickReactionTask : Task?>? = null monarchy.doWithRealm { realm -> - res = updateQuickReaction(realm, params.reaction, params.oppositeReaction, params.eventId, params.myUserId) + res = updateQuickReaction(realm, params.reaction, params.oppositeReaction, params.eventId) } return UpdateQuickReactionTask.Result(res?.first, res?.second ?: emptyList()) } - private fun updateQuickReaction(realm: Realm, reaction: String, oppositeReaction: String, eventId: String, myUserId: String): Pair?> { + private fun updateQuickReaction(realm: Realm, reaction: String, oppositeReaction: String, eventId: String): Pair?> { // the emoji reaction has been selected, we need to check if we have reacted it or not val existingSummary = EventAnnotationsSummaryEntity.where(realm, eventId).findFirst() ?: return Pair(reaction, null) @@ -68,7 +69,7 @@ internal class DefaultUpdateQuickReactionTask @Inject constructor(private val mo val toRedact = aggregationForOppositeReaction?.sourceEvents?.mapNotNull { // find source event val entity = EventEntity.where(realm, it).findFirst() - if (entity?.sender == myUserId) entity.eventId else null + if (entity?.sender == userId) entity.eventId else null } return Pair(reaction, toRedact) } else { @@ -77,7 +78,7 @@ internal class DefaultUpdateQuickReactionTask @Inject constructor(private val mo val toRedact = aggregationForReaction.sourceEvents.mapNotNull { // find source event val entity = EventEntity.where(realm, it).findFirst() - if (entity?.sender == myUserId) entity.eventId else null + if (entity?.sender == userId) entity.eventId else null } return Pair(null, toRedact) } diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt index 882e171e4a..42e7e850b3 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushrulesConditionTest.kt @@ -342,11 +342,11 @@ class PushrulesConditionTest { TODO("not implemented") // To change body of created functions use File | Settings | File Templates. } - override fun sendReaction(reaction: String, targetEventId: String): Cancelable { + override fun sendReaction(targetEventId: String, reaction: String): Cancelable { TODO("not implemented") // To change body of created functions use File | Settings | File Templates. } - override fun undoReaction(reaction: String, targetEventId: String, myUserId: String) { + override fun undoReaction(targetEventId: String, reaction: String): Cancelable { TODO("not implemented") // To change body of created functions use File | Settings | File Templates. } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailActions.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailActions.kt index d42af3e50a..d032182994 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailActions.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailActions.kt @@ -30,9 +30,9 @@ sealed class RoomDetailActions { data class TimelineEventTurnsVisible(val event: TimelineEvent) : RoomDetailActions() data class TimelineEventTurnsInvisible(val event: TimelineEvent) : RoomDetailActions() data class LoadMoreTimelineEvents(val direction: Timeline.Direction) : RoomDetailActions() - data class SendReaction(val reaction: String, val targetEventId: String) : RoomDetailActions() + data class SendReaction(val targetEventId: String, val reaction: String) : RoomDetailActions() + data class UndoReaction(val targetEventId: String, val reaction: String, val reason: String? = "") : RoomDetailActions() data class RedactAction(val targetEventId: String, val reason: String? = "") : RoomDetailActions() - data class UndoReaction(val targetEventId: String, val key: String, val reason: String? = "") : RoomDetailActions() data class UpdateQuickReactAction(val targetEventId: String, val selectedReaction: String, val add: Boolean) : RoomDetailActions() data class NavigateToEvent(val eventId: String, val highlight: Boolean) : RoomDetailActions() data class SetReadMarkerAction(val eventId: String) : RoomDetailActions() diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 6907af9ff6..f09fbff09f 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -420,7 +420,7 @@ class RoomDetailFragment : val eventId = data.getStringExtra(EmojiReactionPickerActivity.EXTRA_EVENT_ID) ?: return val reaction = data.getStringExtra(EmojiReactionPickerActivity.EXTRA_REACTION_RESULT) ?: return // TODO check if already reacted with that? - roomDetailViewModel.process(RoomDetailActions.SendReaction(reaction, eventId)) + roomDetailViewModel.process(RoomDetailActions.SendReaction(eventId, reaction)) } } } @@ -909,7 +909,7 @@ class RoomDetailFragment : override fun onClickOnReactionPill(informationData: MessageInformationData, reaction: String, on: Boolean) { if (on) { // we should test the current real state of reaction on this event - roomDetailViewModel.process(RoomDetailActions.SendReaction(reaction, informationData.eventId)) + roomDetailViewModel.process(RoomDetailActions.SendReaction(informationData.eventId, reaction)) } else { // I need to redact a reaction roomDetailViewModel.process(RoomDetailActions.UndoReaction(informationData.eventId, reaction)) 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 7db9fc41d5..57a2c76f61 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 @@ -445,7 +445,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } private fun handleSendReaction(action: RoomDetailActions.SendReaction) { - room.sendReaction(action.reaction, action.targetEventId) + room.sendReaction(action.targetEventId, action.reaction) } private fun handleRedactEvent(action: RoomDetailActions.RedactAction) { @@ -454,14 +454,14 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } private fun handleUndoReact(action: RoomDetailActions.UndoReaction) { - room.undoReaction(action.key, action.targetEventId, session.myUserId) + room.undoReaction(action.targetEventId, action.reaction) } private fun handleUpdateQuickReaction(action: RoomDetailActions.UpdateQuickReactAction) { if (action.add) { - room.sendReaction(action.selectedReaction, action.targetEventId) + room.sendReaction(action.targetEventId, action.selectedReaction) } else { - room.undoReaction(action.selectedReaction, action.targetEventId, session.myUserId) + room.undoReaction(action.targetEventId, action.selectedReaction) } }