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

View File

@ -57,15 +57,16 @@ internal class RoomSyncAccountDataHandler @Inject constructor(
} }
private fun handleGeneric(roomEntity: RoomEntity, content: JsonDict?, eventType: String) { private fun handleGeneric(roomEntity: RoomEntity, content: JsonDict?, eventType: String) {
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)
return
}
val existing = roomEntity.accountData.where().equalTo(RoomAccountDataEntityFields.TYPE, eventType).findFirst() val existing = roomEntity.accountData.where().equalTo(RoomAccountDataEntityFields.TYPE, eventType).findFirst()
if (existing != null) { if (existing != null) {
if (content.isNullOrEmpty()) { existing.contentStr = ContentMapper.map(content)
// 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)
}
} else { } else {
val roomAccountData = RoomAccountDataEntity( val roomAccountData = RoomAccountDataEntity(
type = eventType, type = eventType,