mirror of
https://github.com/element-hq/element-android
synced 2024-11-25 02:45:37 +03:00
Code robustness (avoid using !!)
This commit is contained in:
parent
08e4b4473c
commit
17e028178e
3 changed files with 23 additions and 20 deletions
|
@ -64,15 +64,17 @@ data class IncomingRoomKeyRequest(
|
||||||
*
|
*
|
||||||
* @param event the event
|
* @param event the event
|
||||||
*/
|
*/
|
||||||
fun fromEvent(event: Event): IncomingRoomKeyRequest {
|
fun fromEvent(event: Event): IncomingRoomKeyRequest? {
|
||||||
val roomKeyShareRequest = event.getClearContent().toModel<RoomKeyShareRequest>()!!
|
return event.getClearContent()
|
||||||
|
.toModel<RoomKeyShareRequest>()
|
||||||
return IncomingRoomKeyRequest(
|
?.let {
|
||||||
userId = event.senderId,
|
IncomingRoomKeyRequest(
|
||||||
deviceId = roomKeyShareRequest.requestingDeviceId,
|
userId = event.senderId,
|
||||||
requestId = roomKeyShareRequest.requestId,
|
deviceId = it.requestingDeviceId,
|
||||||
requestBody = roomKeyShareRequest.body ?: RoomKeyRequestBody()
|
requestId = it.requestId,
|
||||||
)
|
requestBody = it.body ?: RoomKeyRequestBody()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,20 +40,21 @@ data class IncomingRoomKeyRequestCancellation(
|
||||||
override val requestId: String? = null
|
override val requestId: String? = null
|
||||||
) : IncomingRoomKeyRequestCommon {
|
) : IncomingRoomKeyRequestCommon {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory
|
* Factory
|
||||||
*
|
*
|
||||||
* @param event the event
|
* @param event the event
|
||||||
*/
|
*/
|
||||||
fun fromEvent(event: Event): IncomingRoomKeyRequestCancellation {
|
fun fromEvent(event: Event): IncomingRoomKeyRequestCancellation? {
|
||||||
val roomKeyShareRequestCancellation = event.getClearContent().toModel<RoomKeyShareCancellation>()!!
|
return event.getClearContent()
|
||||||
|
.toModel<RoomKeyShareCancellation>()
|
||||||
return IncomingRoomKeyRequestCancellation(
|
?.let {
|
||||||
userId = event.senderId,
|
IncomingRoomKeyRequestCancellation(
|
||||||
deviceId = roomKeyShareRequestCancellation.requestingDeviceId,
|
userId = event.senderId,
|
||||||
requestId = roomKeyShareRequestCancellation.requestId
|
deviceId = it.requestingDeviceId,
|
||||||
)
|
requestId = it.requestId
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,8 @@ internal class IncomingRoomKeyRequestManager @Inject constructor(
|
||||||
fun onRoomKeyRequestEvent(event: Event) {
|
fun onRoomKeyRequestEvent(event: Event) {
|
||||||
val roomKeyShare = event.getClearContent().toModel<RoomKeyShare>()
|
val roomKeyShare = event.getClearContent().toModel<RoomKeyShare>()
|
||||||
when (roomKeyShare?.action) {
|
when (roomKeyShare?.action) {
|
||||||
RoomKeyShare.ACTION_SHARE_REQUEST -> receivedRoomKeyRequests.add(IncomingRoomKeyRequest.fromEvent(event))
|
RoomKeyShare.ACTION_SHARE_REQUEST -> IncomingRoomKeyRequest.fromEvent(event)?.let { receivedRoomKeyRequests.add(it) }
|
||||||
RoomKeyShare.ACTION_SHARE_CANCELLATION -> receivedRoomKeyRequestCancellations.add(IncomingRoomKeyRequestCancellation.fromEvent(event))
|
RoomKeyShare.ACTION_SHARE_CANCELLATION -> IncomingRoomKeyRequestCancellation.fromEvent(event)?.let { receivedRoomKeyRequestCancellations.add(it) }
|
||||||
else -> Timber.e("## onRoomKeyRequestEvent() : unsupported action ${roomKeyShare?.action}")
|
else -> Timber.e("## onRoomKeyRequestEvent() : unsupported action ${roomKeyShare?.action}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue