Skip to content
Snippets Groups Projects
Commit dfa677e8 authored by Taras's avatar Taras
Browse files

Calculate following in circles count

parent 7b8dd9f5
No related branches found
No related tags found
No related merge requests found
......@@ -6,8 +6,11 @@ import org.futo.circles.R
import org.futo.circles.core.matrix.room.RoomRelationsBuilder
import org.futo.circles.extensions.createResult
import org.futo.circles.mapping.toFollowingListItem
import org.futo.circles.model.CIRCLE_TAG
import org.futo.circles.provider.MatrixSessionProvider
import org.matrix.android.sdk.api.session.getRoom
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
class FollowingDataSource(
private val roomId: String,
......@@ -27,7 +30,7 @@ class FollowingDataSource(
val children = it.getOrNull()?.spaceChildren ?: emptyList()
children.mapNotNull {
session.getRoom(it.childRoomId)?.roomSummary()?.takeIf { it.membership.isActive() }
?.toFollowingListItem(roomId)
?.toFollowingListItem(roomId, getFollowingInCircleCount(it.childRoomId))
}
}
......@@ -39,4 +42,17 @@ class FollowingDataSource(
roomRelationsBuilder.removeFromAllParents(childRoomId)
session.roomService().leaveRoom(childRoomId)
}
private fun getFollowingInCircleCount(roomId: String): Int {
var followingCount = 0
session.roomService().getRoomSummaries(roomSummaryQueryParams { excludeType = null })
.filter { summary ->
summary.hasTag(CIRCLE_TAG) && summary.membership == Membership.JOIN
}.forEach { circle ->
circle.spaceChildren?.firstOrNull { it.childRoomId == roomId }?.let {
followingCount++
}
}
return followingCount
}
}
\ No newline at end of file
......@@ -48,6 +48,7 @@ class FollowingDialogFragment :
private fun showRemoveOptionsDialog(item: FollowingListItem) {
RemoveFollowingDialog(requireContext(), item.id, item.name,
item.followInCirclesCount,
object : RemoveFollowingListener {
override fun onRemove(roomId: String) {
viewModel.removeRoomFromCircle(roomId)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment