taking heroes into account when processing room display name
This commit is contained in:
parent
355d4a021c
commit
d30925fd5a
|
@ -56,6 +56,12 @@ internal data class ApiSyncRoom(
|
|||
@SerialName("state") val state: ApiSyncRoomState,
|
||||
@SerialName("account_data") val accountData: ApiAccountData? = null,
|
||||
@SerialName("ephemeral") val ephemeral: ApiEphemeral? = null,
|
||||
@SerialName("summary") val summary: ApiRoomSummary? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
internal data class ApiRoomSummary(
|
||||
@SerialName("m.heroes") val heroes: List<UserId>? = null
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
|
|
@ -15,16 +15,14 @@ internal class RoomOverviewProcessor(
|
|||
suspend fun process(roomToProcess: RoomToProcess, previousState: RoomOverview?, lastMessage: LastMessage?): RoomOverview {
|
||||
val combinedEvents = roomToProcess.apiSyncRoom.state.stateEvents + roomToProcess.apiSyncRoom.timeline.apiTimelineEvents
|
||||
val isEncrypted = combinedEvents.any { it is ApiTimelineEvent.Encryption }
|
||||
|
||||
val readMarker = roomToProcess.apiSyncRoom.accountData?.events?.filterIsInstance<ApiAccountEvent.FullyRead>()?.firstOrNull()?.content?.eventId
|
||||
return when (previousState) {
|
||||
null -> combinedEvents.filterIsInstance<ApiTimelineEvent.RoomCreate>().first().let { roomCreate ->
|
||||
val roomName = roomDisplayName(combinedEvents)
|
||||
val roomName = roomDisplayName(roomToProcess, combinedEvents)
|
||||
val isGroup = roomToProcess.directMessage == null
|
||||
val processedName = roomName ?: roomToProcess.directMessage?.let {
|
||||
roomMembersService.find(roomToProcess.roomId, it)?.let { it.displayName ?: it.id.value }
|
||||
}
|
||||
|
||||
RoomOverview(
|
||||
roomName = processedName,
|
||||
roomCreationUtc = roomCreate.utcTimestamp,
|
||||
|
@ -45,7 +43,7 @@ internal class RoomOverviewProcessor(
|
|||
|
||||
else -> {
|
||||
previousState.copy(
|
||||
roomName = previousState.roomName ?: roomDisplayName(combinedEvents),
|
||||
roomName = previousState.roomName ?: roomDisplayName(roomToProcess, combinedEvents),
|
||||
lastMessage = lastMessage ?: previousState.lastMessage,
|
||||
roomAvatarUrl = previousState.roomAvatarUrl ?: roomAvatar(
|
||||
roomToProcess.roomId,
|
||||
|
@ -61,10 +59,13 @@ internal class RoomOverviewProcessor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun roomDisplayName(combinedEvents: List<ApiTimelineEvent>): String? {
|
||||
val roomName = combinedEvents.filterIsInstance<ApiTimelineEvent.RoomName>().lastOrNull()
|
||||
return (roomName?.content?.name)
|
||||
private suspend fun roomDisplayName(roomToProcess: RoomToProcess, combinedEvents: List<ApiTimelineEvent>): String? {
|
||||
val roomName = combinedEvents.filterIsInstance<ApiTimelineEvent.RoomName>().lastOrNull()?.content?.name
|
||||
?: combinedEvents.filterIsInstance<ApiTimelineEvent.CanonicalAlias>().lastOrNull()?.content?.alias
|
||||
?: roomToProcess.heroes?.let {
|
||||
roomMembersService.find(roomToProcess.roomId, it).joinToString { it.displayName ?: it.id.value }
|
||||
}
|
||||
return roomName?.takeIf { it.isNotEmpty() }
|
||||
}
|
||||
|
||||
private suspend fun roomAvatar(
|
||||
|
|
|
@ -10,4 +10,5 @@ internal data class RoomToProcess(
|
|||
val apiSyncRoom: ApiSyncRoom,
|
||||
val directMessage: UserId?,
|
||||
val userCredentials: UserCredentials,
|
||||
val heroes: List<UserId>?,
|
||||
)
|
|
@ -30,7 +30,6 @@ internal class SyncReducer(
|
|||
|
||||
suspend fun reduce(isInitialSync: Boolean, sideEffects: SideEffectResult, response: ApiSyncResponse, userCredentials: UserCredentials): ReducerResult {
|
||||
val directMessages = response.directMessages()
|
||||
|
||||
val invites = response.rooms?.invite?.map { roomInvite(it, userCredentials) } ?: emptyList()
|
||||
val roomsLeft = findRoomsLeft(response, userCredentials)
|
||||
val newRooms = response.rooms?.join?.keys?.filterNot { roomDataSource.contains(it) } ?: emptyList()
|
||||
|
@ -46,6 +45,7 @@ internal class SyncReducer(
|
|||
apiSyncRoom = apiRoom,
|
||||
directMessage = directMessages[roomId],
|
||||
userCredentials = userCredentials,
|
||||
heroes = apiRoom.summary?.heroes,
|
||||
),
|
||||
isInitialSync = isInitialSync
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue