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
52c1576f
Commit
52c1576f
authored
1 year ago
by
Taras
Browse files
Options
Downloads
Patches
Plain Diff
Use category ds in people ds
parent
d2571ca5
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/people/PeopleDataSource.kt
+20
-63
20 additions, 63 deletions
.../java/org/futo/circles/feature/people/PeopleDataSource.kt
with
20 additions
and
63 deletions
app/src/main/java/org/futo/circles/feature/people/PeopleDataSource.kt
+
20
−
63
View file @
52c1576f
...
...
@@ -8,39 +8,29 @@ import kotlinx.coroutines.flow.combine
import
kotlinx.coroutines.flow.distinctUntilChanged
import
kotlinx.coroutines.flow.flowOf
import
kotlinx.coroutines.withContext
import
org.futo.circles.core.extensions.getRoomOwner
import
org.futo.circles.core.feature.room.knoks.KnockRequestsDataSource
import
org.futo.circles.core.feature.select_users.SearchUserDataSource
import
org.futo.circles.core.feature.workspace.SharedCircleDataSource
import
org.futo.circles.core.feature.workspace.SpacesTreeAccountDataSource
import
org.futo.circles.core.model.CIRCLES_SPACE_ACCOUNT_DATA_KEY
import
org.futo.circles.core.provider.MatrixSessionProvider
import
org.futo.circles.core.utils.getJoinedRoomById
import
org.futo.circles.core.utils.getSpacesLiveData
import
org.futo.circles.
core.utils.getTimelineRoomFor
import
org.futo.circles.
feature.people.category.PeopleCategoryDataSource
import
org.futo.circles.mapping.toPeopleUserListItem
import
org.futo.circles.model.PeopleCategoryListItem
import
org.futo.circles.model.PeopleListItem
import
org.futo.circles.model.PeopleRequestNotificationListItem
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.user.model.User
import
javax.inject.Inject
class
PeopleDataSource
@Inject
constructor
(
private
val
searchUserDataSource
:
SearchUserDataSource
,
private
val
sharedCircleDataSource
:
SharedCircleDataSource
,
private
val
knockRequestsDataSource
:
KnockRequestsDataSource
,
private
val
spacesTreeAccountDataSource
:
SpacesTreeAccount
DataSource
private
val
peopleCategoryDataSource
:
PeopleCategory
DataSource
)
{
private
val
session
=
MatrixSessionProvider
.
getSessionOrThrow
()
private
val
profileRoomId
=
sharedCircleDataSource
.
getSharedCirclesSpaceId
()
?:
""
private
fun
getKnockRequestCountFlow
():
Flow
<
Int
>
=
knockRequestsDataSource
.
getKnockRequestsListItemsLiveData
(
profileRoomId
)
?.
map
{
it
.
size
}
?.
asFlow
()
?:
flowOf
()
knockRequestsDataSource
.
getKnockRequestsListItemsLiveData
(
peopleCategoryDataSource
.
getProfileRoomId
())
?.
map
{
it
.
size
}
?.
asFlow
()
?:
flowOf
()
private
fun
getProfileSpaceInvitesCountFlow
()
=
getSpacesLiveData
(
listOf
(
Membership
.
INVITE
)).
map
{
it
.
size
}.
asFlow
()
...
...
@@ -49,7 +39,7 @@ class PeopleDataSource @Inject constructor(
suspend
fun
getPeopleList
(
query
:
String
)
=
combine
(
searchUserDataSource
.
searchKnownUsers
(
query
),
searchUserDataSource
.
searchSuggestions
(
query
),
getIgnoredUserFlow
(),
peopleCategoryDataSource
.
getIgnoredUserFlow
(),
getKnockRequestCountFlow
(),
getProfileSpaceInvitesCountFlow
()
)
{
knowUsers
,
suggestions
,
ignoredUsers
,
knocksCount
,
profileInvitesCount
->
...
...
@@ -69,9 +59,6 @@ class PeopleDataSource @Inject constructor(
searchUserDataSource
.
loadAllRoomMembersIfNeeded
()
}
private
fun
getIgnoredUserFlow
()
=
session
.
userService
().
getIgnoredUsersLive
().
asFlow
()
private
fun
buildList
(
query
:
String
,
knowUsers
:
List
<
User
>,
...
...
@@ -106,55 +93,25 @@ class PeopleDataSource @Inject constructor(
):
List
<
PeopleListItem
>
{
val
list
=
mutableListOf
<
PeopleListItem
>()
val
requestsCount
=
knocksCount
+
profileInvitesCount
val
knownIds
=
knowUsers
.
map
{
it
.
userId
}
val
followingUsersIds
=
getPeopleImFollowingIds
()
val
followersUsersIds
=
getFollowersIds
()
val
connectionsIds
=
knowUsers
.
mapNotNull
{
if
(
isConnection
(
it
.
userId
))
it
.
userId
else
null
}
val
otherMemberIds
=
knownIds
-
connectionsIds
.
toSet
()
-
followersUsersIds
.
toSet
()
-
followingUsersIds
.
toSet
()
val
followingUsers
=
peopleCategoryDataSource
.
getPeopleImFollowing
()
val
followersUsers
=
peopleCategoryDataSource
.
getFollowers
()
val
connections
=
peopleCategoryDataSource
.
getMyConnections
(
knowUsers
)
val
otherMembers
=
peopleCategoryDataSource
.
getOtherUsers
(
knowUsers
,
connections
,
followersUsers
,
followingUsers
)
list
.
apply
{
if
(
requestsCount
>
0
)
add
(
PeopleRequestNotificationListItem
(
requestsCount
))
add
(
PeopleCategoryListItem
.
connections
.
copy
(
count
=
connections
Ids
.
size
))
add
(
PeopleCategoryListItem
.
followingUsers
.
copy
(
count
=
followingUsers
Ids
.
size
))
add
(
PeopleCategoryListItem
.
followersUsers
.
copy
(
count
=
followersUsers
Ids
.
size
))
add
(
PeopleCategoryListItem
.
others
.
copy
(
count
=
otherMember
Id
s
.
size
))
add
(
PeopleCategoryListItem
.
connections
.
copy
(
count
=
connections
.
size
))
add
(
PeopleCategoryListItem
.
followingUsers
.
copy
(
count
=
followingUsers
.
size
))
add
(
PeopleCategoryListItem
.
followersUsers
.
copy
(
count
=
followersUsers
.
size
))
add
(
PeopleCategoryListItem
.
others
.
copy
(
count
=
otherMembers
.
size
))
add
(
PeopleCategoryListItem
.
ignored
.
copy
(
count
=
ignoredUsers
.
size
))
}
return
list
}
//All the joined members (except me) in all of my circle timeline rooms
private
fun
getFollowersIds
():
List
<
String
>
{
val
myCirclesSpace
=
getMyCirclesSpaceSummary
()
?:
return
emptyList
()
val
myTimelinesFollowers
=
myCirclesSpace
.
spaceChildren
?.
mapNotNull
{
getTimelineRoomFor
(
it
.
childRoomId
)
?.
roomSummary
()
?.
otherMemberIds
}
?.
flatMap
{
it
.
toSet
()
}
?:
emptyList
()
return
myTimelinesFollowers
}
//All the creators of all the timeline rooms that I'm following in my circles
private
fun
getPeopleImFollowingIds
():
List
<
String
>
{
val
myCirclesSpace
=
getMyCirclesSpaceSummary
()
?:
return
emptyList
()
val
peopleIamFollowing
=
myCirclesSpace
.
spaceChildren
?.
mapNotNull
{
getJoinedRoomById
(
it
.
childRoomId
)
?.
roomSummary
()
?.
spaceChildren
?.
mapNotNull
{
getRoomOwner
(
it
.
childRoomId
)
?.
userId
?.
takeIf
{
it
!=
session
.
myUserId
}
}
}
?.
flatMap
{
it
.
toSet
()
}
?:
emptyList
()
return
peopleIamFollowing
}
private
fun
getMyCirclesSpaceSummary
():
RoomSummary
?
{
val
circlesSpaceId
=
spacesTreeAccountDataSource
.
getRoomIdByKey
(
CIRCLES_SPACE_ACCOUNT_DATA_KEY
)
?:
""
return
getJoinedRoomById
(
circlesSpaceId
)
?.
roomSummary
()
}
private
fun
isConnection
(
userId
:
String
)
=
sharedCircleDataSource
.
getSharedCircleFor
(
userId
)
!=
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