mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 08:10:59 +00:00
Refactoring
This commit is contained in:
parent
e7d8446d0c
commit
5275ee0d21
1 changed files with 25 additions and 25 deletions
|
@ -4,10 +4,11 @@ import Mastodon
|
||||||
import ServiceLayer
|
import ServiceLayer
|
||||||
|
|
||||||
public struct CollectionItemIdentifier: Hashable {
|
public struct CollectionItemIdentifier: Hashable {
|
||||||
public let id: String
|
private let item: CollectionItem
|
||||||
public let kind: Kind
|
|
||||||
public let pinned: Bool
|
init(item: CollectionItem) {
|
||||||
public let showMoreToggled: Bool
|
self.item = item
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension CollectionItemIdentifier {
|
public extension CollectionItemIdentifier {
|
||||||
|
@ -16,30 +17,29 @@ public extension CollectionItemIdentifier {
|
||||||
case loadMore
|
case loadMore
|
||||||
case account
|
case account
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var kind: Kind {
|
||||||
|
switch item {
|
||||||
|
case .status:
|
||||||
|
return .status
|
||||||
|
case .loadMore:
|
||||||
|
return .loadMore
|
||||||
|
case .account:
|
||||||
|
return .account
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension CollectionItemIdentifier {
|
extension CollectionItemIdentifier {
|
||||||
init(item: CollectionItem) {
|
|
||||||
switch item {
|
|
||||||
case let .status(status, configuration):
|
|
||||||
id = status.id
|
|
||||||
kind = .status
|
|
||||||
pinned = configuration.isPinned
|
|
||||||
showMoreToggled = configuration.showMoreToggled
|
|
||||||
case let .loadMore(loadMore):
|
|
||||||
id = loadMore.afterStatusId
|
|
||||||
kind = .loadMore
|
|
||||||
pinned = false
|
|
||||||
showMoreToggled = false
|
|
||||||
case let .account(account):
|
|
||||||
id = account.id
|
|
||||||
kind = .account
|
|
||||||
pinned = false
|
|
||||||
showMoreToggled = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static func isSameExceptShowMoreToggled(lhs: Self, rhs: Self) -> Bool {
|
public static func isSameExceptShowMoreToggled(lhs: Self, rhs: Self) -> Bool {
|
||||||
lhs.id == rhs.id && lhs.kind == rhs.kind && lhs.pinned == rhs.pinned
|
guard case let .status(lhsStatus, lhsConfiguration) = lhs.item,
|
||||||
|
case let .status(rhsStatus, rhsConfiguration) = rhs.item,
|
||||||
|
lhsStatus == rhsStatus
|
||||||
|
else { return false }
|
||||||
|
|
||||||
|
return lhsConfiguration.isContextParent == rhsConfiguration.isContextParent
|
||||||
|
&& lhsConfiguration.isPinned == rhsConfiguration.isPinned
|
||||||
|
&& lhsConfiguration.isReplyInContext == rhsConfiguration.isReplyInContext
|
||||||
|
&& lhsConfiguration.hasReplyFollowing == rhsConfiguration.hasReplyFollowing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue