mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Merge pull request #1401 from vector-im/feature/cleanup
Small PR with code cleanup
This commit is contained in:
commit
860595520b
@ -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>> {
|
||||
|
@ -137,7 +137,7 @@ internal class OneTimeKeysUploader @Inject constructor(
|
||||
private suspend fun uploadOneTimeKeys(oneTimeKeys: Map<String, Map<String, String>>?): KeysUploadResponse {
|
||||
val oneTimeJson = mutableMapOf<String, Any>()
|
||||
|
||||
val curve25519Map = oneTimeKeys?.get(OlmAccount.JSON_KEY_ONE_TIME_KEY) ?: emptyMap()
|
||||
val curve25519Map = oneTimeKeys?.get(OlmAccount.JSON_KEY_ONE_TIME_KEY).orEmpty()
|
||||
|
||||
curve25519Map.forEach { (key_id, value) ->
|
||||
val k = mutableMapOf<String, Any>()
|
||||
|
@ -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) {
|
||||
|
@ -47,7 +47,7 @@ internal object CryptoInfoMapper {
|
||||
return CryptoCrossSigningKey(
|
||||
userId = keyInfo.userId,
|
||||
usages = keyInfo.usages,
|
||||
keys = keyInfo.keys ?: emptyMap(),
|
||||
keys = keyInfo.keys.orEmpty(),
|
||||
signatures = keyInfo.signatures,
|
||||
trustLevel = null
|
||||
)
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ internal open class OutgoingGossipingRequestEntity(
|
||||
GossipRequestType.KEY -> {
|
||||
OutgoingRoomKeyRequest(
|
||||
requestBody = getRequestedKeyInfo(),
|
||||
recipients = getRecipients() ?: emptyMap(),
|
||||
recipients = getRecipients().orEmpty(),
|
||||
requestId = requestId ?: "",
|
||||
state = requestState
|
||||
)
|
||||
@ -86,7 +86,7 @@ internal open class OutgoingGossipingRequestEntity(
|
||||
GossipRequestType.SECRET -> {
|
||||
OutgoingSecretRequest(
|
||||
secretName = getRequestedSecretName(),
|
||||
recipients = getRecipients() ?: emptyMap(),
|
||||
recipients = getRecipients().orEmpty(),
|
||||
requestId = requestId ?: "",
|
||||
state = requestState
|
||||
)
|
||||
|
@ -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,
|
||||
|
@ -52,7 +52,7 @@ internal class TimelineEventMapper @Inject constructor(private val readReceiptsS
|
||||
it.user
|
||||
}?.sortedByDescending {
|
||||
it.originServerTs
|
||||
} ?: emptyList()
|
||||
}.orEmpty()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -229,40 +229,40 @@ internal abstract class SessionModule {
|
||||
abstract fun bindSession(session: DefaultSession): Session
|
||||
|
||||
@Binds
|
||||
abstract fun bindNetworkConnectivityChecker(networkConnectivityChecker: DefaultNetworkConnectivityChecker): NetworkConnectivityChecker
|
||||
abstract fun bindNetworkConnectivityChecker(checker: DefaultNetworkConnectivityChecker): NetworkConnectivityChecker
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
abstract fun bindGroupSummaryUpdater(groupSummaryUpdater: GroupSummaryUpdater): LiveEntityObserver
|
||||
abstract fun bindGroupSummaryUpdater(updater: GroupSummaryUpdater): LiveEntityObserver
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
abstract fun bindEventsPruner(eventsPruner: EventsPruner): LiveEntityObserver
|
||||
abstract fun bindEventsPruner(pruner: EventsPruner): LiveEntityObserver
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
abstract fun bindEventRelationsAggregationUpdater(eventRelationsAggregationUpdater: EventRelationsAggregationUpdater): LiveEntityObserver
|
||||
abstract fun bindEventRelationsAggregationUpdater(updater: EventRelationsAggregationUpdater): LiveEntityObserver
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
abstract fun bindRoomTombstoneEventLiveObserver(roomTombstoneEventLiveObserver: RoomTombstoneEventLiveObserver): LiveEntityObserver
|
||||
abstract fun bindRoomTombstoneEventLiveObserver(observer: RoomTombstoneEventLiveObserver): LiveEntityObserver
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
abstract fun bindRoomCreateEventLiveObserver(roomCreateEventLiveObserver: RoomCreateEventLiveObserver): LiveEntityObserver
|
||||
abstract fun bindRoomCreateEventLiveObserver(observer: RoomCreateEventLiveObserver): LiveEntityObserver
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
abstract fun bindVerificationMessageLiveObserver(verificationMessageLiveObserver: VerificationMessageLiveObserver): LiveEntityObserver
|
||||
abstract fun bindVerificationMessageLiveObserver(observer: VerificationMessageLiveObserver): LiveEntityObserver
|
||||
|
||||
@Binds
|
||||
abstract fun bindInitialSyncProgressService(initialSyncProgressService: DefaultInitialSyncProgressService): InitialSyncProgressService
|
||||
abstract fun bindInitialSyncProgressService(service: DefaultInitialSyncProgressService): InitialSyncProgressService
|
||||
|
||||
@Binds
|
||||
abstract fun bindSecureStorageService(secureStorageService: DefaultSecureStorageService): SecureStorageService
|
||||
abstract fun bindSecureStorageService(service: DefaultSecureStorageService): SecureStorageService
|
||||
|
||||
@Binds
|
||||
abstract fun bindHomeServerCapabilitiesService(homeServerCapabilitiesService: DefaultHomeServerCapabilitiesService): HomeServerCapabilitiesService
|
||||
abstract fun bindHomeServerCapabilitiesService(service: DefaultHomeServerCapabilitiesService): HomeServerCapabilitiesService
|
||||
|
||||
@Binds
|
||||
abstract fun bindAccountDataService(service: DefaultAccountDataService): AccountDataService
|
||||
|
@ -25,8 +25,8 @@ import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
||||
internal abstract class ContentModule {
|
||||
|
||||
@Binds
|
||||
abstract fun bindContentUploadStateTracker(contentUploadStateTracker: DefaultContentUploadStateTracker): ContentUploadStateTracker
|
||||
abstract fun bindContentUploadStateTracker(tracker: DefaultContentUploadStateTracker): ContentUploadStateTracker
|
||||
|
||||
@Binds
|
||||
abstract fun bindContentUrlResolver(contentUrlResolver: DefaultContentUrlResolver): ContentUrlResolver
|
||||
abstract fun bindContentUrlResolver(resolver: DefaultContentUrlResolver): ContentUrlResolver
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ internal class AccountDataMapper @Inject constructor(moshi: Moshi) {
|
||||
fun map(entity: UserAccountDataEntity): UserAccountDataEvent {
|
||||
return UserAccountDataEvent(
|
||||
type = entity.type ?: "",
|
||||
content = entity.contentStr?.let { adapter.fromJson(it) } ?: emptyMap()
|
||||
content = entity.contentStr?.let { adapter.fromJson(it) }.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 {
|
||||
|
@ -41,5 +41,5 @@ internal abstract class AccountDataModule {
|
||||
abstract fun bindSaveBreadcrumbsTask(task: DefaultSaveBreadcrumbsTask): SaveBreadcrumbsTask
|
||||
|
||||
@Binds
|
||||
abstract fun bindUpdateBreadcrumsTask(task: DefaultUpdateBreadcrumbsTask): UpdateBreadcrumbsTask
|
||||
abstract fun bindUpdateBreadcrumbsTask(task: DefaultUpdateBreadcrumbsTask): UpdateBreadcrumbsTask
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ internal class DefaultAccountDataService @Inject constructor(
|
||||
entity.type?.let { type ->
|
||||
UserAccountDataEvent(
|
||||
type = type,
|
||||
content = entity.contentStr?.let { adapter.fromJson(it) } ?: emptyMap()
|
||||
content = entity.contentStr?.let { adapter.fromJson(it) }.orEmpty()
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -84,7 +84,7 @@ internal class DefaultAccountDataService @Inject constructor(
|
||||
}, { entity ->
|
||||
UserAccountDataEvent(
|
||||
type = entity.type ?: "",
|
||||
content = entity.contentStr?.let { adapter.fromJson(it) } ?: emptyMap()
|
||||
content = entity.contentStr?.let { adapter.fromJson(it) }.orEmpty()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
@ -75,8 +75,8 @@ abstract class VectorModule {
|
||||
abstract fun bindNavigator(navigator: DefaultNavigator): Navigator
|
||||
|
||||
@Binds
|
||||
abstract fun bindErrorFormatter(errorFormatter: DefaultErrorFormatter): ErrorFormatter
|
||||
abstract fun bindErrorFormatter(formatter: DefaultErrorFormatter): ErrorFormatter
|
||||
|
||||
@Binds
|
||||
abstract fun bindUiStateRepository(uiStateRepository: SharedPreferencesUiStateRepository): UiStateRepository
|
||||
abstract fun bindUiStateRepository(repository: SharedPreferencesUiStateRepository): UiStateRepository
|
||||
}
|
||||
|
@ -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())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,5 @@ import dagger.Module
|
||||
abstract class RoomListModule {
|
||||
|
||||
@Binds
|
||||
abstract fun providesRoomListViewModelFactory(roomListViewModelFactory: RoomListViewModelFactory): RoomListViewModel.Factory
|
||||
abstract fun providesRoomListViewModelFactory(factory: RoomListViewModelFactory): RoomListViewModel.Factory
|
||||
}
|
||||
|
@ -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 New Issue
Block a user