metatext/DB/Sources/DB/Entities/CollectionItem.swift

67 lines
2.1 KiB
Swift
Raw Normal View History

2020-10-05 06:36:22 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import Mastodon
public enum CollectionItem: Hashable {
2020-10-05 23:54:45 +00:00
case status(Status, StatusConfiguration)
2020-10-05 06:36:22 +00:00
case loadMore(LoadMore)
case account(Account)
2020-10-30 07:11:24 +00:00
case notification(MastodonNotification, StatusConfiguration?)
2020-10-29 06:03:45 +00:00
case conversation(Conversation)
2020-10-05 06:36:22 +00:00
}
public extension CollectionItem {
2020-10-31 00:53:57 +00:00
typealias Id = String
2020-10-05 06:36:22 +00:00
struct StatusConfiguration: Hashable {
2020-10-14 00:03:01 +00:00
public let showContentToggled: Bool
public let showAttachmentsToggled: Bool
2020-10-05 23:44:15 +00:00
public let isContextParent: Bool
public let isPinned: Bool
2020-10-05 06:36:22 +00:00
public let isReplyInContext: Bool
public let hasReplyFollowing: Bool
2020-10-14 00:03:01 +00:00
init(showContentToggled: Bool,
showAttachmentsToggled: Bool,
2020-10-07 21:06:26 +00:00
isContextParent: Bool = false,
2020-10-05 23:44:15 +00:00
isPinned: Bool = false,
isReplyInContext: Bool = false,
hasReplyFollowing: Bool = false) {
2020-10-14 00:03:01 +00:00
self.showContentToggled = showContentToggled
self.showAttachmentsToggled = showAttachmentsToggled
2020-10-05 23:44:15 +00:00
self.isContextParent = isContextParent
self.isPinned = isPinned
2020-10-05 06:36:22 +00:00
self.isReplyInContext = isReplyInContext
self.hasReplyFollowing = hasReplyFollowing
}
}
2020-10-31 00:53:57 +00:00
var itemId: Id? {
switch self {
case let .status(status, _):
return status.id
case .loadMore:
return nil
case let .account(account):
return account.id
case let .notification(notification, _):
return notification.id
2020-10-29 06:03:45 +00:00
case let .conversation(conversation):
return conversation.id
2020-10-31 00:53:57 +00:00
}
}
2020-10-05 06:36:22 +00:00
}
2020-10-06 00:33:58 +00:00
public extension CollectionItem.StatusConfiguration {
2020-10-14 00:03:01 +00:00
static let `default` = Self(showContentToggled: false, showAttachmentsToggled: false)
2021-01-10 05:56:15 +00:00
func reply() -> Self {
Self(showContentToggled: showContentToggled,
showAttachmentsToggled: showAttachmentsToggled,
isContextParent: false,
isPinned: false,
isReplyInContext: false,
hasReplyFollowing: true)
}
2020-10-06 00:33:58 +00:00
}