Use folders when handling push notifications
This commit is contained in:
@ -324,10 +324,6 @@ struct AnimatingCellHeight: AnimatableModifier {
|
||||
await viewModel.loadNewItems(dataService: dataService)
|
||||
}
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: Notification.Name("PushJSONArticle"))) { notification in
|
||||
guard let libraryItemId = notification.userInfo?["libraryItemId"] as? String else { return }
|
||||
viewModel.pushLinkedRequest(request: LinkRequest(id: UUID(), serverID: libraryItemId))
|
||||
}
|
||||
.sheet(isPresented: $searchPresented) {
|
||||
LibrarySearchView(homeFeedViewModel: self.viewModel)
|
||||
}
|
||||
|
||||
@ -48,6 +48,10 @@ public struct LibrarySplitView: View {
|
||||
$0.preferredPrimaryColumnWidth = 230
|
||||
$0.displayModeButtonVisibility = .always
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: Notification.Name("PushLibraryItem"))) { notification in
|
||||
guard let libraryItemId = notification.userInfo?["libraryItemId"] as? String else { return }
|
||||
viewModel.pushLinkedRequest(request: LinkRequest(id: UUID(), serverID: libraryItemId))
|
||||
}
|
||||
.onOpenURL { url in
|
||||
viewModel.linkRequest = nil
|
||||
|
||||
|
||||
@ -144,6 +144,17 @@ struct LibraryTabView: View {
|
||||
await syncManager.syncUpdates(dataService: dataService)
|
||||
}
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: Notification.Name("PushLibraryItem"))) { notification in
|
||||
guard let folder = notification.userInfo?["libraryItemId"] as? String else { return }
|
||||
guard let libraryItemId = notification.userInfo?["libraryItemId"] as? String else { return }
|
||||
if folder == "following" {
|
||||
selectedTab = "following"
|
||||
followingViewModel.pushLinkedRequest(request: LinkRequest(id: UUID(), serverID: libraryItemId))
|
||||
} else {
|
||||
selectedTab = "inbox"
|
||||
inboxViewModel.pushLinkedRequest(request: LinkRequest(id: UUID(), serverID: libraryItemId))
|
||||
}
|
||||
}
|
||||
.onOpenURL { url in
|
||||
inboxViewModel.linkRequest = nil
|
||||
|
||||
@ -162,10 +173,7 @@ struct LibraryTabView: View {
|
||||
case let .webAppLinkRequest(requestID):
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
|
||||
withoutAnimation {
|
||||
inboxViewModel.linkRequest = LinkRequest(id: UUID(), serverID: requestID)
|
||||
inboxViewModel.presentWebContainer = true
|
||||
}
|
||||
inboxViewModel.pushLinkedRequest(request: LinkRequest(id: UUID(), serverID: requestID))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,8 +3,7 @@ import Foundation
|
||||
import Models
|
||||
|
||||
public extension NSNotification {
|
||||
static let PushJSONArticle = Notification.Name("PushJSONArticle")
|
||||
static let PushReaderItem = Notification.Name("PushReaderItem")
|
||||
static let PushLibraryItem = Notification.Name("PushLibraryItem")
|
||||
static let SnackBar = Notification.Name("SnackBar")
|
||||
static let OperationFailure = Notification.Name("OperationFailure")
|
||||
static let ReaderSettingsChanged = Notification.Name("ReaderSettingsChanged")
|
||||
@ -19,11 +18,7 @@ public extension NSNotification {
|
||||
}
|
||||
|
||||
static var pushFeedItemPublisher: NotificationCenter.Publisher {
|
||||
NotificationCenter.default.publisher(for: PushJSONArticle)
|
||||
}
|
||||
|
||||
static var pushReaderItemPublisher: NotificationCenter.Publisher {
|
||||
NotificationCenter.default.publisher(for: PushReaderItem)
|
||||
NotificationCenter.default.publisher(for: PushLibraryItem)
|
||||
}
|
||||
|
||||
static var snackBarPublisher: NotificationCenter.Publisher {
|
||||
@ -61,19 +56,14 @@ public extension NSNotification {
|
||||
return nil
|
||||
}
|
||||
|
||||
static func pushJSONArticle(libraryItemId: String) {
|
||||
static func pushLibraryItem(folder: String?, libraryItemId: String) {
|
||||
NotificationCenter.default.post(
|
||||
name: NSNotification.PushJSONArticle,
|
||||
name: NSNotification.PushLibraryItem,
|
||||
object: nil,
|
||||
userInfo: ["libraryItemId": libraryItemId]
|
||||
)
|
||||
}
|
||||
|
||||
static func pushReaderItem(objectID: NSManagedObjectID) {
|
||||
NotificationCenter.default.post(
|
||||
name: NSNotification.PushReaderItem,
|
||||
object: nil,
|
||||
userInfo: ["objectID": objectID]
|
||||
userInfo: [
|
||||
"folder": folder ?? "inbox",
|
||||
"libraryItemId": libraryItemId
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -69,7 +69,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
|
||||
let userInfo = response.notification.request.content.userInfo
|
||||
|
||||
if let libraryItemId = userInfo["libraryItemId"] as? String {
|
||||
NSNotification.pushJSONArticle(libraryItemId: libraryItemId)
|
||||
NSNotification.pushLibraryItem(folder: userInfo["folder"] as? String, libraryItemId: libraryItemId)
|
||||
}
|
||||
|
||||
completionHandler()
|
||||
|
||||
@ -73,6 +73,7 @@ const sendNotification = async (obj: RuleActionObj) => {
|
||||
image: item.thumbnail,
|
||||
}
|
||||
const data = {
|
||||
folder: item.folder,
|
||||
libraryItemId: item.id,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user