From a3ec0e03a04eeba15dc29c661642c999ad11fbaa Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 5 Feb 2020 12:05:12 +0100 Subject: [PATCH] Use NoOpMatrixCallback when it's possible --- .../internal/crypto/DefaultCryptoService.kt | 3 ++- .../android/internal/task/ConfigurableTask.kt | 3 ++- .../settings/KeysBackupSettingsViewModel.kt | 3 ++- .../home/room/detail/RoomDetailViewModel.kt | 14 +++++++------- .../features/home/room/list/RoomListViewModel.kt | 3 ++- .../notifications/NotificationBroadcastReceiver.kt | 8 ++++---- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt index 7d6a4e8eff..a422394f16 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DefaultCryptoService.kt @@ -26,6 +26,7 @@ import com.squareup.moshi.Types import com.zhuinden.monarchy.Monarchy import dagger.Lazy import im.vector.matrix.android.api.MatrixCallback +import im.vector.matrix.android.api.NoOpMatrixCallback import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.api.listeners.ProgressListener @@ -189,7 +190,7 @@ internal class DefaultCryptoService @Inject constructor( this.callback = object : MatrixCallback { override fun onSuccess(data: Unit) { // bg refresh of crypto device - downloadKeys(listOf(credentials.userId), true, object : MatrixCallback> {}) + downloadKeys(listOf(credentials.userId), true, NoOpMatrixCallback()) callback.onSuccess(data) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/ConfigurableTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/ConfigurableTask.kt index 1f8cb5cc60..dce6f5f951 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/ConfigurableTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/task/ConfigurableTask.kt @@ -17,6 +17,7 @@ package im.vector.matrix.android.internal.task import im.vector.matrix.android.api.MatrixCallback +import im.vector.matrix.android.api.NoOpMatrixCallback import im.vector.matrix.android.api.util.Cancelable import java.util.UUID @@ -47,7 +48,7 @@ internal data class ConfigurableTask( var callbackThread: TaskThread = TaskThread.MAIN, var executionThread: TaskThread = TaskThread.IO, var retryCount: Int = 0, - var callback: MatrixCallback = object : MatrixCallback {} + var callback: MatrixCallback = NoOpMatrixCallback() ) { fun build() = ConfigurableTask( diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/settings/KeysBackupSettingsViewModel.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/settings/KeysBackupSettingsViewModel.kt index bed18ae99d..e4bbd39684 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/settings/KeysBackupSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/settings/KeysBackupSettingsViewModel.kt @@ -19,6 +19,7 @@ import com.airbnb.mvrx.* import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import im.vector.matrix.android.api.MatrixCallback +import im.vector.matrix.android.api.NoOpMatrixCallback import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupService import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupState @@ -68,7 +69,7 @@ class KeysBackupSettingsViewModel @AssistedInject constructor(@Assisted initialS } private fun init() { - keysBackupService.forceUsingLastVersion(object : MatrixCallback {}) + keysBackupService.forceUsingLastVersion(NoOpMatrixCallback()) } private fun getKeysBackupTrust() = withState { state -> 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 0eee1eaccd..6080ae6332 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 @@ -158,7 +158,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro observeUnreadState() observeMyRoomMember() room.getRoomSummaryLive() - room.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT, object : MatrixCallback {}) + room.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT, NoOpMatrixCallback()) room.rx(session).loadRoomMembersIfNeeded().subscribeLogError().disposeOnClear() // Inform the SDK that the room is displayed session.onRoomDisplayed(initialState.roomId) @@ -225,7 +225,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro private fun stopTrackingUnreadMessages() { if (trackUnreadMessages.getAndSet(false)) { mostRecentDisplayedEvent?.root?.eventId?.also { - room.setReadMarker(it, callback = object : MatrixCallback {}) + room.setReadMarker(it, callback = NoOpMatrixCallback()) } mostRecentDisplayedEvent = null } @@ -525,7 +525,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } private fun popDraft() { - room.deleteDraft(object : MatrixCallback {}) + room.deleteDraft(NoOpMatrixCallback()) } private fun legacyRiotQuoteText(quotedText: String?, myText: String): String { @@ -631,11 +631,11 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } private fun handleRejectInvite() { - room.leave(null, object : MatrixCallback {}) + room.leave(null, NoOpMatrixCallback()) } private fun handleAcceptInvite() { - room.join(callback = object : MatrixCallback {}) + room.join(callback = NoOpMatrixCallback()) } private fun handleEditAction(action: RoomDetailAction.EnterEditMode) { @@ -808,14 +808,14 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } } bufferedMostRecentDisplayedEvent.root.eventId?.let { eventId -> - room.setReadReceipt(eventId, callback = object : MatrixCallback {}) + room.setReadReceipt(eventId, callback = NoOpMatrixCallback()) } }) .disposeOnClear() } private fun handleMarkAllAsRead() { - room.markAsRead(ReadService.MarkAsReadParams.BOTH, object : MatrixCallback {}) + room.markAsRead(ReadService.MarkAsReadParams.BOTH, NoOpMatrixCallback()) } private fun handleReportContent(action: RoomDetailAction.ReportContent) { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewModel.kt index 397df50c2b..22c18e9134 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/list/RoomListViewModel.kt @@ -20,6 +20,7 @@ import com.airbnb.mvrx.FragmentViewModelContext import com.airbnb.mvrx.MvRxViewModelFactory import com.airbnb.mvrx.ViewModelContext import im.vector.matrix.android.api.MatrixCallback +import im.vector.matrix.android.api.NoOpMatrixCallback import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.room.model.Membership import im.vector.matrix.android.api.session.room.model.RoomSummary @@ -182,7 +183,7 @@ class RoomListViewModel @Inject constructor(initialState: RoomListViewState, ?.filter { it.membership == Membership.JOIN } ?.map { it.roomId } ?.toList() - ?.let { session.markAllAsRead(it, object : MatrixCallback {}) } + ?.let { session.markAllAsRead(it, NoOpMatrixCallback()) } } private fun handleChangeNotificationMode(action: RoomListAction.ChangeRoomNotificationState) { diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt index 816e0dc0ad..53d69bce2d 100644 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt @@ -20,7 +20,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import androidx.core.app.RemoteInput -import im.vector.matrix.android.api.MatrixCallback +import im.vector.matrix.android.api.NoOpMatrixCallback import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.room.Room import im.vector.matrix.android.api.session.room.read.ReadService @@ -75,21 +75,21 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { private fun handleJoinRoom(roomId: String) { activeSessionHolder.getSafeActiveSession()?.let { session -> session.getRoom(roomId) - ?.join(callback = object : MatrixCallback {}) + ?.join(callback = NoOpMatrixCallback()) } } private fun handleRejectRoom(roomId: String) { activeSessionHolder.getSafeActiveSession()?.let { session -> session.getRoom(roomId) - ?.leave(callback = object : MatrixCallback {}) + ?.leave(callback = NoOpMatrixCallback()) } } private fun handleMarkAsRead(roomId: String) { activeSessionHolder.getActiveSession().let { session -> session.getRoom(roomId) - ?.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT, object : MatrixCallback {}) + ?.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT, NoOpMatrixCallback()) } }