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