metatext-app-ios-iphone-ipad/DB/Sources/DB/Entities/CollectionItem.swift

87 lines
2.7 KiB
Swift
Raw Normal View History

2020-10-05 08:36:22 +02:00
// Copyright © 2020 Metabolist. All rights reserved.
import Mastodon
public enum CollectionItem: Hashable {
2021-02-08 02:46:51 +01:00
case status(Status, StatusConfiguration, Relationship?)
2020-10-05 08:36:22 +02:00
case loadMore(LoadMore)
2021-02-08 02:46:51 +01:00
case account(Account, AccountConfiguration, Relationship?)
2020-10-30 08:11:24 +01:00
case notification(MastodonNotification, StatusConfiguration?)
2020-10-29 07:03:45 +01:00
case conversation(Conversation)
2021-01-24 04:12:30 +01:00
case tag(Tag)
2021-04-25 21:38:36 +02:00
case announcement(Announcement)
2021-01-25 08:42:39 +01:00
case moreResults(MoreResults)
2020-10-05 08:36:22 +02:00
}
public extension CollectionItem {
2020-10-31 01:53:57 +01:00
typealias Id = String
2020-10-05 08:36:22 +02:00
struct StatusConfiguration: Hashable {
2020-10-14 02:03:01 +02:00
public let showContentToggled: Bool
public let showAttachmentsToggled: Bool
2020-10-06 01:44:15 +02:00
public let isContextParent: Bool
public let isPinned: Bool
2020-10-05 08:36:22 +02:00
public let isReplyInContext: Bool
2021-04-04 21:26:02 +02:00
public let isReplyOutOfContext: Bool
2020-10-05 08:36:22 +02:00
public let hasReplyFollowing: Bool
2020-10-14 02:03:01 +02:00
init(showContentToggled: Bool,
showAttachmentsToggled: Bool,
2020-10-07 23:06:26 +02:00
isContextParent: Bool = false,
2020-10-06 01:44:15 +02:00
isPinned: Bool = false,
isReplyInContext: Bool = false,
2021-04-04 21:26:02 +02:00
isReplyOutOfContext: Bool = false,
2020-10-06 01:44:15 +02:00
hasReplyFollowing: Bool = false) {
2020-10-14 02:03:01 +02:00
self.showContentToggled = showContentToggled
self.showAttachmentsToggled = showAttachmentsToggled
2020-10-06 01:44:15 +02:00
self.isContextParent = isContextParent
self.isPinned = isPinned
2020-10-05 08:36:22 +02:00
self.isReplyInContext = isReplyInContext
2021-04-04 21:26:02 +02:00
self.isReplyOutOfContext = isReplyOutOfContext
2020-10-05 08:36:22 +02:00
self.hasReplyFollowing = hasReplyFollowing
}
}
2020-10-31 01:53:57 +01:00
2021-01-26 07:57:44 +01:00
enum AccountConfiguration: Hashable {
case withNote
case withoutNote
case followRequest
2021-02-11 03:04:04 +01:00
case mute
case block
2021-01-26 07:57:44 +01:00
}
2020-10-31 01:53:57 +01:00
var itemId: Id? {
switch self {
2021-02-08 02:46:51 +01:00
case let .status(status, _, _):
2020-10-31 01:53:57 +01:00
return status.id
case .loadMore:
return nil
2021-02-08 02:46:51 +01:00
case let .account(account, _, _):
2020-10-31 01:53:57 +01:00
return account.id
case let .notification(notification, _):
return notification.id
2020-10-29 07:03:45 +01:00
case let .conversation(conversation):
return conversation.id
2021-01-24 04:12:30 +01:00
case let .tag(tag):
return tag.name
2021-04-25 21:38:36 +02:00
case let .announcement(announcement):
return announcement.id
2021-01-25 08:42:39 +01:00
case .moreResults:
return nil
2020-10-31 01:53:57 +01:00
}
}
2020-10-05 08:36:22 +02:00
}
2020-10-06 02:33:58 +02:00
public extension CollectionItem.StatusConfiguration {
2020-10-14 02:03:01 +02:00
static let `default` = Self(showContentToggled: false, showAttachmentsToggled: false)
2021-01-10 06:56:15 +01:00
func reply() -> Self {
Self(showContentToggled: showContentToggled,
showAttachmentsToggled: showAttachmentsToggled,
isContextParent: false,
isPinned: false,
isReplyInContext: false,
hasReplyFollowing: true)
}
2020-10-06 02:33:58 +02:00
}