filtering out spaces from the room overviews
This commit is contained in:
parent
416d10a2b6
commit
3d7730bc32
|
@ -21,7 +21,13 @@ internal sealed class ApiTimelineEvent {
|
||||||
@Serializable
|
@Serializable
|
||||||
internal data class Content(
|
internal data class Content(
|
||||||
@SerialName("type") val type: String? = null
|
@SerialName("type") val type: String? = null
|
||||||
)
|
) {
|
||||||
|
|
||||||
|
object Type {
|
||||||
|
const val SPACE = "m.space"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|
|
@ -12,33 +12,38 @@ internal class RoomOverviewProcessor(
|
||||||
private val roomMembersService: RoomMembersService,
|
private val roomMembersService: RoomMembersService,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
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(roomToProcess, combinedEvents)
|
when (roomCreate.content.type) {
|
||||||
val isGroup = roomToProcess.directMessage == null
|
ApiTimelineEvent.RoomCreate.Content.Type.SPACE -> null
|
||||||
val processedName = roomName ?: roomToProcess.directMessage?.let {
|
else -> {
|
||||||
roomMembersService.find(roomToProcess.roomId, it)?.let { it.displayName ?: it.id.value }
|
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,
|
||||||
|
lastMessage = lastMessage,
|
||||||
|
roomId = roomToProcess.roomId,
|
||||||
|
isGroup = isGroup,
|
||||||
|
roomAvatarUrl = roomAvatar(
|
||||||
|
roomToProcess.roomId,
|
||||||
|
roomMembersService,
|
||||||
|
roomToProcess.directMessage,
|
||||||
|
combinedEvents,
|
||||||
|
roomToProcess.userCredentials.homeServer
|
||||||
|
),
|
||||||
|
readMarker = readMarker,
|
||||||
|
isEncrypted = isEncrypted,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
RoomOverview(
|
|
||||||
roomName = processedName,
|
|
||||||
roomCreationUtc = roomCreate.utcTimestamp,
|
|
||||||
lastMessage = lastMessage,
|
|
||||||
roomId = roomToProcess.roomId,
|
|
||||||
isGroup = isGroup,
|
|
||||||
roomAvatarUrl = roomAvatar(
|
|
||||||
roomToProcess.roomId,
|
|
||||||
roomMembersService,
|
|
||||||
roomToProcess.directMessage,
|
|
||||||
combinedEvents,
|
|
||||||
roomToProcess.userCredentials.homeServer
|
|
||||||
),
|
|
||||||
readMarker = readMarker,
|
|
||||||
isEncrypted = isEncrypted,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
|
|
|
@ -17,7 +17,7 @@ internal class RoomProcessor(
|
||||||
private val ephemeralEventsUseCase: EphemeralEventsUseCase,
|
private val ephemeralEventsUseCase: EphemeralEventsUseCase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun processRoom(roomToProcess: RoomToProcess, isInitialSync: Boolean): RoomState {
|
suspend fun processRoom(roomToProcess: RoomToProcess, isInitialSync: Boolean): RoomState? {
|
||||||
val members = roomToProcess.apiSyncRoom.collectMembers(roomToProcess.userCredentials)
|
val members = roomToProcess.apiSyncRoom.collectMembers(roomToProcess.userCredentials)
|
||||||
roomMembersService.insert(roomToProcess.roomId, members)
|
roomMembersService.insert(roomToProcess.roomId, members)
|
||||||
|
|
||||||
|
@ -28,16 +28,17 @@ internal class RoomProcessor(
|
||||||
previousState?.events ?: emptyList(),
|
previousState?.events ?: emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
val overview = createRoomOverview(distinctEvents, roomToProcess, previousState)
|
return createRoomOverview(distinctEvents, roomToProcess, previousState)?.let {
|
||||||
unreadEventsProcessor.processUnreadState(overview, previousState?.roomOverview, newEvents, roomToProcess.userCredentials.userId, isInitialSync)
|
unreadEventsProcessor.processUnreadState(it, previousState?.roomOverview, newEvents, roomToProcess.userCredentials.userId, isInitialSync)
|
||||||
|
|
||||||
return RoomState(overview, distinctEvents).also {
|
RoomState(it, distinctEvents).also {
|
||||||
roomDataSource.persist(roomToProcess.roomId, previousState, it)
|
roomDataSource.persist(roomToProcess.roomId, previousState, it)
|
||||||
ephemeralEventsUseCase.processEvents(roomToProcess)
|
ephemeralEventsUseCase.processEvents(roomToProcess)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun createRoomOverview(distinctEvents: List<RoomEvent>, roomToProcess: RoomToProcess, previousState: RoomState?): RoomOverview {
|
private suspend fun createRoomOverview(distinctEvents: List<RoomEvent>, roomToProcess: RoomToProcess, previousState: RoomState?): RoomOverview? {
|
||||||
val lastMessage = distinctEvents.sortedByDescending { it.utcTimestamp }.findLastMessage()
|
val lastMessage = distinctEvents.sortedByDescending { it.utcTimestamp }.findLastMessage()
|
||||||
return roomOverviewProcessor.process(roomToProcess, previousState?.roomOverview, lastMessage)
|
return roomOverviewProcessor.process(roomToProcess, previousState?.roomOverview, lastMessage)
|
||||||
}
|
}
|
||||||
|
@ -56,6 +57,7 @@ private fun ApiSyncRoom.collectMembers(userCredentials: UserCredentials): List<R
|
||||||
avatarUrl = it.content.avatarUrl?.convertMxUrToUrl(userCredentials.homeServer)?.let { AvatarUrl(it) },
|
avatarUrl = it.content.avatarUrl?.convertMxUrToUrl(userCredentials.homeServer)?.let { AvatarUrl(it) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue