This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Account posts paging refactor (#563)
- moving to the new paging methods for account timelines --------- Co-authored-by: John Oberhauser <j.git-global@obez.io>
- Loading branch information
1 parent
df37ca7
commit b11b10a
Showing
12 changed files
with
137 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...ging/src/main/kotlin/social/firefly/core/repository/paging/pagers/AccountTimelinePager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package social.firefly.core.repository.paging.pagers | ||
|
||
import androidx.paging.PagingSource | ||
import social.firefly.core.database.model.entities.statusCollections.AccountTimelineStatusWrapper | ||
import social.firefly.core.model.AccountTimelineType | ||
import social.firefly.core.model.PageItem | ||
import social.firefly.core.model.Status | ||
import social.firefly.core.model.paging.MastodonPagedResponse | ||
import social.firefly.core.repository.mastodon.AccountRepository | ||
import social.firefly.core.repository.mastodon.DatabaseDelegate | ||
import social.firefly.core.repository.mastodon.TimelineRepository | ||
import social.firefly.core.repository.mastodon.model.status.toExternalModel | ||
import social.firefly.core.repository.paging.IdBasedPager | ||
import social.firefly.core.usecase.mastodon.status.GetInReplyToAccountNames | ||
import social.firefly.core.usecase.mastodon.status.SaveStatusToDatabase | ||
|
||
class AccountTimelinePager( | ||
private val accountId: String, | ||
private val timelineType: AccountTimelineType, | ||
private val accountRepository: AccountRepository, | ||
private val databaseDelegate: DatabaseDelegate, | ||
private val timelineRepository: TimelineRepository, | ||
private val saveStatusToDatabase: SaveStatusToDatabase, | ||
private val getInReplyToAccountNames: GetInReplyToAccountNames, | ||
) : IdBasedPager<Status, AccountTimelineStatusWrapper> { | ||
override fun mapDbObjectToExternalModel(dbo: AccountTimelineStatusWrapper): Status = | ||
dbo.status.toExternalModel() | ||
|
||
override suspend fun saveLocally(items: List<PageItem<Status>>, isRefresh: Boolean) { | ||
databaseDelegate.withTransaction { | ||
if (isRefresh) { | ||
timelineRepository.deleteAccountTimeline(accountId, timelineType) | ||
} | ||
|
||
val statuses = items.map { it.item } | ||
|
||
saveStatusToDatabase(statuses) | ||
timelineRepository.insertAllIntoAccountTimeline(statuses, timelineType) | ||
} | ||
} | ||
|
||
override suspend fun getRemotely(limit: Int, nextKey: String?): MastodonPagedResponse<Status> { | ||
val response = accountRepository.getAccountStatuses( | ||
accountId = accountId, | ||
maxId = nextKey, | ||
minId = null, | ||
loadSize = limit, | ||
onlyMedia = timelineType == AccountTimelineType.MEDIA, | ||
excludeReplies = timelineType == AccountTimelineType.POSTS, | ||
) | ||
|
||
return getInReplyToAccountNames(response) | ||
} | ||
|
||
override fun pagingSource(): PagingSource<Int, AccountTimelineStatusWrapper> = | ||
timelineRepository.accountTimelinePagingSource( | ||
accountId = accountId, | ||
timelineType = timelineType, | ||
) | ||
} |
Oops, something went wrong.