diff --git a/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift b/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift index 5550b177d..c0a6c2381 100644 --- a/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift +++ b/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift @@ -22,6 +22,7 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte statusView: StatusView, headerDidPressed header: UIView ) { + let domain = statusView.domain ?? "" Task { let source = DataSourceItem.Source(tableViewCell: cell, indexPath: nil) guard let item = await item(from: source) else { @@ -40,12 +41,13 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte let _replyToAuthor: ManagedObjectRecord? = try? await context.managedObjectContext.perform { guard let inReplyToAccountID = status.entity.inReplyToAccountID else { return nil } let request = MastodonUser.sortedFetchRequest - request.predicate = MastodonUser.predicate(domain: status.entity.account.domain ?? "", id: inReplyToAccountID) + request.predicate = MastodonUser.predicate(domain: domain, id: inReplyToAccountID) request.fetchLimit = 1 guard let author = self.context.managedObjectContext.safeFetch(request).first else { return nil } return .init(objectID: author.objectID) } guard let replyToAuthor = _replyToAuthor else { + assertionFailure() return } diff --git a/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewController+DataSourceProvider.swift b/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewController+DataSourceProvider.swift index a15f1664c..4cda5e530 100644 --- a/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewController+DataSourceProvider.swift +++ b/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewController+DataSourceProvider.swift @@ -25,7 +25,7 @@ extension NotificationTimelineViewController: DataSourceProvider { let managedObjectContext = context.managedObjectContext let item: DataSourceItem? = { guard feed.kind == .notificationAll || feed.kind == .notificationMentions else { return nil } - if let notification = feed.notification, let mastodonNotification = MastodonNotification.fromEntity(notification, using: managedObjectContext) { + if let notification = feed.notification, let mastodonNotification = MastodonNotification.fromEntity(notification, using: managedObjectContext, domain: authContext.mastodonAuthenticationBox.domain) { return .notification(record: mastodonNotification) } else { return nil diff --git a/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewModel.swift b/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewModel.swift index ca739ed55..fc4bd4557 100644 --- a/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewModel.swift +++ b/Mastodon/Scene/Notification/NotificationTimeline/NotificationTimelineViewModel.swift @@ -61,41 +61,6 @@ final class NotificationTimelineViewModel { extension NotificationTimelineViewModel { typealias Scope = APIService.MastodonNotificationScope - - static func feedPredicate( - authenticationBox: MastodonAuthenticationBox, - scope: Scope - ) -> NSPredicate { - let domain = authenticationBox.domain - let userID = authenticationBox.userID - let acct = Feed.Acct.mastodon( - domain: domain, - userID: userID - ) - - let predicate: NSPredicate = { - switch scope { - case .everything: - return NSCompoundPredicate(andPredicateWithSubpredicates: [ - Feed.hasNotificationPredicate(), - Feed.predicate( - kind: .notificationAll, - acct: acct - ) - ]) - case .mentions: - return NSCompoundPredicate(andPredicateWithSubpredicates: [ - Feed.hasNotificationPredicate(), - Feed.predicate( - kind: .notificationMentions, - acct: acct - ), - Feed.notificationTypePredicate(types: scope.includeTypes ?? []) - ]) - } - }() - return predicate - } } diff --git a/Mastodon/Scene/Share/View/Content/NotificationView+Configuration.swift b/Mastodon/Scene/Share/View/Content/NotificationView+Configuration.swift index 9600461df..98dec5397 100644 --- a/Mastodon/Scene/Share/View/Content/NotificationView+Configuration.swift +++ b/Mastodon/Scene/Share/View/Content/NotificationView+Configuration.swift @@ -28,7 +28,11 @@ extension NotificationView { return } - MastodonNotification.fromEntity(notification, using: managedObjectContext).map(configure(notification:)) + MastodonNotification.fromEntity( + notification, + using: managedObjectContext, + domain: viewModel.authContext?.mastodonAuthenticationBox.domain ?? "" + ).map(configure(notification:)) } } diff --git a/MastodonSDK/Sources/MastodonSDK/MastodonFeed.swift b/MastodonSDK/Sources/MastodonSDK/MastodonFeed.swift index c5016934a..fbeed892f 100644 --- a/MastodonSDK/Sources/MastodonSDK/MastodonFeed.swift +++ b/MastodonSDK/Sources/MastodonSDK/MastodonFeed.swift @@ -21,7 +21,7 @@ public final class MastodonFeed { public let kind: Feed.Kind init(hasMore: Bool, isLoadingMore: Bool, status: MastodonStatus?, notification: Mastodon.Entity.Notification?, kind: Feed.Kind) { - self.id = status?.id ?? notification?.id ?? UUID().uuidString + self.id = notification?.id ?? status?.id ?? UUID().uuidString self.hasMore = hasMore self.isLoadingMore = isLoadingMore self.status = status diff --git a/MastodonSDK/Sources/MastodonSDK/MastodonNotification.swift b/MastodonSDK/Sources/MastodonSDK/MastodonNotification.swift index 4cffc393f..b32d59c29 100644 --- a/MastodonSDK/Sources/MastodonSDK/MastodonNotification.swift +++ b/MastodonSDK/Sources/MastodonSDK/MastodonNotification.swift @@ -26,10 +26,13 @@ public final class MastodonNotification { } public extension MastodonNotification { - static func fromEntity(_ entity: Mastodon.Entity.Notification, using managedObjectContext: NSManagedObjectContext) -> MastodonNotification? { + static func fromEntity(_ entity: Mastodon.Entity.Notification, using managedObjectContext: NSManagedObjectContext, domain: String) -> MastodonNotification? { guard let user = MastodonUser.fetch(in: managedObjectContext, configurationBlock: { request in - request.predicate = MastodonUser.predicate(domain: entity.account.domain ?? "", id: entity.account.id) - }).first else { return nil } + request.predicate = MastodonUser.predicate(domain: domain, id: entity.account.id) + }).first else { + assertionFailure() + return nil + } return MastodonNotification(entity: entity, account: user, status: entity.status.map(MastodonStatus.fromEntity), feeds: []) } } diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift index 5c57db96b..bdd160435 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift @@ -50,6 +50,10 @@ public final class StatusView: UIView { public weak var delegate: StatusViewDelegate? public private(set) var style: Style? + + public var domain: String? { + viewModel.authContext?.mastodonAuthenticationBox.domain + } // accessibility actions var toolbarActions = [UIAccessibilityCustomAction]()