Fix notifications show empty view (IOS-198)
This commit is contained in:
parent
b57f38ddc5
commit
63e45d65f9
@ -22,6 +22,7 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte
|
|||||||
statusView: StatusView,
|
statusView: StatusView,
|
||||||
headerDidPressed header: UIView
|
headerDidPressed header: UIView
|
||||||
) {
|
) {
|
||||||
|
let domain = statusView.domain ?? ""
|
||||||
Task {
|
Task {
|
||||||
let source = DataSourceItem.Source(tableViewCell: cell, indexPath: nil)
|
let source = DataSourceItem.Source(tableViewCell: cell, indexPath: nil)
|
||||||
guard let item = await item(from: source) else {
|
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 {
|
let _replyToAuthor: ManagedObjectRecord<MastodonUser>? = try? await context.managedObjectContext.perform {
|
||||||
guard let inReplyToAccountID = status.entity.inReplyToAccountID else { return nil }
|
guard let inReplyToAccountID = status.entity.inReplyToAccountID else { return nil }
|
||||||
let request = MastodonUser.sortedFetchRequest
|
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
|
request.fetchLimit = 1
|
||||||
guard let author = self.context.managedObjectContext.safeFetch(request).first else { return nil }
|
guard let author = self.context.managedObjectContext.safeFetch(request).first else { return nil }
|
||||||
return .init(objectID: author.objectID)
|
return .init(objectID: author.objectID)
|
||||||
}
|
}
|
||||||
guard let replyToAuthor = _replyToAuthor else {
|
guard let replyToAuthor = _replyToAuthor else {
|
||||||
|
assertionFailure()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ extension NotificationTimelineViewController: DataSourceProvider {
|
|||||||
let managedObjectContext = context.managedObjectContext
|
let managedObjectContext = context.managedObjectContext
|
||||||
let item: DataSourceItem? = {
|
let item: DataSourceItem? = {
|
||||||
guard feed.kind == .notificationAll || feed.kind == .notificationMentions else { return nil }
|
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)
|
return .notification(record: mastodonNotification)
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
|
@ -61,41 +61,6 @@ final class NotificationTimelineViewModel {
|
|||||||
extension NotificationTimelineViewModel {
|
extension NotificationTimelineViewModel {
|
||||||
|
|
||||||
typealias Scope = APIService.MastodonNotificationScope
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,11 @@ extension NotificationView {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
MastodonNotification.fromEntity(notification, using: managedObjectContext).map(configure(notification:))
|
MastodonNotification.fromEntity(
|
||||||
|
notification,
|
||||||
|
using: managedObjectContext,
|
||||||
|
domain: viewModel.authContext?.mastodonAuthenticationBox.domain ?? ""
|
||||||
|
).map(configure(notification:))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public final class MastodonFeed {
|
|||||||
public let kind: Feed.Kind
|
public let kind: Feed.Kind
|
||||||
|
|
||||||
init(hasMore: Bool, isLoadingMore: Bool, status: MastodonStatus?, notification: Mastodon.Entity.Notification?, 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.hasMore = hasMore
|
||||||
self.isLoadingMore = isLoadingMore
|
self.isLoadingMore = isLoadingMore
|
||||||
self.status = status
|
self.status = status
|
||||||
|
@ -26,10 +26,13 @@ public final class MastodonNotification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public extension 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
|
guard let user = MastodonUser.fetch(in: managedObjectContext, configurationBlock: { request in
|
||||||
request.predicate = MastodonUser.predicate(domain: entity.account.domain ?? "", id: entity.account.id)
|
request.predicate = MastodonUser.predicate(domain: domain, id: entity.account.id)
|
||||||
}).first else { return nil }
|
}).first else {
|
||||||
|
assertionFailure()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return MastodonNotification(entity: entity, account: user, status: entity.status.map(MastodonStatus.fromEntity), feeds: [])
|
return MastodonNotification(entity: entity, account: user, status: entity.status.map(MastodonStatus.fromEntity), feeds: [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,10 @@ public final class StatusView: UIView {
|
|||||||
public weak var delegate: StatusViewDelegate?
|
public weak var delegate: StatusViewDelegate?
|
||||||
|
|
||||||
public private(set) var style: Style?
|
public private(set) var style: Style?
|
||||||
|
|
||||||
|
public var domain: String? {
|
||||||
|
viewModel.authContext?.mastodonAuthenticationBox.domain
|
||||||
|
}
|
||||||
|
|
||||||
// accessibility actions
|
// accessibility actions
|
||||||
var toolbarActions = [UIAccessibilityCustomAction]()
|
var toolbarActions = [UIAccessibilityCustomAction]()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user