mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 02:15:35 +03:00
Kotlin: use orEmpty()
This commit is contained in:
parent
e793a46576
commit
691e7fe616
19 changed files with 26 additions and 26 deletions
|
@ -76,7 +76,7 @@ fun RegistrationFlowResponse.toFlowResult(): FlowResult {
|
|||
this.flows?.forEach { it.stages?.mapTo(allFlowTypes) { type -> type } }
|
||||
|
||||
allFlowTypes.forEach { type ->
|
||||
val isMandatory = flows?.all { type in it.stages ?: emptyList() } == true
|
||||
val isMandatory = flows?.all { type in it.stages.orEmpty() } == true
|
||||
|
||||
val stage = when (type) {
|
||||
LoginFlowTypes.RECAPTCHA -> Stage.ReCaptcha(isMandatory, ((params?.get(type) as? Map<*, *>)?.get("public_key") as? String)
|
||||
|
@ -88,7 +88,7 @@ fun RegistrationFlowResponse.toFlowResult(): FlowResult {
|
|||
else -> Stage.Other(isMandatory, type, (params?.get(type) as? Map<*, *>))
|
||||
}
|
||||
|
||||
if (type in completedStages ?: emptyList()) {
|
||||
if (type in completedStages.orEmpty()) {
|
||||
completedStage.add(stage)
|
||||
} else {
|
||||
missingStage.add(stage)
|
||||
|
|
|
@ -262,7 +262,7 @@ internal class DefaultCryptoService @Inject constructor(
|
|||
|
||||
override fun onSuccess(data: DevicesListResponse) {
|
||||
// Save in local DB
|
||||
cryptoStore.saveMyDevicesInfo(data.devices ?: emptyList())
|
||||
cryptoStore.saveMyDevicesInfo(data.devices.orEmpty())
|
||||
callback.onSuccess(data)
|
||||
}
|
||||
}
|
||||
|
@ -446,7 +446,7 @@ internal class DefaultCryptoService @Inject constructor(
|
|||
}
|
||||
|
||||
override fun getCryptoDeviceInfo(userId: String): List<CryptoDeviceInfo> {
|
||||
return cryptoStore.getUserDeviceList(userId) ?: emptyList()
|
||||
return cryptoStore.getUserDeviceList(userId).orEmpty()
|
||||
}
|
||||
|
||||
override fun getLiveCryptoDeviceInfo(): LiveData<List<CryptoDeviceInfo>> {
|
||||
|
|
|
@ -34,7 +34,7 @@ internal class EnsureOlmSessionsForUsersAction @Inject constructor(private val o
|
|||
suspend fun handle(users: List<String>): MXUsersDevicesMap<MXOlmSessionResult> {
|
||||
Timber.v("## ensureOlmSessionsForUsers() : ensureOlmSessionsForUsers $users")
|
||||
val devicesByUser = users.associateWith { userId ->
|
||||
val devices = cryptoStore.getUserDevices(userId)?.values ?: emptyList()
|
||||
val devices = cryptoStore.getUserDevices(userId)?.values.orEmpty()
|
||||
|
||||
devices.filter {
|
||||
// Don't bother setting up session to ourself
|
||||
|
|
|
@ -103,7 +103,7 @@ internal class MXMegolmDecryption(private val userId: String,
|
|||
senderCurve25519Key = olmDecryptionResult.senderKey,
|
||||
claimedEd25519Key = olmDecryptionResult.keysClaimed?.get("ed25519"),
|
||||
forwardingCurve25519KeyChain = olmDecryptionResult.forwardingCurve25519KeyChain
|
||||
?: emptyList()
|
||||
.orEmpty()
|
||||
)
|
||||
} else {
|
||||
throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON)
|
||||
|
|
|
@ -44,7 +44,7 @@ internal class MXOlmEncryption(
|
|||
ensureSession(userIds)
|
||||
val deviceInfos = ArrayList<CryptoDeviceInfo>()
|
||||
for (userId in userIds) {
|
||||
val devices = cryptoStore.getUserDevices(userId)?.values ?: emptyList()
|
||||
val devices = cryptoStore.getUserDevices(userId)?.values.orEmpty()
|
||||
for (device in devices) {
|
||||
val key = device.identityKey()
|
||||
if (key == olmDevice.deviceCurve25519Key) {
|
||||
|
|
|
@ -450,7 +450,7 @@ internal class RealmCryptoStore @Inject constructor(
|
|||
}
|
||||
)
|
||||
return Transformations.map(liveData) {
|
||||
it.firstOrNull() ?: emptyList()
|
||||
it.firstOrNull().orEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -480,7 +480,7 @@ internal class RealmCryptoStore @Inject constructor(
|
|||
}
|
||||
)
|
||||
return Transformations.map(liveData) {
|
||||
it.firstOrNull() ?: emptyList()
|
||||
it.firstOrNull().orEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ internal object PushRulesMapper {
|
|||
|
||||
private fun fromActionStr(actionsStr: String?): List<Any> {
|
||||
try {
|
||||
return actionsStr?.let { moshiActionsAdapter.fromJson(it) } ?: emptyList()
|
||||
return actionsStr?.let { moshiActionsAdapter.fromJson(it) }.orEmpty()
|
||||
} catch (e: Throwable) {
|
||||
Timber.e(e, "## failed to map push rule actions <$actionsStr>")
|
||||
return emptyList()
|
||||
|
|
|
@ -49,7 +49,7 @@ internal class RoomSummaryMapper @Inject constructor(private val timelineEventMa
|
|||
membership = roomSummaryEntity.membership,
|
||||
versioningState = roomSummaryEntity.versioningState,
|
||||
readMarkerId = roomSummaryEntity.readMarkerId,
|
||||
userDrafts = roomSummaryEntity.userDrafts?.userDrafts?.map { DraftMapper.map(it) } ?: emptyList(),
|
||||
userDrafts = roomSummaryEntity.userDrafts?.userDrafts?.map { DraftMapper.map(it) }.orEmpty(),
|
||||
canonicalAlias = roomSummaryEntity.canonicalAlias,
|
||||
aliases = roomSummaryEntity.aliases.toList(),
|
||||
isEncrypted = roomSummaryEntity.isEncrypted,
|
||||
|
|
|
@ -49,7 +49,7 @@ internal class TimelineEventMapper @Inject constructor(private val readReceiptsS
|
|||
it.user
|
||||
}?.sortedByDescending {
|
||||
it.originServerTs
|
||||
} ?: emptyList()
|
||||
}.orEmpty()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ internal class RoomSummaryUpdater @Inject constructor(
|
|||
?.canonicalAlias
|
||||
|
||||
val roomAliases = ContentMapper.map(lastAliasesEvent?.content).toModel<RoomAliasesContent>()?.aliases
|
||||
?: emptyList()
|
||||
.orEmpty()
|
||||
roomSummaryEntity.aliases.clear()
|
||||
roomSummaryEntity.aliases.addAll(roomAliases)
|
||||
roomSummaryEntity.flatAliases = roomAliases.joinToString(separator = "|", prefix = "|")
|
||||
|
|
|
@ -143,7 +143,7 @@ class DraftRepository @Inject constructor(private val monarchy: Monarchy) {
|
|||
}
|
||||
)
|
||||
return Transformations.map(liveData) {
|
||||
it.firstOrNull() ?: emptyList()
|
||||
it.firstOrNull().orEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ internal class DefaultReadService @AssistedInject constructor(
|
|||
{ readReceiptsSummaryMapper.map(it) }
|
||||
)
|
||||
return Transformations.map(liveRealmData) {
|
||||
it.firstOrNull() ?: emptyList()
|
||||
it.firstOrNull().orEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ internal class DefaultUpdateQuickReactionTask @Inject constructor(private val mo
|
|||
monarchy.doWithRealm { realm ->
|
||||
res = updateQuickReaction(realm, params.reaction, params.oppositeReaction, params.eventId)
|
||||
}
|
||||
return UpdateQuickReactionTask.Result(res?.first, res?.second ?: emptyList())
|
||||
return UpdateQuickReactionTask.Result(res?.first, res?.second.orEmpty())
|
||||
}
|
||||
|
||||
private fun updateQuickReaction(realm: Realm, reaction: String, oppositeReaction: String, eventId: String): Pair<String?, List<String>?> {
|
||||
|
|
|
@ -44,7 +44,7 @@ data class TermsResponse(
|
|||
version = tos[VERSION] as? String
|
||||
)
|
||||
}
|
||||
}?.filterNotNull() ?: emptyList()
|
||||
}?.filterNotNull().orEmpty()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
|
|
@ -43,7 +43,7 @@ class AttachmentsPreviewActivity : VectorBaseActivity(), ToolbarConfigurable {
|
|||
}
|
||||
|
||||
fun getOutput(intent: Intent): List<ContentAttachmentData> {
|
||||
return intent.getParcelableArrayListExtra(ATTACHMENTS_PREVIEW_RESULT) ?: emptyList()
|
||||
return intent.getParcelableArrayListExtra<ContentAttachmentData>(ATTACHMENTS_PREVIEW_RESULT).orEmpty()
|
||||
}
|
||||
|
||||
fun getKeepOriginalSize(intent: Intent): Boolean {
|
||||
|
|
|
@ -151,8 +151,8 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
|
|||
|
||||
private fun changeThreePidState(threePid: ThreePid, state: Async<SharedState>) {
|
||||
setState {
|
||||
val currentMails = emailList() ?: emptyList()
|
||||
val phones = phoneNumbersList() ?: emptyList()
|
||||
val currentMails = emailList().orEmpty()
|
||||
val phones = phoneNumbersList().orEmpty()
|
||||
copy(
|
||||
emailList = Success(
|
||||
currentMails.map {
|
||||
|
@ -178,8 +178,8 @@ class DiscoverySettingsViewModel @AssistedInject constructor(
|
|||
|
||||
private fun changeThreePidSubmitState(threePid: ThreePid, submitState: Async<Unit>) {
|
||||
setState {
|
||||
val currentMails = emailList() ?: emptyList()
|
||||
val phones = phoneNumbersList() ?: emptyList()
|
||||
val currentMails = emailList().orEmpty()
|
||||
val phones = phoneNumbersList().orEmpty()
|
||||
copy(
|
||||
emailList = Success(
|
||||
currentMails.map {
|
||||
|
|
|
@ -123,12 +123,12 @@ class HomeDetailFragment @Inject constructor(
|
|||
?.navigator
|
||||
?.requestSessionVerification(requireContext(), newest.deviceId ?: "")
|
||||
unknownDeviceDetectorSharedViewModel.handle(
|
||||
UnknownDeviceDetectorSharedViewModel.Action.IgnoreDevice(newest.deviceId?.let { listOf(it) } ?: emptyList())
|
||||
UnknownDeviceDetectorSharedViewModel.Action.IgnoreDevice(newest.deviceId?.let { listOf(it) }.orEmpty())
|
||||
)
|
||||
}
|
||||
dismissedAction = Runnable {
|
||||
unknownDeviceDetectorSharedViewModel.handle(
|
||||
UnknownDeviceDetectorSharedViewModel.Action.IgnoreDevice(newest.deviceId?.let { listOf(it) } ?: emptyList())
|
||||
UnknownDeviceDetectorSharedViewModel.Action.IgnoreDevice(newest.deviceId?.let { listOf(it) }.orEmpty())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -382,7 +382,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
|
|||
fun getUnknownDeviceDismissedList(): List<String> {
|
||||
return tryThis {
|
||||
defaultPrefs.getStringSet(SETTINGS_UNKNOWN_DEVICE_DISMISSED_LIST, null)?.toList()
|
||||
} ?: emptyList()
|
||||
}.orEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -415,7 +415,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
|
|||
session.cryptoService().fetchDevicesList(object : MatrixCallback<DevicesListResponse> {
|
||||
override fun onSuccess(data: DevicesListResponse) {
|
||||
if (isAdded) {
|
||||
refreshCryptographyPreference(data.devices ?: emptyList())
|
||||
refreshCryptographyPreference(data.devices.orEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue