Refactoring

This commit is contained in:
Justin Mazzocchi 2020-10-12 21:56:46 -07:00
parent e7d8446d0c
commit 5275ee0d21
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
1 changed files with 25 additions and 25 deletions

View File

@ -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
} }
} }