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,17 +82,13 @@ 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) {
UserAccountDataTypes.TYPE_DIRECT_MESSAGES -> handleDirectChatRooms(realm, event)
UserAccountDataTypes.TYPE_PUSH_RULES -> handlePushRules(realm, event)
UserAccountDataTypes.TYPE_IGNORED_USER_LIST -> handleIgnoredUsers(realm, event)
UserAccountDataTypes.TYPE_BREADCRUMBS -> handleBreadcrumbs(realm, event)
}
// Generic handling, just save in base
handleGenericAccountData(realm, event.type, event.content)
when (event.type) {
UserAccountDataTypes.TYPE_DIRECT_MESSAGES -> handleDirectChatRooms(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)
.findFirst()
if (existing != null) {
// Update current value
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
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,17 +45,13 @@ 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>()
roomTagHandler.handle(realm, roomId, content)
} else if (eventType == RoomAccountDataTypes.EVENT_TYPE_FULLY_READ) {
val content = event.getClearContent().toModel<FullyReadContent>()
roomFullyReadHandler.handle(realm, roomId, content)
}
handleGeneric(roomEntity, event.getClearContent(), eventType)
if (eventType == RoomAccountDataTypes.EVENT_TYPE_TAG) {
val content = event.getClearContent().toModel<RoomTagContent>()
roomTagHandler.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) {
val existing = roomEntity.accountData.where().equalTo(RoomAccountDataEntityFields.TYPE, eventType).findFirst()
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 {
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