Adding a method to retrieve livedata of crypto device info for a given device id

This commit is contained in:
Maxime NATUREL 2022-08-30 16:47:34 +02:00
parent c690a8cd81
commit cc36f40a8d
4 changed files with 14 additions and 0 deletions

View File

@ -122,6 +122,8 @@ interface CryptoService {
fun getLiveCryptoDeviceInfo(): LiveData<List<CryptoDeviceInfo>>
fun getLiveCryptoDeviceInfoWithId(deviceId: String): LiveData<Optional<CryptoDeviceInfo>>
fun getLiveCryptoDeviceInfo(userId: String): LiveData<List<CryptoDeviceInfo>>
fun getLiveCryptoDeviceInfo(userIds: List<String>): LiveData<List<CryptoDeviceInfo>>

View File

@ -534,6 +534,10 @@ internal class DefaultCryptoService @Inject constructor(
return cryptoStore.getLiveDeviceList()
}
override fun getLiveCryptoDeviceInfoWithId(deviceId: String): LiveData<Optional<CryptoDeviceInfo>> {
return cryptoStore.getLiveDeviceWithId(deviceId)
}
override fun getLiveCryptoDeviceInfo(userId: String): LiveData<List<CryptoDeviceInfo>> {
return cryptoStore.getLiveDeviceList(userId)
}

View File

@ -238,6 +238,8 @@ internal interface IMXCryptoStore {
// TODO temp
fun getLiveDeviceList(): LiveData<List<CryptoDeviceInfo>>
fun getLiveDeviceWithId(deviceId: String): LiveData<Optional<CryptoDeviceInfo>>
fun getMyDevicesInfo(): List<DeviceInfo>
fun getLiveMyDevicesInfo(): LiveData<List<DeviceInfo>>

View File

@ -581,6 +581,12 @@ internal class RealmCryptoStore @Inject constructor(
}
}
override fun getLiveDeviceWithId(deviceId: String): LiveData<Optional<CryptoDeviceInfo>> {
return Transformations.map(getLiveDeviceList()) { devices ->
devices.firstOrNull { it.deviceId == deviceId }.toOptional()
}
}
override fun getMyDevicesInfo(): List<DeviceInfo> {
return monarchy.fetchAllCopiedSync {
it.where<MyDeviceLastSeenInfoEntity>()