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 roomId the room id
* @param type the type * @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( suspend fun deleteRoomAccountData(
@Path("userId") userId: String, @Path("userId") userId: String,
@Path("roomId") roomId: String, @Path("roomId") roomId: String,

View File

@ -82,17 +82,13 @@ internal class UserAccountDataSyncHandler @Inject constructor(
fun handle(realm: Realm, accountData: UserAccountDataSync?) { fun handle(realm: Realm, accountData: UserAccountDataSync?) {
accountData?.list?.forEach { event -> accountData?.list?.forEach { event ->
if (event.content.isEmpty()) { // Generic handling, just save in base
UserAccountDataEntity.delete(realm, event.type) handleGenericAccountData(realm, event.type, event.content)
} else { when (event.type) {
// Generic handling, just save in base UserAccountDataTypes.TYPE_DIRECT_MESSAGES -> handleDirectChatRooms(realm, event)
handleGenericAccountData(realm, event.type, event.content) UserAccountDataTypes.TYPE_PUSH_RULES -> handlePushRules(realm, event)
when (event.type) { UserAccountDataTypes.TYPE_IGNORED_USER_LIST -> handleIgnoredUsers(realm, event)
UserAccountDataTypes.TYPE_DIRECT_MESSAGES -> handleDirectChatRooms(realm, event) UserAccountDataTypes.TYPE_BREADCRUMBS -> handleBreadcrumbs(realm, event)
UserAccountDataTypes.TYPE_PUSH_RULES -> handlePushRules(realm, event)
UserAccountDataTypes.TYPE_IGNORED_USER_LIST -> handleIgnoredUsers(realm, event)
UserAccountDataTypes.TYPE_BREADCRUMBS -> handleBreadcrumbs(realm, event)
}
} }
} }
} }
@ -261,8 +257,14 @@ internal class UserAccountDataSyncHandler @Inject constructor(
.equalTo(UserAccountDataEntityFields.TYPE, type) .equalTo(UserAccountDataEntityFields.TYPE, type)
.findFirst() .findFirst()
if (existing != null) { if (existing != null) {
// Update current value 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
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

@ -45,17 +45,13 @@ internal class RoomSyncAccountDataHandler @Inject constructor(
val roomEntity = RoomEntity.getOrCreate(realm, roomId) val roomEntity = RoomEntity.getOrCreate(realm, roomId)
for (event in accountData.events) { for (event in accountData.events) {
val eventType = event.getClearType() val eventType = event.getClearType()
if (event.getClearContent().isNullOrEmpty()) { handleGeneric(roomEntity, event.getClearContent(), eventType)
roomEntity.removeAccountData(eventType) if (eventType == RoomAccountDataTypes.EVENT_TYPE_TAG) {
} else { val content = event.getClearContent().toModel<RoomTagContent>()
handleGeneric(roomEntity, event.getClearContent(), eventType) roomTagHandler.handle(realm, roomId, content)
if (eventType == RoomAccountDataTypes.EVENT_TYPE_TAG) { } else if (eventType == RoomAccountDataTypes.EVENT_TYPE_FULLY_READ) {
val content = event.getClearContent().toModel<RoomTagContent>() val content = event.getClearContent().toModel<FullyReadContent>()
roomTagHandler.handle(realm, roomId, content) roomFullyReadHandler.handle(realm, roomId, content)
} else if (eventType == RoomAccountDataTypes.EVENT_TYPE_FULLY_READ) {
val content = event.getClearContent().toModel<FullyReadContent>()
roomFullyReadHandler.handle(realm, roomId, content)
}
} }
} }
} }
@ -63,7 +59,13 @@ internal class RoomSyncAccountDataHandler @Inject constructor(
private fun handleGeneric(roomEntity: RoomEntity, content: JsonDict?, eventType: String) { private fun handleGeneric(roomEntity: RoomEntity, content: JsonDict?, eventType: String) {
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) {
existing.contentStr = ContentMapper.map(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
roomEntity.removeAccountData(eventType)
} else {
existing.contentStr = ContentMapper.map(content)
}
} else { } else {
val roomAccountData = RoomAccountDataEntity( val roomAccountData = RoomAccountDataEntity(
type = eventType, type = eventType,

View File

@ -25,7 +25,7 @@ import retrofit2.http.Path
internal interface AccountDataAPI { internal interface AccountDataAPI {
/** /**
* Set some account_data for the client. * Set some account_data for the user.
* *
* @param userId the user id * @param userId the user id
* @param type the type * @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 userId the user id
* @param type the type * @param type the type