Code review fixes.

This commit is contained in:
Onuray Sahin 2022-12-12 13:39:56 +03:00
parent b09a00efda
commit 746fb7719a
2 changed files with 18 additions and 15 deletions

View file

@ -253,18 +253,20 @@ internal class UserAccountDataSyncHandler @Inject constructor(
}
fun handleGenericAccountData(realm: Realm, type: String, content: Content?) {
val existing = realm.where<UserAccountDataEntity>()
.equalTo(UserAccountDataEntityFields.TYPE, type)
.findFirst()
if (existing != null) {
if (content.isNullOrEmpty()) {
// This is a response for a deleted account data according to
// https://github.com/ShadowJonathan/matrix-doc/blob/account-data-delete/proposals/3391-account-data-delete.md#sync
UserAccountDataEntity.delete(realm, type)
} else {
return
}
val existing = realm.where<UserAccountDataEntity>()
.equalTo(UserAccountDataEntityFields.TYPE, type)
.findFirst()
if (existing != null) {
// Update current value
existing.contentStr = ContentMapper.map(content)
}
} else {
realm.createObject(UserAccountDataEntity::class.java).let { accountDataEntity ->
accountDataEntity.type = type

View file

@ -57,15 +57,16 @@ internal class RoomSyncAccountDataHandler @Inject constructor(
}
private fun handleGeneric(roomEntity: RoomEntity, content: JsonDict?, eventType: String) {
val existing = roomEntity.accountData.where().equalTo(RoomAccountDataEntityFields.TYPE, eventType).findFirst()
if (existing != null) {
if (content.isNullOrEmpty()) {
// This is a response for a deleted account data according to
// https://github.com/ShadowJonathan/matrix-doc/blob/account-data-delete/proposals/3391-account-data-delete.md#sync
roomEntity.removeAccountData(eventType)
} else {
existing.contentStr = ContentMapper.map(content)
return
}
val existing = roomEntity.accountData.where().equalTo(RoomAccountDataEntityFields.TYPE, eventType).findFirst()
if (existing != null) {
existing.contentStr = ContentMapper.map(content)
} else {
val roomAccountData = RoomAccountDataEntity(
type = eventType,