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