Browse Source

Enable detekt rules `UseLet` and fix existing issues.

pull/967/head
Benoit Marty 1 year ago committed by Benoit Marty
parent
commit
495d6020ad
  1. 11
      libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/room/MatrixRoomMembers.kt
  2. 18
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandler.kt
  3. 2
      tools/detekt/detekt.yml

11
libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/room/MatrixRoomMembers.kt

@ -57,14 +57,9 @@ fun MatrixRoom.getDirectRoomMember(roomMembersState: MatrixRoomMembersState): St @@ -57,14 +57,9 @@ fun MatrixRoom.getDirectRoomMember(roomMembersState: MatrixRoomMembersState): St
val roomMembers = roomMembersState.roomMembers()
return remember(roomMembersState) {
derivedStateOf {
if (roomMembers == null) {
null
} else if (roomMembers.size == 2 && isDirect && isEncrypted) {
roomMembers.find { it.userId != this.sessionId }
} else {
null
}
roomMembers
?.takeIf { it.size == 2 && isDirect && isEncrypted }
?.find { it.userId != sessionId }
}
}
}

18
libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandler.kt

@ -100,15 +100,15 @@ class DefaultPushHandler @Inject constructor( @@ -100,15 +100,15 @@ class DefaultPushHandler @Inject constructor(
}
val clientSecret = pushData.clientSecret
val userId = if (clientSecret == null) {
// Should not happen. In this case, restore default session
null
} else {
// Get userId from client secret
pushClientSecret.getUserIdFromSecret(clientSecret)
} ?: run {
matrixAuthenticationService.getLatestSessionId()
}
// clientSecret should not be null. If this happens, restore default session
val userId = clientSecret
?.let {
// Get userId from client secret
pushClientSecret.getUserIdFromSecret(clientSecret)
}
?: run {
matrixAuthenticationService.getLatestSessionId()
}
if (userId == null) {
Timber.w("Unable to get a session")

2
tools/detekt/detekt.yml

@ -63,6 +63,8 @@ style: @@ -63,6 +63,8 @@ style:
UseDataClass:
active: true
allowVars: false
UseLet:
active: true
coroutines:
GlobalCoroutineUsage:

Loading…
Cancel
Save