mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 11:26:01 +03:00
Avoid usage of !!
This commit is contained in:
parent
1fcbf7ed42
commit
14e7e5e9fd
1 changed files with 23 additions and 25 deletions
|
@ -48,17 +48,14 @@ class OlmInboundGroupSessionWrapper2 : Serializable {
|
||||||
*/
|
*/
|
||||||
val firstKnownIndex: Long?
|
val firstKnownIndex: Long?
|
||||||
get() {
|
get() {
|
||||||
if (null != olmInboundGroupSession) {
|
return try {
|
||||||
try {
|
return olmInboundGroupSession?.firstKnownIndex
|
||||||
return olmInboundGroupSession!!.firstKnownIndex
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "## getFirstKnownIndex() : getFirstKnownIndex failed")
|
Timber.e(e, "## getFirstKnownIndex() : getFirstKnownIndex failed")
|
||||||
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
@ -90,11 +87,13 @@ class OlmInboundGroupSessionWrapper2 : Serializable {
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
constructor(megolmSessionData: MegolmSessionData) {
|
constructor(megolmSessionData: MegolmSessionData) {
|
||||||
try {
|
try {
|
||||||
olmInboundGroupSession = OlmInboundGroupSession.importSession(megolmSessionData.sessionKey!!)
|
val safeSessionKey = megolmSessionData.sessionKey ?: throw Exception("invalid data")
|
||||||
|
olmInboundGroupSession = OlmInboundGroupSession.importSession(safeSessionKey)
|
||||||
if (olmInboundGroupSession!!.sessionIdentifier() != megolmSessionData.sessionId) {
|
.also {
|
||||||
|
if (it.sessionIdentifier() != megolmSessionData.sessionId) {
|
||||||
throw Exception("Mismatched group session Id")
|
throw Exception("Mismatched group session Id")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
senderKey = megolmSessionData.senderKey
|
senderKey = megolmSessionData.senderKey
|
||||||
keysClaimed = megolmSessionData.senderClaimedKeys
|
keysClaimed = megolmSessionData.senderClaimedKeys
|
||||||
|
@ -120,16 +119,18 @@ class OlmInboundGroupSessionWrapper2 : Serializable {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
val wantedIndex = index ?: olmInboundGroupSession!!.firstKnownIndex
|
val safeOlmInboundGroupSession = olmInboundGroupSession ?: return null
|
||||||
|
|
||||||
|
val wantedIndex = index ?: safeOlmInboundGroupSession.firstKnownIndex
|
||||||
|
|
||||||
MegolmSessionData(
|
MegolmSessionData(
|
||||||
senderClaimedEd25519Key = keysClaimed?.get("ed25519"),
|
senderClaimedEd25519Key = keysClaimed?.get("ed25519"),
|
||||||
forwardingCurve25519KeyChain = ArrayList(forwardingCurve25519KeyChain!!),
|
forwardingCurve25519KeyChain = forwardingCurve25519KeyChain?.toList().orEmpty(),
|
||||||
senderKey = senderKey,
|
senderKey = senderKey,
|
||||||
senderClaimedKeys = keysClaimed,
|
senderClaimedKeys = keysClaimed,
|
||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
sessionId = olmInboundGroupSession!!.sessionIdentifier(),
|
sessionId = safeOlmInboundGroupSession.sessionIdentifier(),
|
||||||
sessionKey = olmInboundGroupSession!!.export(wantedIndex),
|
sessionKey = safeOlmInboundGroupSession.export(wantedIndex),
|
||||||
algorithm = MXCRYPTO_ALGORITHM_MEGOLM
|
algorithm = MXCRYPTO_ALGORITHM_MEGOLM
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -145,14 +146,11 @@ class OlmInboundGroupSessionWrapper2 : Serializable {
|
||||||
* @return the exported data
|
* @return the exported data
|
||||||
*/
|
*/
|
||||||
fun exportSession(messageIndex: Long): String? {
|
fun exportSession(messageIndex: Long): String? {
|
||||||
if (null != olmInboundGroupSession) {
|
return try {
|
||||||
try {
|
return olmInboundGroupSession?.export(messageIndex)
|
||||||
return olmInboundGroupSession!!.export(messageIndex)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "## exportSession() : export failed")
|
Timber.e(e, "## exportSession() : export failed")
|
||||||
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue