chore: code format and define onceRequestTootMaxCount

This commit is contained in:
sunxiaojian 2021-02-18 12:49:24 +08:00
parent b55790fee8
commit 99f2e4a854
8 changed files with 23 additions and 16 deletions

View File

@ -85,15 +85,17 @@ extension TimelineSection {
cell.timelinePostView.activeTextLabel.config(content: toot.content)
// toolbar
let isLike = (toot.reblog ?? toot).favouritedBy.flatMap({ $0.contains(where: { $0.id == requestUserID }) }) ?? false
let isLike = (toot.reblog ?? toot).favouritedBy.flatMap { $0.contains(where: { $0.id == requestUserID }) } ?? false
let favoriteCountTitle: String = {
let count = (toot.reblog ?? toot).favouritesCount.intValue
return TimelineSection.formattedNumberTitleForActionButton(count)
}()
cell.timelinePostView.actionToolbarContainer.starButton.setTitle(favoriteCountTitle, for: .normal)
cell.timelinePostView.actionToolbarContainer.isStarButtonHighlight = isLike
// set date
let createdAt = (toot.reblog ?? toot).createdAt
cell.timelinePostView.dateLabel.text = createdAt.shortTimeAgoSinceNow
timestampUpdatePublisher
.sink { _ in
cell.timelinePostView.dateLabel.text = createdAt.shortTimeAgoSinceNow
@ -106,16 +108,16 @@ extension TimelineSection {
.sink { _ in
// do nothing
} receiveValue: { change in
guard case let .update(object) = change.changeType,
guard case .update(let object) = change.changeType,
let newToot = object as? Toot else { return }
let targetToot = newToot.reblog ?? newToot
let isLike = targetToot.favouritedBy.flatMap({ $0.contains(where: { $0.id == requestUserID }) }) ?? false
let isLike = targetToot.favouritedBy.flatMap { $0.contains(where: { $0.id == requestUserID }) } ?? false
let favoriteCount = targetToot.favouritesCount.intValue
let favoriteCountTitle = TimelineSection.formattedNumberTitleForActionButton(favoriteCount)
cell.timelinePostView.actionToolbarContainer.starButton.setTitle(favoriteCountTitle, for: .normal)
cell.timelinePostView.actionToolbarContainer.isStarButtonHighlight = isLike
os_log("%{public}s[%{public}ld], %{public}s: like count label for tweet %s did update: %ld", ((#file as NSString).lastPathComponent), #line, #function, targetToot.id, favoriteCount )
os_log("%{public}s[%{public}ld], %{public}s: like count label for toot %s did update: %ld", (#file as NSString).lastPathComponent, #line, #function, targetToot.id, favoriteCount)
}
.store(in: &cell.disposeBag)
}

View File

@ -65,7 +65,7 @@ extension HomeTimelineViewModel.LoadLatestState {
let endFetch = CACurrentMediaTime()
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: collect timelineIndexes cost: %.2fs", ((#file as NSString).lastPathComponent), #line, #function, endFetch - start)
latestTootIDs = timelineIndexes
.prefix(200) // avoid performance issue
.prefix(APIService.onceRequestTootMaxCount) // avoid performance issue
.compactMap { timelineIndex in
timelineIndex.value(forKeyPath: #keyPath(HomeTimelineIndex.toot.id)) as? Toot.ID
}

View File

@ -124,7 +124,7 @@ extension APIService {
extension APIService {
func likeList(
limit: Int = 200,
limit: Int = onceRequestTootMaxCount,
userID: String,
maxID: String? = nil,
mastodonAuthenticationBox: AuthenticationService.MastodonAuthenticationBox

View File

@ -19,7 +19,7 @@ extension APIService {
domain: String,
sinceID: Mastodon.Entity.Status.ID? = nil,
maxID: Mastodon.Entity.Status.ID? = nil,
limit: Int = 100,
limit: Int = onceRequestTootMaxCount,
local: Bool? = nil,
authorizationBox: AuthenticationService.MastodonAuthenticationBox
) -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Status]>, Error> {

View File

@ -21,7 +21,7 @@ extension APIService {
domain: String,
sinceID: Mastodon.Entity.Status.ID? = nil,
maxID: Mastodon.Entity.Status.ID? = nil,
limit: Int = 100
limit: Int = onceRequestTootMaxCount
) -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Status]>, Error> {
let query = Mastodon.API.Timeline.PublicTimelineQuery(
local: nil,

View File

@ -43,6 +43,11 @@ final class APIService {
}
extension APIService {
public static let onceRequestTootMaxCount = 100
public static let onceRequestUserMaxCount = 100
}
extension APIService {
public enum Persist { }
public enum CoreData { }