Fix notifications show empty view (IOS-198)

This commit is contained in:
Marcus Kida 2023-12-04 10:14:42 +01:00
parent b57f38ddc5
commit 63e45d65f9
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
7 changed files with 20 additions and 42 deletions

View File

@ -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<MastodonUser>? = 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
}

View File

@ -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

View File

@ -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
}
}

View File

@ -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:))
}
}

View File

@ -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

View File

@ -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: [])
}
}

View File

@ -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]()