Subscription.swift 927 B

12345678910111213141516171819202122232425262728293031323334
  1. import Foundation
  2. extension Subscription {
  3. func urlString() -> String {
  4. return topicUrl(baseUrl: baseUrl ?? "?", topic: topic ?? "?")
  5. }
  6. func displayName() -> String {
  7. return topicShortUrl(baseUrl: baseUrl ?? "?", topic: topic ?? "?")
  8. }
  9. func topicName() -> String {
  10. return topic ?? "?"
  11. }
  12. func urlHash() -> String {
  13. return topicHash(baseUrl: baseUrl ?? "?", topic: topic ?? "?")
  14. }
  15. func notificationCount() -> Int {
  16. return notifications?.count ?? 0
  17. }
  18. func lastNotification() -> Notification? {
  19. return notificationsSorted().first
  20. }
  21. func notificationsSorted() -> [Notification] {
  22. if let notifications = notifications {
  23. return notifications.sortedArray(using: [NSSortDescriptor(keyPath: \Notification.time, ascending: false)]) as! [Notification]
  24. }
  25. return []
  26. }
  27. }