diff --git a/Pachyderm/Model/Notification.swift b/Pachyderm/Model/Notification.swift index 56ed204b..080b17f0 100644 --- a/Pachyderm/Model/Notification.swift +++ b/Pachyderm/Model/Notification.swift @@ -15,6 +15,24 @@ public class Notification: Decodable { public let account: Account public let status: Status? + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.id = try container.decode(String.self, forKey: .id) + if let kind = try? container.decode(Kind.self, forKey: .kind) { + self.kind = kind + } else { + self.kind = .unknown + } + self.createdAt = try container.decode(Date.self, forKey: .createdAt) + self.account = try container.decode(Account.self, forKey: .account) + if container.contains(.status) { + self.status = try container.decode(Status.self, forKey: .status) + } else { + self.status = nil + } + } + public static func dismiss(id notificationID: String) -> Request { return Request(method: .post, path: "/api/v1/notifications/dismiss", body: .parameters([ "id" => notificationID @@ -37,6 +55,7 @@ extension Notification { case favourite case follow case followRequest = "follow_request" + case unknown } } diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 63a6803f..2b3d7cea 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -165,6 +165,7 @@ D6945C3A23AC75E2005C403C /* FindInstanceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6945C3923AC75E2005C403C /* FindInstanceViewController.swift */; }; D6969E9E240C81B9002843CE /* NSTextAttachment+Emoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6969E9D240C81B9002843CE /* NSTextAttachment+Emoji.swift */; }; D6969EA0240C8384002843CE /* EmojiLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6969E9F240C8384002843CE /* EmojiLabel.swift */; }; + D6969EA4240DD28D002843CE /* UnknownNotificationTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6969EA2240DD28D002843CE /* UnknownNotificationTableViewCell.xib */; }; D6A3BC7723218E1300FD64D5 /* TimelineSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6A3BC7323218C6E00FD64D5 /* TimelineSegment.swift */; }; D6A3BC7923218E9200FD64D5 /* NotificationGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6A3BC7823218E9200FD64D5 /* NotificationGroup.swift */; }; D6A3BC7C232195C600FD64D5 /* ActionNotificationGroupTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6A3BC7A232195C600FD64D5 /* ActionNotificationGroupTableViewCell.swift */; }; @@ -447,6 +448,7 @@ D6945C3923AC75E2005C403C /* FindInstanceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FindInstanceViewController.swift; path = Tusker/Screens/FindInstanceViewController.swift; sourceTree = SOURCE_ROOT; }; D6969E9D240C81B9002843CE /* NSTextAttachment+Emoji.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSTextAttachment+Emoji.swift"; sourceTree = ""; }; D6969E9F240C8384002843CE /* EmojiLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiLabel.swift; sourceTree = ""; }; + D6969EA2240DD28D002843CE /* UnknownNotificationTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = UnknownNotificationTableViewCell.xib; sourceTree = ""; }; D6A3BC7323218C6E00FD64D5 /* TimelineSegment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineSegment.swift; sourceTree = ""; }; D6A3BC7823218E9200FD64D5 /* NotificationGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationGroup.swift; sourceTree = ""; }; D6A3BC7A232195C600FD64D5 /* ActionNotificationGroupTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionNotificationGroupTableViewCell.swift; sourceTree = ""; }; @@ -926,6 +928,7 @@ D6A3BC7F2321B7E600FD64D5 /* FollowNotificationGroupTableViewCell.xib */, D64BC18D23C18B9D000D0238 /* FollowRequestNotificationTableViewCell.swift */, D64BC18E23C18B9D000D0238 /* FollowRequestNotificationTableViewCell.xib */, + D6969EA2240DD28D002843CE /* UnknownNotificationTableViewCell.xib */, ); path = Notifications; sourceTree = ""; @@ -1468,6 +1471,7 @@ D6D4DDD7212518A200E1C4BB /* Assets.xcassets in Resources */, D663625D2135C74800C9CBA2 /* ConversationMainStatusTableViewCell.xib in Resources */, D640D76922BAF5E6004FBE69 /* DomainBlocks.plist in Resources */, + D6969EA4240DD28D002843CE /* UnknownNotificationTableViewCell.xib in Resources */, D6289E84217B795D0003D1D7 /* LargeImageViewController.xib in Resources */, D627FF79217E950100CC0648 /* DraftsTableViewController.xib in Resources */, D626493323BD751600612E6E /* ShowCameraCollectionViewCell.xib in Resources */, diff --git a/Tusker/Screens/Notifications/NotificationsTableViewController.swift b/Tusker/Screens/Notifications/NotificationsTableViewController.swift index 414323f7..caa25201 100644 --- a/Tusker/Screens/Notifications/NotificationsTableViewController.swift +++ b/Tusker/Screens/Notifications/NotificationsTableViewController.swift @@ -15,6 +15,7 @@ class NotificationsTableViewController: EnhancedTableViewController { private let actionGroupCell = "actionGroupCell" private let followGroupCell = "followGroupCell" private let followRequestCell = "followRequestCell" + private let unknownCell = "unknownCell" let mastodonController: MastodonController @@ -50,6 +51,7 @@ class NotificationsTableViewController: EnhancedTableViewController { tableView.register(UINib(nibName: "ActionNotificationGroupTableViewCell", bundle: .main), forCellReuseIdentifier: actionGroupCell) tableView.register(UINib(nibName: "FollowNotificationGroupTableViewCell", bundle: .main), forCellReuseIdentifier: followGroupCell) tableView.register(UINib(nibName: "FollowRequestNotificationTableViewCell", bundle: .main), forCellReuseIdentifier: followRequestCell) + tableView.register(UINib(nibName: "UnknownNotificationTableViewCell", bundle: .main), forCellReuseIdentifier: unknownCell) tableView.prefetchDataSource = self @@ -116,6 +118,9 @@ class NotificationsTableViewController: EnhancedTableViewController { cell.delegate = self cell.updateUI(notification: notification) return cell + + case .unknown: + return tableView.dequeueReusableCell(withIdentifier: unknownCell, for: indexPath) } } diff --git a/Tusker/Views/Notifications/UnknownNotificationTableViewCell.xib b/Tusker/Views/Notifications/UnknownNotificationTableViewCell.xib new file mode 100644 index 00000000..8f226368 --- /dev/null +++ b/Tusker/Views/Notifications/UnknownNotificationTableViewCell.xib @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +