Kurdtvs-Live-Kurdish-TV-Kur.../Mastodon/Scene/Notification/NotificationViewModel.swift

99 lines
3.4 KiB
Swift
Raw Normal View History

2021-04-12 10:31:53 +02:00
//
// NotificationViewModel.swift
// Mastodon
//
// Created by sxiaojian on 2021/4/12.
//
import os.log
2021-04-15 04:16:30 +02:00
import UIKit
import Combine
import MastodonAsset
import MastodonLocalization
import Pageboy
2021-04-12 10:31:53 +02:00
final class NotificationViewModel {
2021-04-12 10:31:53 +02:00
var disposeBag = Set<AnyCancellable>()
// input
let context: AppContext
2021-04-13 15:31:49 +02:00
let viewDidLoad = PassthroughSubject<Void, Never>()
2021-04-12 10:31:53 +02:00
// output
let scopes = NotificationTimelineViewModel.Scope.allCases
@Published var viewControllers: [UIViewController] = []
@Published var currentPageIndex = 0
2021-04-15 04:16:30 +02:00
2021-04-14 13:04:11 +02:00
init(context: AppContext) {
2021-04-12 10:31:53 +02:00
self.context = context
// end init
2021-04-27 10:54:23 +02:00
}
}
2021-04-27 10:54:23 +02:00
extension NotificationTimelineViewModel.Scope {
var title: String {
switch self {
case .everything:
return L10n.Scene.Notification.Title.everything
case .mentions:
return L10n.Scene.Notification.Title.mentions
}
2021-04-27 10:54:23 +02:00
}
2021-04-12 10:31:53 +02:00
}
2021-04-16 07:45:54 +02:00
// func acceptFollowRequest(notification: MastodonNotification) {
// guard let activeMastodonAuthenticationBox = self.activeMastodonAuthenticationBox.value else { return }
// context.apiService.acceptFollowRequest(mastodonUserID: notification.account.id, mastodonAuthenticationBox: activeMastodonAuthenticationBox)
// .sink { [weak self] completion in
// switch completion {
// case .failure(let error):
// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: accept FollowRequest fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
// case .finished:
// break
//// self?.loadLatestStateMachine.enter(NotificationViewModel.LoadLatestState.Loading.self)
// }
// } receiveValue: { _ in
//
// }
// .store(in: &disposeBag)
// }
//
// func rejectFollowRequest(notification: MastodonNotification) {
// guard let activeMastodonAuthenticationBox = self.activeMastodonAuthenticationBox.value else { return }
// context.apiService.rejectFollowRequest(mastodonUserID: notification.account.id, mastodonAuthenticationBox: activeMastodonAuthenticationBox)
// .sink { [weak self] completion in
// switch completion {
// case .failure(let error):
// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: reject FollowRequest fail: %s", ((#file as NSString).lastPathComponent), #line, #function, error.localizedDescription)
// case .finished:
// break
//// self?.loadLatestStateMachine.enter(NotificationViewModel.LoadLatestState.Loading.self)
// }
// } receiveValue: { _ in
//
// }
// .store(in: &disposeBag)
// }
//}
// MARK: - PageboyViewControllerDataSource
extension NotificationViewModel: PageboyViewControllerDataSource {
func numberOfViewControllers(in pageboyViewController: PageboyViewController) -> Int {
return viewControllers.count
2021-04-16 07:45:54 +02:00
}
func viewController(for pageboyViewController: PageboyViewController, at index: PageboyViewController.PageIndex) -> UIViewController? {
return viewControllers[index]
}
func defaultPage(for pageboyViewController: PageboyViewController) -> PageboyViewController.Page? {
return .first
}
2021-04-16 07:45:54 +02:00
}