forked from zelo72/mastodon-ios
chore: code format and define onceRequestTootMaxCount
This commit is contained in:
parent
b55790fee8
commit
99f2e4a854
|
@ -45,19 +45,19 @@ extension TimelineSection {
|
||||||
// configure cell
|
// configure cell
|
||||||
managedObjectContext.performAndWait {
|
managedObjectContext.performAndWait {
|
||||||
let toot = managedObjectContext.object(with: objectID) as! Toot
|
let toot = managedObjectContext.object(with: objectID) as! Toot
|
||||||
TimelineSection.configure(cell: cell, timestampUpdatePublisher: timestampUpdatePublisher, toot: toot, requestUserID:requestUserID)
|
TimelineSection.configure(cell: cell, timestampUpdatePublisher: timestampUpdatePublisher, toot: toot, requestUserID: requestUserID)
|
||||||
}
|
}
|
||||||
cell.delegate = timelinePostTableViewCellDelegate
|
cell.delegate = timelinePostTableViewCellDelegate
|
||||||
return cell
|
return cell
|
||||||
case .publicMiddleLoader(let upperTimelineTootID):
|
case .publicMiddleLoader(let upperTimelineTootID):
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineMiddleLoaderTableViewCell.self), for: indexPath) as! TimelineMiddleLoaderTableViewCell
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineMiddleLoaderTableViewCell.self), for: indexPath) as! TimelineMiddleLoaderTableViewCell
|
||||||
cell.delegate = timelineMiddleLoaderTableViewCellDelegate
|
cell.delegate = timelineMiddleLoaderTableViewCellDelegate
|
||||||
timelineMiddleLoaderTableViewCellDelegate?.configure(cell: cell, upperTimelineTootID: upperTimelineTootID,timelineIndexobjectID: nil)
|
timelineMiddleLoaderTableViewCellDelegate?.configure(cell: cell, upperTimelineTootID: upperTimelineTootID, timelineIndexobjectID: nil)
|
||||||
return cell
|
return cell
|
||||||
case .homeMiddleLoader(let upperTimelineIndexObjectID):
|
case .homeMiddleLoader(let upperTimelineIndexObjectID):
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineMiddleLoaderTableViewCell.self), for: indexPath) as! TimelineMiddleLoaderTableViewCell
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineMiddleLoaderTableViewCell.self), for: indexPath) as! TimelineMiddleLoaderTableViewCell
|
||||||
cell.delegate = timelineMiddleLoaderTableViewCellDelegate
|
cell.delegate = timelineMiddleLoaderTableViewCellDelegate
|
||||||
timelineMiddleLoaderTableViewCellDelegate?.configure(cell: cell, upperTimelineTootID: nil,timelineIndexobjectID: upperTimelineIndexObjectID)
|
timelineMiddleLoaderTableViewCellDelegate?.configure(cell: cell, upperTimelineTootID: nil, timelineIndexobjectID: upperTimelineIndexObjectID)
|
||||||
return cell
|
return cell
|
||||||
case .bottomLoader:
|
case .bottomLoader:
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
|
||||||
|
@ -83,39 +83,41 @@ extension TimelineSection {
|
||||||
)
|
)
|
||||||
// set text
|
// set text
|
||||||
cell.timelinePostView.activeTextLabel.config(content: toot.content)
|
cell.timelinePostView.activeTextLabel.config(content: toot.content)
|
||||||
|
|
||||||
// toolbar
|
// 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 favoriteCountTitle: String = {
|
||||||
let count = (toot.reblog ?? toot).favouritesCount.intValue
|
let count = (toot.reblog ?? toot).favouritesCount.intValue
|
||||||
return TimelineSection.formattedNumberTitleForActionButton(count)
|
return TimelineSection.formattedNumberTitleForActionButton(count)
|
||||||
}()
|
}()
|
||||||
cell.timelinePostView.actionToolbarContainer.starButton.setTitle(favoriteCountTitle, for: .normal)
|
cell.timelinePostView.actionToolbarContainer.starButton.setTitle(favoriteCountTitle, for: .normal)
|
||||||
cell.timelinePostView.actionToolbarContainer.isStarButtonHighlight = isLike
|
cell.timelinePostView.actionToolbarContainer.isStarButtonHighlight = isLike
|
||||||
|
|
||||||
// set date
|
// set date
|
||||||
let createdAt = (toot.reblog ?? toot).createdAt
|
let createdAt = (toot.reblog ?? toot).createdAt
|
||||||
|
cell.timelinePostView.dateLabel.text = createdAt.shortTimeAgoSinceNow
|
||||||
timestampUpdatePublisher
|
timestampUpdatePublisher
|
||||||
.sink { _ in
|
.sink { _ in
|
||||||
cell.timelinePostView.dateLabel.text = createdAt.shortTimeAgoSinceNow
|
cell.timelinePostView.dateLabel.text = createdAt.shortTimeAgoSinceNow
|
||||||
}
|
}
|
||||||
.store(in: &cell.disposeBag)
|
.store(in: &cell.disposeBag)
|
||||||
|
|
||||||
// observe model change
|
// observe model change
|
||||||
ManagedObjectObserver.observe(object: toot.reblog ?? toot)
|
ManagedObjectObserver.observe(object: toot.reblog ?? toot)
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { _ in
|
.sink { _ in
|
||||||
// do nothing
|
// do nothing
|
||||||
} receiveValue: { change in
|
} 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 newToot = object as? Toot else { return }
|
||||||
let targetToot = newToot.reblog ?? newToot
|
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 favoriteCount = targetToot.favouritesCount.intValue
|
||||||
let favoriteCountTitle = TimelineSection.formattedNumberTitleForActionButton(favoriteCount)
|
let favoriteCountTitle = TimelineSection.formattedNumberTitleForActionButton(favoriteCount)
|
||||||
cell.timelinePostView.actionToolbarContainer.starButton.setTitle(favoriteCountTitle, for: .normal)
|
cell.timelinePostView.actionToolbarContainer.starButton.setTitle(favoriteCountTitle, for: .normal)
|
||||||
cell.timelinePostView.actionToolbarContainer.isStarButtonHighlight = isLike
|
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)
|
.store(in: &cell.disposeBag)
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ extension HomeTimelineViewModel.LoadLatestState {
|
||||||
let endFetch = CACurrentMediaTime()
|
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)
|
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
|
latestTootIDs = timelineIndexes
|
||||||
.prefix(200) // avoid performance issue
|
.prefix(APIService.onceRequestTootMaxCount) // avoid performance issue
|
||||||
.compactMap { timelineIndex in
|
.compactMap { timelineIndex in
|
||||||
timelineIndex.value(forKeyPath: #keyPath(HomeTimelineIndex.toot.id)) as? Toot.ID
|
timelineIndex.value(forKeyPath: #keyPath(HomeTimelineIndex.toot.id)) as? Toot.ID
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import os.log
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
protocol TimelineMiddleLoaderTableViewCellDelegate: class {
|
protocol TimelineMiddleLoaderTableViewCellDelegate: class {
|
||||||
func configure(cell: TimelineMiddleLoaderTableViewCell, upperTimelineTootID: String?,timelineIndexobjectID:NSManagedObjectID?)
|
func configure(cell: TimelineMiddleLoaderTableViewCell, upperTimelineTootID: String?, timelineIndexobjectID:NSManagedObjectID?)
|
||||||
func timelineMiddleLoaderTableViewCell(_ cell: TimelineMiddleLoaderTableViewCell, loadMoreButtonDidPressed button: UIButton)
|
func timelineMiddleLoaderTableViewCell(_ cell: TimelineMiddleLoaderTableViewCell, loadMoreButtonDidPressed button: UIButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ extension APIService {
|
||||||
|
|
||||||
extension APIService {
|
extension APIService {
|
||||||
func likeList(
|
func likeList(
|
||||||
limit: Int = 200,
|
limit: Int = onceRequestTootMaxCount,
|
||||||
userID: String,
|
userID: String,
|
||||||
maxID: String? = nil,
|
maxID: String? = nil,
|
||||||
mastodonAuthenticationBox: AuthenticationService.MastodonAuthenticationBox
|
mastodonAuthenticationBox: AuthenticationService.MastodonAuthenticationBox
|
||||||
|
|
|
@ -19,7 +19,7 @@ extension APIService {
|
||||||
domain: String,
|
domain: String,
|
||||||
sinceID: Mastodon.Entity.Status.ID? = nil,
|
sinceID: Mastodon.Entity.Status.ID? = nil,
|
||||||
maxID: Mastodon.Entity.Status.ID? = nil,
|
maxID: Mastodon.Entity.Status.ID? = nil,
|
||||||
limit: Int = 100,
|
limit: Int = onceRequestTootMaxCount,
|
||||||
local: Bool? = nil,
|
local: Bool? = nil,
|
||||||
authorizationBox: AuthenticationService.MastodonAuthenticationBox
|
authorizationBox: AuthenticationService.MastodonAuthenticationBox
|
||||||
) -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Status]>, Error> {
|
) -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Status]>, Error> {
|
||||||
|
|
|
@ -21,7 +21,7 @@ extension APIService {
|
||||||
domain: String,
|
domain: String,
|
||||||
sinceID: Mastodon.Entity.Status.ID? = nil,
|
sinceID: Mastodon.Entity.Status.ID? = nil,
|
||||||
maxID: 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> {
|
) -> AnyPublisher<Mastodon.Response.Content<[Mastodon.Entity.Status]>, Error> {
|
||||||
let query = Mastodon.API.Timeline.PublicTimelineQuery(
|
let query = Mastodon.API.Timeline.PublicTimelineQuery(
|
||||||
local: nil,
|
local: nil,
|
||||||
|
|
|
@ -43,6 +43,11 @@ final class APIService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension APIService {
|
||||||
|
public static let onceRequestTootMaxCount = 100
|
||||||
|
public static let onceRequestUserMaxCount = 100
|
||||||
|
}
|
||||||
|
|
||||||
extension APIService {
|
extension APIService {
|
||||||
public enum Persist { }
|
public enum Persist { }
|
||||||
public enum CoreData { }
|
public enum CoreData { }
|
||||||
|
|
|
@ -423,7 +423,7 @@ extension APIService.Persist {
|
||||||
let timelineIndex = status.homeTimelineIndexes?
|
let timelineIndex = status.homeTimelineIndexes?
|
||||||
.first { $0.userID == requestMastodonUserID }
|
.first { $0.userID == requestMastodonUserID }
|
||||||
if timelineIndex == nil {
|
if timelineIndex == nil {
|
||||||
let timelineIndexProperty = HomeTimelineIndex.Property(domain: domain,userID: requestMastodonUserID)
|
let timelineIndexProperty = HomeTimelineIndex.Property(domain: domain, userID: requestMastodonUserID)
|
||||||
|
|
||||||
let _ = HomeTimelineIndex.insert(
|
let _ = HomeTimelineIndex.insert(
|
||||||
into: managedObjectContext,
|
into: managedObjectContext,
|
||||||
|
|
Loading…
Reference in New Issue