Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal class ActivityCommentListImpl(
get() = _state

override suspend fun get(): Result<List<ThreadedCommentData>> {
return queryComments(query)
return queryComments(query, replace = true)
}

override suspend fun queryMoreComments(limit: Int?): Result<List<ThreadedCommentData>> {
Expand All @@ -75,11 +75,12 @@ internal class ActivityCommentListImpl(
}

private suspend fun queryComments(
query: ActivityCommentsQuery
query: ActivityCommentsQuery,
replace: Boolean = false,
): Result<List<ThreadedCommentData>> {
return commentsRepository
.getComments(query)
.onSuccess { _state.onQueryMoreComments(it) }
.onSuccess { _state.onQueryComments(it, replace) }
.map { it.models }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ internal class ActivityCommentListStateImpl(
_comments.update { emptyList() }
}

override fun onQueryMoreComments(result: PaginationResult<ThreadedCommentData>) {
override fun onQueryComments(result: PaginationResult<ThreadedCommentData>, replace: Boolean) {
_pagination = result.pagination
_comments.update { current ->
current.mergeSorted(result.models, ThreadedCommentData::id, commentsComparator)
if (replace) {
_comments.update { result.models }
} else {
_comments.update { current ->
current.mergeSorted(result.models, ThreadedCommentData::id, commentsComparator)
}
}
}

Expand Down Expand Up @@ -165,9 +169,10 @@ internal interface ActivityCommentListStateUpdates {
/**
* Handles the result of a query for comments.
*
* @param result The pagination result containing the new comments.
* @param result The pagination result containing the comments.
* @param replace If true, replaces the current state; otherwise, merges with it.
*/
fun onQueryMoreComments(result: PaginationResult<ThreadedCommentData>)
fun onQueryComments(result: PaginationResult<ThreadedCommentData>, replace: Boolean = false)

/**
* Handles the removal of a comment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal class ActivityListImpl(
get() = _state

override suspend fun get(): Result<List<ActivityData>> {
return queryActivities(query)
return queryActivities(query, replace = true)
}

override suspend fun queryMoreActivities(limit: Int?): Result<List<ActivityData>> {
Expand All @@ -86,11 +86,14 @@ internal class ActivityListImpl(
return queryActivities(nextQuery)
}

private suspend fun queryActivities(query: ActivitiesQuery): Result<List<ActivityData>> {
private suspend fun queryActivities(
query: ActivitiesQuery,
replace: Boolean = false,
): Result<List<ActivityData>> {
return activitiesRepository
.queryActivities(query)
.onSuccess {
_state.onQueryMoreActivities(it, QueryConfiguration(query.filter, query.sort))
_state.onQueryActivities(it, QueryConfiguration(query.filter, query.sort), replace)
feedOwnValuesRepository.cache(it.models.mapNotNull(ActivityData::currentFeed))
}
.map { it.models }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,20 @@ internal class ActivityListStateImpl(
override val pagination: PaginationData?
get() = _pagination

override fun onQueryMoreActivities(
override fun onQueryActivities(
result: PaginationResult<ActivityData>,
queryConfig: ActivitiesQueryConfig,
replace: Boolean,
) {
_pagination = result.pagination
// Update the query configuration for future queries
this.queryConfig = queryConfig
// Merge the new activities with the existing ones (keeping the sort order)
_activities.update { current ->
current.mergeSorted(result.models, ActivityData::id, activitiesSorting)
if (replace) {
_activities.update { result.models }
} else {
// Merge the new activities with the existing ones (keeping the sort order)
_activities.update { current ->
current.mergeSorted(result.models, ActivityData::id, activitiesSorting)
}
}
}

Expand Down Expand Up @@ -243,14 +247,17 @@ internal interface ActivityListMutableState : ActivityListState, ActivityListSta
internal interface ActivityListStateUpdates {

/**
* Called when more activities are queried and received.
* Called when activities are queried and received.
*
* @param result The result containing the new activities and pagination information.
* @param result The result containing the activities and pagination information.
* @param queryConfig The configuration used for the query, including sorting and filtering.
* @param replace If true, replaces the current activities; if false, merges with the existing
* ones keeping the sort order.
*/
fun onQueryMoreActivities(
fun onQueryActivities(
result: PaginationResult<ActivityData>,
queryConfig: ActivitiesQueryConfig,
replace: Boolean = false,
)
Comment thread
gpunto marked this conversation as resolved.

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal class ActivityReactionListImpl(
get() = _state

override suspend fun get(): Result<List<FeedsReactionData>> {
return queryActivityReactions(query)
return queryActivityReactions(query, replace = true)
}

override suspend fun queryMoreReactions(limit: Int?): Result<List<FeedsReactionData>> {
Expand All @@ -80,14 +80,16 @@ internal class ActivityReactionListImpl(
}

private suspend fun queryActivityReactions(
query: ActivityReactionsQuery
query: ActivityReactionsQuery,
replace: Boolean = false,
): Result<List<FeedsReactionData>> {
return activitiesRepository
.queryActivityReactions(query.activityId, query.toRequest())
.onSuccess {
_state.onQueryMoreActivityReactions(
_state.onQueryActivityReactions(
result = it,
queryConfig = QueryConfiguration(query.filter, query.sort),
replace = replace,
)
}
.map { it.models }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,20 @@ internal class ActivityReactionListStateImpl(override val query: ActivityReactio
_reactions.update { emptyList() }
}

override fun onQueryMoreActivityReactions(
override fun onQueryActivityReactions(
result: PaginationResult<FeedsReactionData>,
queryConfig: ActivityReactionsQueryConfig,
replace: Boolean,
) {
_pagination = result.pagination
// Update the query configuration for future queries
this.queryConfig = queryConfig
// Merge the new reactions with the existing ones (keeping the sort order)
_reactions.update { current ->
current.mergeSorted(result.models, FeedsReactionData::id, reactionsSorting)
if (replace) {
_reactions.update { result.models }
} else {
// Merge the new reactions with the existing ones (keeping the sort order)
_reactions.update { current ->
current.mergeSorted(result.models, FeedsReactionData::id, reactionsSorting)
}
}
}

Expand Down Expand Up @@ -110,10 +114,12 @@ internal interface ActivityReactionListStateUpdates {
* @param result The result of the pagination query containing the reactions.
* @param queryConfig The configuration used for the query, including filters and sorting
* options.
* @param replace Whether to replace existing reactions or merge them with the new ones.
*/
fun onQueryMoreActivityReactions(
fun onQueryActivityReactions(
result: PaginationResult<FeedsReactionData>,
queryConfig: ActivityReactionsQueryConfig,
replace: Boolean = false,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal class BookmarkFolderListImpl(
get() = _state

override suspend fun get(): Result<List<BookmarkFolderData>> {
return queryBookmarkFolders(query)
return queryBookmarkFolders(query, replace = true)
}

override suspend fun queryMoreBookmarkFolders(limit: Int?): Result<List<BookmarkFolderData>> {
Expand All @@ -77,12 +77,17 @@ internal class BookmarkFolderListImpl(
}

private suspend fun queryBookmarkFolders(
query: BookmarkFoldersQuery
query: BookmarkFoldersQuery,
replace: Boolean = false,
): Result<List<BookmarkFolderData>> {
return bookmarksRepository
.queryBookmarkFolders(query)
.onSuccess {
_state.onQueryMoreBookmarkFolders(it, QueryConfiguration(query.filter, query.sort))
_state.onQueryBookmarkFolders(
it,
QueryConfiguration(query.filter, query.sort),
replace,
)
}
.map { it.models }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,21 @@ internal class BookmarkFolderListStateImpl(override val query: BookmarkFoldersQu
override val pagination: PaginationData?
get() = _pagination

override fun onQueryMoreBookmarkFolders(
override fun onQueryBookmarkFolders(
result: PaginationResult<BookmarkFolderData>,
queryConfig: BookmarkFoldersQueryConfig,
replace: Boolean,
) {
_pagination = result.pagination
// Update the query configuration for future queries
this.queryConfig = queryConfig
// Merge the new folders with the existing ones (keeping the sort order)
_folders.update { current ->
current.mergeSorted(result.models, BookmarkFolderData::id, foldersSorting)
if (replace) {
_folders.update { result.models }
} else {
// Merge the new folders with the existing ones (keeping the sort order)
_folders.update { current ->
current.mergeSorted(result.models, BookmarkFolderData::id, foldersSorting)
}
}
}

Expand Down Expand Up @@ -96,13 +101,16 @@ internal interface BookmarkFolderListMutableState :
internal interface BookmarkFolderListStateUpdates {

/**
* Called when more bookmark folders are queried.
* Called when bookmark folders are queried.
*
* @param result The result containing the new bookmark folders and pagination data.
* @param result The result containing the bookmark folders and pagination data.
* @param queryConfig The query configuration used for the query.
* @param replace If true, replaces the current folders; otherwise, merges with existing ones.
*/
fun onQueryMoreBookmarkFolders(
fun onQueryBookmarkFolders(
result: PaginationResult<BookmarkFolderData>,
queryConfig: BookmarkFoldersQueryConfig,
replace: Boolean = false,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal class BookmarkListImpl(
get() = _state

override suspend fun get(): Result<List<BookmarkData>> {
return queryBookmarks(query)
return queryBookmarks(query, replace = true)
}

override suspend fun queryMoreBookmarks(limit: Int?): Result<List<BookmarkData>> {
Expand All @@ -75,11 +75,14 @@ internal class BookmarkListImpl(
return queryBookmarks(nextQuery)
}

private suspend fun queryBookmarks(query: BookmarksQuery): Result<List<BookmarkData>> {
private suspend fun queryBookmarks(
query: BookmarksQuery,
replace: Boolean = false,
): Result<List<BookmarkData>> {
return bookmarksRepository
.queryBookmarks(query)
.onSuccess {
_state.onQueryMoreBookmarks(it, QueryConfiguration(query.filter, query.sort))
_state.onQueryBookmarks(it, QueryConfiguration(query.filter, query.sort), replace)
}
.map { it.models }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,20 @@ internal class BookmarkListStateImpl(override val query: BookmarksQuery) :
override val pagination: PaginationData?
get() = _pagination

override fun onQueryMoreBookmarks(
override fun onQueryBookmarks(
result: PaginationResult<BookmarkData>,
queryConfig: BookmarksQueryConfig,
replace: Boolean,
) {
_pagination = result.pagination
// Update the query configuration for future queries
this.queryConfig = queryConfig
// Merge the new bookmarks with the existing ones (keeping the sort order)
_bookmarks.update { current ->
current.mergeSorted(result.models, BookmarkData::id, bookmarksSorting)
if (replace) {
_bookmarks.update { result.models }
} else {
// Merge the new bookmarks with the existing ones (keeping the sort order)
_bookmarks.update { current ->
current.mergeSorted(result.models, BookmarkData::id, bookmarksSorting)
}
}
}

Expand Down Expand Up @@ -120,9 +124,10 @@ internal interface BookmarkListMutableState : BookmarkListState, BookmarkListSta
/** An interface that defines the methods for updating the state of a bookmark list. */
internal interface BookmarkListStateUpdates {

fun onQueryMoreBookmarks(
fun onQueryBookmarks(
result: PaginationResult<BookmarkData>,
queryConfig: BookmarksQueryConfig,
replace: Boolean = false,
)

fun onBookmarkFolderRemoved(folderId: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal class CommentListImpl(
get() = _state

override suspend fun get(): Result<List<CommentData>> {
return queryComments(query)
return queryComments(query, replace = true)
}

override suspend fun queryMoreComments(limit: Int?): Result<List<CommentData>> {
Expand All @@ -69,9 +69,13 @@ internal class CommentListImpl(
return queryComments(nextQuery)
}

private suspend fun queryComments(query: CommentsQuery): Result<List<CommentData>> {
return commentsRepository.queryComments(query).onSuccess(_state::onQueryMoreComments).map {
it.models
}
private suspend fun queryComments(
query: CommentsQuery,
replace: Boolean = false,
): Result<List<CommentData>> {
return commentsRepository
.queryComments(query)
.onSuccess { _state.onQueryComments(it, replace) }
.map { it.models }
}
}
Loading
Loading