Call getFixedRoomMemberContent() when loading room members of a room
It fixes bad names for Empty room
This commit is contained in:
parent
2d4866cdc5
commit
7e74e6a6f4
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.internal.session.events
|
||||||
|
|
||||||
|
import org.matrix.android.sdk.api.session.events.model.Event
|
||||||
|
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||||
|
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
||||||
|
|
||||||
|
internal fun Event.getFixedRoomMemberContent(): RoomMemberContent? {
|
||||||
|
val content = content.toModel<RoomMemberContent>()
|
||||||
|
// if user is leaving, we should grab his last name and avatar from prevContent
|
||||||
|
return if (content?.membership?.isLeft() == true) {
|
||||||
|
val prevContent = resolvedPrevContent().toModel<RoomMemberContent>()
|
||||||
|
content.copy(
|
||||||
|
displayName = prevContent?.displayName,
|
||||||
|
avatarUrl = prevContent?.avatarUrl
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
content
|
||||||
|
}
|
||||||
|
}
|
@ -16,12 +16,12 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.internal.session.room.membership
|
package org.matrix.android.sdk.internal.session.room.membership
|
||||||
|
|
||||||
|
import io.realm.Realm
|
||||||
import org.matrix.android.sdk.api.session.events.model.Event
|
import org.matrix.android.sdk.api.session.events.model.Event
|
||||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
|
||||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
||||||
|
import org.matrix.android.sdk.internal.session.events.getFixedRoomMemberContent
|
||||||
import org.matrix.android.sdk.internal.session.user.UserEntityFactory
|
import org.matrix.android.sdk.internal.session.user.UserEntityFactory
|
||||||
import io.realm.Realm
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class RoomMemberEventHandler @Inject constructor() {
|
internal class RoomMemberEventHandler @Inject constructor() {
|
||||||
@ -31,7 +31,7 @@ internal class RoomMemberEventHandler @Inject constructor() {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
val userId = event.stateKey ?: return false
|
val userId = event.stateKey ?: return false
|
||||||
val roomMember = event.content.toModel<RoomMemberContent>()
|
val roomMember = event.getFixedRoomMemberContent()
|
||||||
return handle(realm, roomId, userId, roomMember)
|
return handle(realm, roomId, userId, roomMember)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ import org.matrix.android.sdk.internal.database.query.where
|
|||||||
import org.matrix.android.sdk.internal.di.MoshiProvider
|
import org.matrix.android.sdk.internal.di.MoshiProvider
|
||||||
import org.matrix.android.sdk.internal.di.UserId
|
import org.matrix.android.sdk.internal.di.UserId
|
||||||
import org.matrix.android.sdk.internal.extensions.clearWith
|
import org.matrix.android.sdk.internal.extensions.clearWith
|
||||||
|
import org.matrix.android.sdk.internal.session.events.getFixedRoomMemberContent
|
||||||
import org.matrix.android.sdk.internal.session.initsync.ProgressReporter
|
import org.matrix.android.sdk.internal.session.initsync.ProgressReporter
|
||||||
import org.matrix.android.sdk.internal.session.initsync.mapWithProgress
|
import org.matrix.android.sdk.internal.session.initsync.mapWithProgress
|
||||||
import org.matrix.android.sdk.internal.session.initsync.reportSubtask
|
import org.matrix.android.sdk.internal.session.initsync.reportSubtask
|
||||||
@ -464,18 +465,4 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Event.getFixedRoomMemberContent(): RoomMemberContent? {
|
|
||||||
val content = content.toModel<RoomMemberContent>()
|
|
||||||
// if user is leaving, we should grab his last name and avatar from prevContent
|
|
||||||
return if (content?.membership?.isLeft() == true) {
|
|
||||||
val prevContent = resolvedPrevContent().toModel<RoomMemberContent>()
|
|
||||||
content.copy(
|
|
||||||
displayName = prevContent?.displayName,
|
|
||||||
avatarUrl = prevContent?.avatarUrl
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
content
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user