From bf9e9b04f2244b197749ed63fc743298f32a62b0 Mon Sep 17 00:00:00 2001 From: Taras Smakula <tarassmakula@gmail.com> Date: Wed, 6 Mar 2024 13:21:02 +0200 Subject: [PATCH] Filter root post from not owner in circle --- .../timeline/builder/MultiTimelineBuilder.kt | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/futo/circles/core/feature/timeline/builder/MultiTimelineBuilder.kt b/core/src/main/java/org/futo/circles/core/feature/timeline/builder/MultiTimelineBuilder.kt index 8104b347e..92b6f9170 100644 --- a/core/src/main/java/org/futo/circles/core/feature/timeline/builder/MultiTimelineBuilder.kt +++ b/core/src/main/java/org/futo/circles/core/feature/timeline/builder/MultiTimelineBuilder.kt @@ -7,6 +7,7 @@ import org.futo.circles.core.mapping.toPost import org.futo.circles.core.model.Post import org.futo.circles.core.provider.MatrixSessionProvider import org.matrix.android.sdk.api.session.getRoom +import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import javax.inject.Inject @@ -16,16 +17,35 @@ class MultiTimelineBuilder @Inject constructor() : BaseTimelineBuilder() { private var readReceiptMap: MutableMap<String, List<Long>> = mutableMapOf() override suspend fun List<TimelineEvent>.processSnapshot(isThread: Boolean): List<Post> { - val roomId = firstOrNull()?.roomId ?: return getAllTimelinesPostsList() + val roomId = firstOrNull()?.roomId ?: return getCurrentTimelinesPostsList() val room = MatrixSessionProvider.currentSession?.getRoom(roomId) - ?: return getAllTimelinesPostsList() + ?: return getCurrentTimelinesPostsList() val roomName = room.roomSummary()?.nameOrId() - val roomOwnerName = getRoomOwner(roomId)?.notEmptyDisplayName() + val roomOwner = getRoomOwner(roomId) val receipts = getReadReceipts(room).also { readReceiptMap[roomId] = it } - currentSnapshotMap[roomId] = this.map { it.toPost(receipts, roomName, roomOwnerName) } - return sortList(getAllTimelinesPostsList(), isThread) + currentSnapshotMap[roomId] = + this.filterRootPostNotFromOwner(isThread, receipts, roomName, roomOwner) + return sortList(getCurrentTimelinesPostsList(), isThread) } - private fun getAllTimelinesPostsList() = currentSnapshotMap.flatMap { (_, value) -> value } + private fun List<TimelineEvent>.filterRootPostNotFromOwner( + isThread: Boolean, + receipts: List<Long>, + roomName: String?, + roomOwner: RoomMemberSummary? + ): List<Post> { + val roomOwnerId = roomOwner?.userId + val roomOwnerName = roomOwner?.notEmptyDisplayName() + + return mapNotNull { + val senderId = it.senderInfo.userId + if (roomOwnerId == senderId && !isThread) + it.toPost(receipts, roomName, roomOwnerName) + else null + } + } + + + private fun getCurrentTimelinesPostsList() = currentSnapshotMap.flatMap { (_, value) -> value } } \ No newline at end of file -- GitLab