mirror of
https://github.com/metabolist/metatext.git
synced 2025-02-16 14:05:14 +00:00
Refactoring
This commit is contained in:
parent
4c6e242215
commit
ce09e8fd7b
5 changed files with 19 additions and 22 deletions
|
@ -33,10 +33,11 @@ extension ContextItemsInfo {
|
|||
let hasReplyFollowing = section.count > index + 1
|
||||
&& section[index + 1].record.inReplyToId == statusInfo.record.id
|
||||
|
||||
return .status(.init(status: .init(info: statusInfo),
|
||||
isContextParent: statusInfo.record.id == parent.record.id,
|
||||
isReplyInContext: isReplyInContext,
|
||||
hasReplyFollowing: hasReplyFollowing))
|
||||
return .status(
|
||||
.init(info: statusInfo),
|
||||
.init(isContextParent: statusInfo.record.id == parent.record.id,
|
||||
isReplyInContext: isReplyInContext,
|
||||
hasReplyFollowing: hasReplyFollowing))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,13 +32,13 @@ extension TimelineItemsInfo {
|
|||
let timeline = Timeline(record: timelineRecord)!
|
||||
let filterRegularExpression = filters.regularExpression(context: timeline.filterContext)
|
||||
var timelineItems = statusInfos.filtered(regularExpression: filterRegularExpression)
|
||||
.map { CollectionItem.status(.init(status: .init(info: $0))) }
|
||||
.map { CollectionItem.status(.init(info: $0), .init()) }
|
||||
|
||||
for loadMoreRecord in loadMoreRecords {
|
||||
guard let index = timelineItems.firstIndex(where: {
|
||||
guard case let .status(configuration) = $0 else { return false }
|
||||
guard case let .status(status, _) = $0 else { return false }
|
||||
|
||||
return loadMoreRecord.afterStatusId > configuration.status.id
|
||||
return loadMoreRecord.afterStatusId > status.id
|
||||
}) else { continue }
|
||||
|
||||
timelineItems.insert(
|
||||
|
@ -51,7 +51,7 @@ extension TimelineItemsInfo {
|
|||
|
||||
if let pinnedStatusInfos = pinnedStatusesInfo?.pinnedStatusInfos {
|
||||
return [pinnedStatusInfos.filtered(regularExpression: filterRegularExpression)
|
||||
.map { CollectionItem.status(.init(status: .init(info: $0), isPinned: true)) },
|
||||
.map { CollectionItem.status(.init(info: $0), .init(isPinned: true)) },
|
||||
timelineItems]
|
||||
} else {
|
||||
return [timelineItems]
|
||||
|
|
|
@ -3,25 +3,22 @@
|
|||
import Mastodon
|
||||
|
||||
public enum CollectionItem: Hashable {
|
||||
case status(StatusConfiguration)
|
||||
case status(Status, StatusConfiguration)
|
||||
case loadMore(LoadMore)
|
||||
case account(Account)
|
||||
}
|
||||
|
||||
public extension CollectionItem {
|
||||
struct StatusConfiguration: Hashable {
|
||||
public let status: Status
|
||||
public let isContextParent: Bool
|
||||
public let isPinned: Bool
|
||||
public let isReplyInContext: Bool
|
||||
public let hasReplyFollowing: Bool
|
||||
|
||||
init(status: Status,
|
||||
isContextParent: Bool = false,
|
||||
init(isContextParent: Bool = false,
|
||||
isPinned: Bool = false,
|
||||
isReplyInContext: Bool = false,
|
||||
hasReplyFollowing: Bool = false) {
|
||||
self.status = status
|
||||
self.isContextParent = isContextParent
|
||||
self.isPinned = isPinned
|
||||
self.isReplyInContext = isReplyInContext
|
||||
|
|
|
@ -61,13 +61,13 @@ extension CollectionItemsViewModel: CollectionViewModel {
|
|||
let item = items.value[indexPath.section][indexPath.item]
|
||||
|
||||
switch item {
|
||||
case let .status(configuration):
|
||||
case let .status(status, _):
|
||||
navigationEventsSubject.send(
|
||||
.collectionNavigation(
|
||||
CollectionItemsViewModel(
|
||||
collectionService: collectionService
|
||||
.navigationService
|
||||
.contextService(id: configuration.status.displayStatus.id))))
|
||||
.contextService(id: status.displayStatus.id))))
|
||||
case .loadMore:
|
||||
(viewModel(indexPath: indexPath) as? LoadMoreViewModel)?.loadMore()
|
||||
case let .account(account):
|
||||
|
@ -80,7 +80,7 @@ extension CollectionItemsViewModel: CollectionViewModel {
|
|||
|
||||
public func canSelect(indexPath: IndexPath) -> Bool {
|
||||
switch items.value[indexPath.section][indexPath.item] {
|
||||
case let .status(configuration):
|
||||
case let .status(_, configuration):
|
||||
return !configuration.isContextParent
|
||||
case .loadMore:
|
||||
return !((viewModel(indexPath: indexPath) as? LoadMoreViewModel)?.loading ?? false)
|
||||
|
@ -93,14 +93,13 @@ extension CollectionItemsViewModel: CollectionViewModel {
|
|||
let item = items.value[indexPath.section][indexPath.item]
|
||||
|
||||
switch item {
|
||||
case let .status(configuration):
|
||||
case let .status(status, configuration):
|
||||
var viewModel: StatusViewModel
|
||||
|
||||
if let cachedViewModel = viewModelCache[item]?.0 as? StatusViewModel {
|
||||
viewModel = cachedViewModel
|
||||
} else {
|
||||
viewModel = StatusViewModel(
|
||||
statusService: collectionService.navigationService.statusService(status: configuration.status))
|
||||
viewModel = .init(statusService: collectionService.navigationService.statusService(status: status))
|
||||
cache(viewModel: viewModel, forItem: item)
|
||||
}
|
||||
|
||||
|
@ -159,7 +158,7 @@ private extension CollectionItemsViewModel {
|
|||
if collectionService is ContextService,
|
||||
items.value.isEmpty || items.value.map(\.count) == [0, 1, 0],
|
||||
let contextParent = newItems.reduce([], +).first(where: {
|
||||
guard case let .status(configuration) = $0 else { return false }
|
||||
guard case let .status(_, configuration) = $0 else { return false }
|
||||
|
||||
return configuration.isContextParent
|
||||
}) {
|
||||
|
|
|
@ -24,8 +24,8 @@ public extension CollectionItemIdentifier {
|
|||
extension CollectionItemIdentifier {
|
||||
init(item: CollectionItem) {
|
||||
switch item {
|
||||
case let .status(configuration):
|
||||
id = configuration.status.id
|
||||
case let .status(status, configuration):
|
||||
id = status.id
|
||||
kind = .status
|
||||
info = configuration.isPinned ? [.pinned: true] : [:]
|
||||
case let .loadMore(loadMore):
|
||||
|
|
Loading…
Reference in a new issue