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
353becb9
Commit
353becb9
authored
1 year ago
by
Taras
Browse files
Options
Downloads
Patches
Plain Diff
Use filter datasource on select timelines screen
parent
5a607082
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
core/src/main/java/org/futo/circles/core/feature/circles/filter/FilterTimelinesDataSource.kt
+8
-36
8 additions, 36 deletions
.../core/feature/circles/filter/FilterTimelinesDataSource.kt
with
8 additions
and
36 deletions
core/src/main/java/org/futo/circles/core/feature/circles/filter/FilterTimelinesDataSource.kt
+
8
−
36
View file @
353becb9
...
...
@@ -8,40 +8,35 @@ import kotlinx.coroutines.flow.MutableStateFlow
import
kotlinx.coroutines.flow.combine
import
kotlinx.coroutines.flow.flowOn
import
kotlinx.coroutines.flow.update
import
org.futo.circles.core.extensions.createResult
import
org.futo.circles.core.extensions.getOrThrow
import
org.futo.circles.core.model.toFilterTimelinesListItem
import
org.futo.circles.core.provider.MatrixSessionProvider
import
org.futo.circles.core.utils.getTimelineRoomFor
import
org.matrix.android.sdk.api.session.getRoom
import
javax.inject.Inject
class
FilterTimelinesDataSource
@Inject
constructor
(
savedStateHandle
:
SavedStateHandle
savedStateHandle
:
SavedStateHandle
,
private
val
circleFilterAccountDataManager
:
CircleFilterAccountDataManager
)
{
private
val
circleId
:
String
=
savedStateHandle
.
getOrThrow
(
"circleId"
)
private
val
session
=
MatrixSessionProvider
.
getSessionOrThrow
()
val
circleSummaryLiveData
=
session
.
roomService
().
getRoomSummaryLive
(
circleId
)
private
val
selectedTimelinesIds
=
MutableStateFlow
(
getCircleFilter
())
private
val
selectedTimelinesIds
=
MutableStateFlow
(
circleFilterAccountDataManager
.
getCircleFilter
(
circleId
))
val
timelinesLiveData
=
combine
(
circleSummaryLiveData
.
asFlow
(),
selectedTimelinesIds
)
{
_
,
selectedIds
->
getAllTimelinesIds
().
mapNotNull
{
circleFilterAccountDataManager
.
getAllTimelinesIds
(
circleId
).
mapNotNull
{
session
.
getRoom
(
it
)
?.
roomSummary
()
?.
toFilterTimelinesListItem
(
selectedIds
.
contains
(
it
))
}
}.
flowOn
(
Dispatchers
.
IO
).
asLiveData
()
suspend
fun
applyFilter
()
=
createResult
{
session
.
getRoom
(
circleId
)
?.
roomAccountDataService
()
?.
updateAccountData
(
CIRCLE_FILTER_EVENT_TYPE
,
mapOf
(
TIMELINES_KEY
to
selectedTimelinesIds
.
value
)
)
}
suspend
fun
applyFilter
()
=
circleFilterAccountDataManager
.
updateFilter
(
circleId
,
selectedTimelinesIds
.
value
)
fun
toggleItemSelected
(
roomId
:
String
)
{
val
isItemSelected
=
selectedTimelinesIds
.
value
.
contains
(
roomId
)
...
...
@@ -54,30 +49,7 @@ class FilterTimelinesDataSource @Inject constructor(
}
fun
selectAllTimelines
()
{
selectedTimelinesIds
.
update
{
getAllTimelinesIds
()
}
}
private
fun
getCircleFilter
():
Set
<
String
>
{
val
content
=
session
.
getRoom
(
circleId
)
?.
roomAccountDataService
()
?.
getAccountDataEvent
(
CIRCLE_FILTER_EVENT_TYPE
)
?.
content
?:
return
getAllTimelinesIds
()
return
(
content
[
TIMELINES_KEY
]
as
?
List
<
*
>)
?.
map
{
it
.
toString
()
}
?.
toSet
()
?:
getAllTimelinesIds
()
selectedTimelinesIds
.
update
{
circleFilterAccountDataManager
.
getAllTimelinesIds
(
circleId
)
}
}
private
fun
getAllTimelinesIds
():
Set
<
String
>
{
val
children
=
session
.
getRoom
(
circleId
)
?.
roomSummary
()
?.
spaceChildren
?:
emptyList
()
val
myTimelineId
=
getTimelineRoomFor
(
circleId
)
?.
roomId
return
children
.
mapNotNull
{
val
timelineSummary
=
session
.
getRoom
(
it
.
childRoomId
)
?.
roomSummary
()
?.
takeIf
{
summary
->
summary
.
membership
.
isActive
()
&&
summary
.
roomId
!=
myTimelineId
}
timelineSummary
?.
roomId
}.
toSet
()
}
companion
object
{
private
const
val
CIRCLE_FILTER_EVENT_TYPE
=
"m.circle.filter"
private
const
val
TIMELINES_KEY
=
"timelines"
}
}
\ 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