Code review fixes.

This commit is contained in:
Onuray Sahin 2022-12-08 17:11:09 +03:00
parent d6c20226bb
commit b09a00efda
4 changed files with 32 additions and 28 deletions

View File

@ -433,7 +433,7 @@ internal interface RoomAPI {
* @param roomId the room id
* @param type the type
*/
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_MEDIA_PROXY_UNSTABLE + "org.matrix.msc3391/user/{userId}/rooms/{roomId}/account_data/{type}")
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "org.matrix.msc3391/user/{userId}/rooms/{roomId}/account_data/{type}")
suspend fun deleteRoomAccountData(
@Path("userId") userId: String,
@Path("roomId") roomId: String,

View File

@ -82,9 +82,6 @@ internal class UserAccountDataSyncHandler @Inject constructor(
fun handle(realm: Realm, accountData: UserAccountDataSync?) {
accountData?.list?.forEach { event ->
if (event.content.isEmpty()) {
UserAccountDataEntity.delete(realm, event.type)
} else {
// Generic handling, just save in base
handleGenericAccountData(realm, event.type, event.content)
when (event.type) {
@ -95,7 +92,6 @@ internal class UserAccountDataSyncHandler @Inject constructor(
}
}
}
}
// If we get some direct chat invites, we synchronize the user account data including those.
suspend fun synchronizeWithServerIfNeeded(invites: Map<String, InvitedRoomSync>) {
@ -261,8 +257,14 @@ internal class UserAccountDataSyncHandler @Inject constructor(
.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 {
// Update current value
existing.contentStr = ContentMapper.map(content)
}
} else {
realm.createObject(UserAccountDataEntity::class.java).let { accountDataEntity ->
accountDataEntity.type = type

View File

@ -45,9 +45,6 @@ internal class RoomSyncAccountDataHandler @Inject constructor(
val roomEntity = RoomEntity.getOrCreate(realm, roomId)
for (event in accountData.events) {
val eventType = event.getClearType()
if (event.getClearContent().isNullOrEmpty()) {
roomEntity.removeAccountData(eventType)
} else {
handleGeneric(roomEntity, event.getClearContent(), eventType)
if (eventType == RoomAccountDataTypes.EVENT_TYPE_TAG) {
val content = event.getClearContent().toModel<RoomTagContent>()
@ -58,12 +55,17 @@ 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)
}
} else {
val roomAccountData = RoomAccountDataEntity(
type = eventType,

View File

@ -25,7 +25,7 @@ import retrofit2.http.Path
internal interface AccountDataAPI {
/**
* Set some account_data for the client.
* Set some account_data for the user.
*
* @param userId the user id
* @param type the type
@ -39,7 +39,7 @@ internal interface AccountDataAPI {
)
/**
* Remove an account_data for the client.
* Remove an account_data for the user.
*
* @param userId the user id
* @param type the type