StatusItem.swift 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // StatusItem.swift
  3. // Mastodon
  4. //
  5. // Created by MainasuK on 2022-1-11.
  6. //
  7. import Foundation
  8. import CoreDataStack
  9. import MastodonUI
  10. enum StatusItem: Hashable {
  11. case feed(record: ManagedObjectRecord<Feed>)
  12. case feedLoader(record: ManagedObjectRecord<Feed>)
  13. case status(record: ManagedObjectRecord<Status>)
  14. case thread(Thread)
  15. case topLoader
  16. case bottomLoader
  17. }
  18. extension StatusItem {
  19. enum Thread: Hashable {
  20. case root(context: Context)
  21. case reply(context: Context)
  22. case leaf(context: Context)
  23. public var record: ManagedObjectRecord<Status> {
  24. switch self {
  25. case .root(let threadContext),
  26. .reply(let threadContext),
  27. .leaf(let threadContext):
  28. return threadContext.status
  29. }
  30. }
  31. }
  32. }
  33. extension StatusItem.Thread {
  34. class Context: Hashable {
  35. let status: ManagedObjectRecord<Status>
  36. var displayUpperConversationLink: Bool
  37. var displayBottomConversationLink: Bool
  38. init(
  39. status: ManagedObjectRecord<Status>,
  40. displayUpperConversationLink: Bool = false,
  41. displayBottomConversationLink: Bool = false
  42. ) {
  43. self.status = status
  44. self.displayUpperConversationLink = displayUpperConversationLink
  45. self.displayBottomConversationLink = displayBottomConversationLink
  46. }
  47. static func == (lhs: StatusItem.Thread.Context, rhs: StatusItem.Thread.Context) -> Bool {
  48. return lhs.status == rhs.status
  49. && lhs.displayUpperConversationLink == rhs.displayUpperConversationLink
  50. && lhs.displayBottomConversationLink == rhs.displayBottomConversationLink
  51. }
  52. func hash(into hasher: inout Hasher) {
  53. hasher.combine(status)
  54. hasher.combine(displayUpperConversationLink)
  55. hasher.combine(displayBottomConversationLink)
  56. }
  57. }
  58. }