From 1ee1c31b9c43b34daccdde71e4597520b2ecaa85 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 3 Jul 2019 15:40:31 +0200 Subject: [PATCH] Fix bugs detected by Sonar --- .../crypto/model/MXUsersDevicesMap.java | 8 ++---- .../db/model/IncomingRoomKeyRequestEntity.kt | 12 ++++---- .../notifications/NotifiableEventResolver.kt | 28 ++++++++----------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/MXUsersDevicesMap.java b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/MXUsersDevicesMap.java index ff12514146..a6e4580e94 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/MXUsersDevicesMap.java +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/model/MXUsersDevicesMap.java @@ -175,16 +175,12 @@ public class MXUsersDevicesMap implements Serializable { } } - public boolean isEmpty(){ + public boolean isEmpty() { return mMap.isEmpty(); } @Override public String toString() { - if (null != mMap) { - return "MXUsersDevicesMap " + mMap.toString(); - } else { - return "MXDeviceInfo : null map"; - } + return "MXUsersDevicesMap " + mMap.toString(); } } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/model/IncomingRoomKeyRequestEntity.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/model/IncomingRoomKeyRequestEntity.kt index eb2c250fab..707418ab7e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/model/IncomingRoomKeyRequestEntity.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/store/db/model/IncomingRoomKeyRequestEntity.kt @@ -16,9 +16,9 @@ package im.vector.matrix.android.internal.crypto.store.db.model -import io.realm.RealmObject import im.vector.matrix.android.internal.crypto.IncomingRoomKeyRequest import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyRequestBody +import io.realm.RealmObject internal open class IncomingRoomKeyRequestEntity( var requestId: String? = null, @@ -32,11 +32,11 @@ internal open class IncomingRoomKeyRequestEntity( ) : RealmObject() { fun toIncomingRoomKeyRequest(): IncomingRoomKeyRequest { - return IncomingRoomKeyRequest().apply { - requestId = requestId - userId = userId - deviceId = deviceId - requestBody = RoomKeyRequestBody().apply { + return IncomingRoomKeyRequest().also { + it.requestId = requestId + it.userId = userId + it.deviceId = deviceId + it.requestBody = RoomKeyRequestBody().apply { algorithm = requestBodyAlgorithm roomId = requestBodyRoomId senderKey = requestBodySenderKey diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotifiableEventResolver.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotifiableEventResolver.kt index 2ab3c03005..14d64d444c 100644 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotifiableEventResolver.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotifiableEventResolver.kt @@ -63,6 +63,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St else -> { //If the event can be displayed, display it as is + Timber.w("NotifiableEventResolver Received an unsupported event matching a bing rule") //TODO Better event text display val bodyPreview = event.type @@ -75,11 +76,6 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St title = stringProvider.getString(R.string.notification_unknown_new_event), soundName = null, type = event.type) - - - //Unsupported event - Timber.w("NotifiableEventResolver Received an unsupported event matching a bing rule") - return null } } } @@ -96,8 +92,8 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St // Ok room is not known in store, but we can still display something val body = event.annotations?.editSummary?.aggregatedContent?.toModel()?.body - ?: event.root.getClearContent().toModel()?.body - ?: stringProvider.getString(R.string.notification_unknown_new_event) + ?: event.root.getClearContent().toModel()?.body + ?: stringProvider.getString(R.string.notification_unknown_new_event) val roomName = stringProvider.getString(R.string.notification_unknown_room_name) val senderDisplayName = event.senderName ?: event.root.senderId @@ -115,8 +111,8 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St return notifiableEvent } else { val body = event.annotations?.editSummary?.aggregatedContent?.toModel()?.body - ?: event.root.getClearContent().toModel()?.body - ?: stringProvider.getString(R.string.notification_unknown_new_event) + ?: event.root.getClearContent().toModel()?.body + ?: stringProvider.getString(R.string.notification_unknown_new_event) val roomName = room.roomSummary()?.displayName ?: "" val senderDisplayName = event.senderName ?: event.root.senderId @@ -138,15 +134,15 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St // TODO They will be not displayed the first time (known limitation) notifiableEvent.roomAvatarPath = session.contentUrlResolver() .resolveThumbnail(room.roomSummary()?.avatarUrl, - 250, - 250, - ContentUrlResolver.ThumbnailMethod.SCALE) + 250, + 250, + ContentUrlResolver.ThumbnailMethod.SCALE) notifiableEvent.senderAvatarPath = session.contentUrlResolver() .resolveThumbnail(event.senderAvatar, - 250, - 250, - ContentUrlResolver.ThumbnailMethod.SCALE) + 250, + 250, + ContentUrlResolver.ThumbnailMethod.SCALE) return notifiableEvent } @@ -159,7 +155,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St val dName = event.senderId?.let { session.getUser(it)?.displayName } if (Membership.INVITE == content.membership) { val body = noticeEventFormatter.format(event, dName) - ?: stringProvider.getString(R.string.notification_new_invitation) + ?: stringProvider.getString(R.string.notification_new_invitation) return InviteNotifiableEvent( session.sessionParams.credentials.userId, eventId = event.eventId!!,