fix: follow push notification deep-link not works issue

This commit is contained in:
CMK 2022-02-11 15:28:39 +08:00
parent 9e954c517e
commit d85af16e03
2 changed files with 34 additions and 68 deletions

View File

@ -56,48 +56,43 @@ final class RemoteProfileViewModel: ProfileViewModel {
init(context: AppContext, notificationID: Mastodon.Entity.Notification.ID) { init(context: AppContext, notificationID: Mastodon.Entity.Notification.ID) {
super.init(context: context, optionalMastodonUser: nil) super.init(context: context, optionalMastodonUser: nil)
guard let activeMastodonAuthenticationBox = context.authenticationService.activeMastodonAuthenticationBox.value else { guard let authenticationBox = context.authenticationService.activeMastodonAuthenticationBox.value else {
return return
} }
let domain = activeMastodonAuthenticationBox.domain
let authorization = activeMastodonAuthenticationBox.userAuthorization
// context.apiService.notification( Task { @MainActor in
// notificationID: notificationID, let response = try await context.apiService.notification(
// mastodonAuthenticationBox: activeMastodonAuthenticationBox notificationID: notificationID,
// ) authenticationBox: authenticationBox
// .compactMap { [weak self] response -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Account>, Error>? in )
// let userID = response.value.account.id let userID = response.value.account.id
// // TODO: use .account directly
// return context.apiService.accountInfo( let _user: MastodonUser? = try await context.managedObjectContext.perform {
// domain: domain, let request = MastodonUser.sortedFetchRequest
// userID: userID, request.predicate = MastodonUser.predicate(domain: authenticationBox.domain, id: userID)
// authorization: authorization request.fetchLimit = 1
// ) return context.managedObjectContext.safeFetch(request).first
// } }
// .switchToLatest()
// .retry(3) if let user = _user {
// .sink { completion in self.user = user
// switch completion { } else {
// case .failure(let error): _ = try await context.apiService.accountInfo(
// // TODO: handle error domain: authenticationBox.domain,
// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: remote notification %s user fetch failed: %s", ((#file as NSString).lastPathComponent), #line, #function, notificationID, error.localizedDescription) userID: userID,
// case .finished: authorization: authenticationBox.userAuthorization
// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: remote notification %s user fetched", ((#file as NSString).lastPathComponent), #line, #function, notificationID) )
// }
// } receiveValue: { [weak self] response in let _user: MastodonUser? = try await context.managedObjectContext.perform {
// guard let self = self else { return } let request = MastodonUser.sortedFetchRequest
// let managedObjectContext = context.managedObjectContext request.predicate = MastodonUser.predicate(domain: authenticationBox.domain, id: userID)
// let request = MastodonUser.sortedFetchRequest request.fetchLimit = 1
// request.fetchLimit = 1 return context.managedObjectContext.safeFetch(request).first
// request.predicate = MastodonUser.predicate(domain: domain, id: response.value.id) }
// guard let mastodonUser = managedObjectContext.safeFetch(request).first else {
// assertionFailure() self.user = _user
// return }
// } } // end Task
// self.mastodonUser.value = mastodonUser
// }
// .store(in: &disposeBag)
} }
} }

View File

@ -43,35 +43,6 @@ extension APIService {
} }
return response return response
// .flatMap { response -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Account>, Error> in
// let log = OSLog.api
// let account = response.value
//
// return self.backgroundManagedObjectContext.performChanges {
// let (mastodonUser, isCreated) = APIService.CoreData.createOrMergeMastodonUser(
// into: self.backgroundManagedObjectContext,
// for: nil,
// in: domain,
// entity: account,
// userCache: nil,
// networkDate: response.networkDate,
// log: log
// )
// let flag = isCreated ? "+" : "-"
// os_log(.info, log: log, "%{public}s[%{public}ld], %{public}s: fetch mastodon user [%s](%s)%s", ((#file as NSString).lastPathComponent), #line, #function, flag, mastodonUser.id, mastodonUser.username)
// }
// .setFailureType(to: Error.self)
// .tryMap { result -> Mastodon.Response.Content<Mastodon.Entity.Account> in
// switch result {
// case .success:
// return response
// case .failure(let error):
// throw error
// }
// }
// .eraseToAnyPublisher()
// }
// .eraseToAnyPublisher()
} }
} }