Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
circles-android
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Circles
circles-android
Commits
5c9e7770
Commit
5c9e7770
authored
1 year ago
by
Taras
Browse files
Options
Downloads
Patches
Plain Diff
improve filter for select rooms
parent
172acc86
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/org/futo/circles/feature/room/select/SelectRoomsDataSource.kt
+11
-17
11 additions, 17 deletions
...futo/circles/feature/room/select/SelectRoomsDataSource.kt
with
11 additions
and
17 deletions
app/src/main/java/org/futo/circles/feature/room/select/SelectRoomsDataSource.kt
+
11
−
17
View file @
5c9e7770
...
...
@@ -9,19 +9,17 @@ import kotlinx.coroutines.flow.Flow
import
kotlinx.coroutines.flow.MutableStateFlow
import
kotlinx.coroutines.flow.combine
import
kotlinx.coroutines.flow.distinctUntilChanged
import
kotlinx.coroutines.flow.emptyFlow
import
kotlinx.coroutines.flow.flowOn
import
org.futo.circles.core.extensions.getOrThrow
import
org.futo.circles.core.mapping.toSelectableRoomListItem
import
org.futo.circles.core.model.CircleRoomTypeArg
import
org.futo.circles.core.model.GALLERY_TYPE
import
org.futo.circles.core.model.GROUP_TYPE
import
org.futo.circles.core.model.SelectableRoomListItem
import
org.futo.circles.core.provider.MatrixSessionProvider
import
org.futo.circles.core.utils.getGalleriesLiveData
import
org.futo.circles.core.utils.getGroupsLiveData
import
org.futo.circles.core.utils.getSpacesLiveData
import
org.futo.circles.feature.circles.CirclesDataSource
import
org.matrix.android.sdk.api.session.room.model.Membership
import
org.matrix.android.sdk.api.session.room.model.RoomSummary
import
org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
import
javax.inject.Inject
@ViewModelScoped
...
...
@@ -35,8 +33,6 @@ class SelectRoomsDataSource @Inject constructor(
CircleRoomTypeArg
.
entries
.
firstOrNull
{
it
.
ordinal
==
ordinal
}
?:
CircleRoomTypeArg
.
Circle
private
val
session
by
lazy
{
MatrixSessionProvider
.
currentSession
}
private
val
selectedRoomsFlow
=
MutableStateFlow
<
List
<
SelectableRoomListItem
>>(
emptyList
())
val
roomsFlow
=
getMergedRoomsListFlow
()
...
...
@@ -48,11 +44,16 @@ class SelectRoomsDataSource @Inject constructor(
private
fun
getRoomsFlowWithType
():
Flow
<
List
<
RoomSummary
>>
=
when
(
roomType
)
{
CircleRoomTypeArg
.
Circle
->
{
val
joinedCirclesIds
=
circleDataSource
.
getJoinedCirclesIds
()
getFilteredRoomsFlow
{
circleDataSource
.
isJoinedCircle
(
it
,
joinedCirclesIds
)
}
getSpacesLiveData
(
listOf
(
Membership
.
JOIN
)).
map
{
summaries
->
summaries
.
mapNotNull
{
summary
->
if
(
joinedCirclesIds
.
contains
(
summary
.
roomId
))
summary
else
null
}
}.
asFlow
()
}
CircleRoomTypeArg
.
Group
->
get
FilteredRoomsFlow
{
(
it
.
roomType
==
GROUP_TYPE
&&
it
.
membership
==
Membership
.
JOIN
)
}
CircleRoomTypeArg
.
Photo
->
get
FilteredRoomsFlow
{
(
it
.
roomType
==
GALLERY_TYPE
&&
it
.
membership
==
Membership
.
JOIN
)
}
CircleRoomTypeArg
.
Group
->
get
GroupsLiveData
(
listOf
(
Membership
.
JOIN
)
).
asFlow
()
CircleRoomTypeArg
.
Photo
->
get
GalleriesLiveData
(
listOf
(
Membership
.
JOIN
)
).
asFlow
()
}
fun
getSelectedRooms
()
=
selectedRoomsFlow
.
value
.
filter
{
it
.
isSelected
}
...
...
@@ -64,13 +65,6 @@ class SelectRoomsDataSource @Inject constructor(
selectedRoomsFlow
.
value
=
list
}
private
fun
getFilteredRoomsFlow
(
filter
:
(
summary
:
RoomSummary
)
->
Boolean
)
=
session
?.
roomService
()
?.
getRoomSummariesLive
(
roomSummaryQueryParams
{
excludeType
=
null
})
?.
map
{
summaries
->
summaries
.
mapNotNull
{
summary
->
if
(
filter
(
summary
))
summary
else
null
}
}
?.
asFlow
()
?:
emptyFlow
()
private
fun
List
<
SelectableRoomListItem
>.
containsWithId
(
id
:
String
)
=
firstOrNull
{
it
.
id
==
id
}
!=
null
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment