Cleanup (IOS-192)
This commit is contained in:
parent
a170a462ee
commit
f6e630aa66
|
@ -57,7 +57,7 @@ extension ProfileCardView.ViewModel {
|
||||||
private func bindHeader(view: ProfileCardView) {
|
private func bindHeader(view: ProfileCardView) {
|
||||||
$authorBannerImageURL
|
$authorBannerImageURL
|
||||||
.sink { url in
|
.sink { url in
|
||||||
guard let url = url, !url.absoluteString.hasSuffix(Mastodon.Entity.Account.missingImageName) else {
|
guard let url, !url.absoluteString.hasSuffix(Mastodon.Entity.Account.missingImageName) else {
|
||||||
view.bannerImageView.image = .placeholder(color: .systemGray3)
|
view.bannerImageView.image = .placeholder(color: .systemGray3)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ final class DiscoveryPostsViewModel {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.authContext = authContext
|
self.authContext = authContext
|
||||||
self.dataController = StatusDataController()
|
self.dataController = StatusDataController()
|
||||||
// end init
|
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
await checkServerEndpoint()
|
await checkServerEndpoint()
|
||||||
|
|
|
@ -25,7 +25,6 @@ extension NotificationTimelineViewController: DataSourceProvider {
|
||||||
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 }
|
||||||
|
|
||||||
//TODO: Get relationship
|
|
||||||
if let notification = feed.notification {
|
if let notification = feed.notification {
|
||||||
let mastodonNotification = MastodonNotification.fromEntity(notification, relationship: nil)
|
let mastodonNotification = MastodonNotification.fromEntity(notification, relationship: nil)
|
||||||
return .notification(record: mastodonNotification)
|
return .notification(record: mastodonNotification)
|
||||||
|
|
|
@ -56,7 +56,6 @@ final class NotificationTimelineViewModel {
|
||||||
|
|
||||||
switch scope {
|
switch scope {
|
||||||
case .everything:
|
case .everything:
|
||||||
//TODO: I need the relationship here, too
|
|
||||||
self.dataController.records = (try? FileManager.default.cachedNotificationsAll(for: authContext.mastodonAuthenticationBox))?.map({ notification in
|
self.dataController.records = (try? FileManager.default.cachedNotificationsAll(for: authContext.mastodonAuthenticationBox))?.map({ notification in
|
||||||
MastodonFeed.fromNotification(notification, relationship: nil, kind: .notificationAll)
|
MastodonFeed.fromNotification(notification, relationship: nil, kind: .notificationAll)
|
||||||
}) ?? []
|
}) ?? []
|
||||||
|
|
|
@ -409,7 +409,6 @@ extension ProfileViewController {
|
||||||
|
|
||||||
guard let relationship else { return }
|
guard let relationship else { return }
|
||||||
|
|
||||||
// they don't run as there's not a change, probably?
|
|
||||||
self.viewModel.relationship = relationship
|
self.viewModel.relationship = relationship
|
||||||
self.viewModel.account = account
|
self.viewModel.account = account
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,17 +127,17 @@ extension MainTabBarController {
|
||||||
.sink { [weak self] error in
|
.sink { [weak self] error in
|
||||||
guard let self, let coordinator = self.coordinator else { return }
|
guard let self, let coordinator = self.coordinator else { return }
|
||||||
switch error {
|
switch error {
|
||||||
case .implicit:
|
case .implicit:
|
||||||
break
|
break
|
||||||
case .explicit:
|
case .explicit:
|
||||||
let alertController = UIAlertController(for: error, title: nil, preferredStyle: .alert)
|
let alertController = UIAlertController(for: error, title: nil, preferredStyle: .alert)
|
||||||
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
|
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
|
||||||
alertController.addAction(okAction)
|
alertController.addAction(okAction)
|
||||||
_ = coordinator.present(
|
_ = coordinator.present(
|
||||||
scene: .alertController(alertController: alertController),
|
scene: .alertController(alertController: alertController),
|
||||||
from: nil,
|
from: nil,
|
||||||
transition: .alertController(animated: true, completion: nil)
|
transition: .alertController(animated: true, completion: nil)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.store(in: &disposeBag)
|
.store(in: &disposeBag)
|
||||||
|
|
|
@ -74,12 +74,12 @@ extension SidebarViewModel {
|
||||||
|
|
||||||
let imageURL: URL?
|
let imageURL: URL?
|
||||||
switch item {
|
switch item {
|
||||||
case .me:
|
case .me:
|
||||||
let account = self.authContext?.mastodonAuthenticationBox.authentication.account()
|
let account = self.authContext?.mastodonAuthenticationBox.authentication.account()
|
||||||
imageURL = account?.avatarImageURL()
|
imageURL = account?.avatarImageURL()
|
||||||
case .home, .search, .compose, .notifications:
|
case .home, .search, .compose, .notifications:
|
||||||
// no custom avatar for other tabs
|
// no custom avatar for other tabs
|
||||||
imageURL = nil
|
imageURL = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cell.item = SidebarListContentView.Item(
|
cell.item = SidebarListContentView.Item(
|
||||||
|
|
|
@ -269,75 +269,75 @@ extension SceneDelegate {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch url.host {
|
switch url.host {
|
||||||
case "post":
|
case "post":
|
||||||
showComposeViewController()
|
showComposeViewController()
|
||||||
case "profile":
|
case "profile":
|
||||||
let components = url.pathComponents
|
let components = url.pathComponents
|
||||||
guard
|
guard
|
||||||
components.count == 2,
|
components.count == 2,
|
||||||
components[0] == "/",
|
components[0] == "/",
|
||||||
let authContext = coordinator?.authContext
|
let authContext = coordinator?.authContext
|
||||||
else { return }
|
else { return }
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
let authenticationBox = authContext.mastodonAuthenticationBox
|
let authenticationBox = authContext.mastodonAuthenticationBox
|
||||||
|
|
||||||
guard let me = authContext.mastodonAuthenticationBox.authentication.account() else { return }
|
guard let me = authContext.mastodonAuthenticationBox.authentication.account() else { return }
|
||||||
|
|
||||||
guard let account = try await AppContext.shared.apiService.search(
|
guard let account = try await AppContext.shared.apiService.search(
|
||||||
query: .init(q: components[1], type: .accounts, resolve: true),
|
query: .init(q: components[1], type: .accounts, resolve: true),
|
||||||
authenticationBox: authenticationBox
|
authenticationBox: authenticationBox
|
||||||
).value.accounts.first else { return }
|
).value.accounts.first else { return }
|
||||||
|
|
||||||
guard let relationship = try await AppContext.shared.apiService.relationship(
|
guard let relationship = try await AppContext.shared.apiService.relationship(
|
||||||
forAccounts: [account],
|
forAccounts: [account],
|
||||||
authenticationBox: authenticationBox
|
authenticationBox: authenticationBox
|
||||||
).value.first else { return }
|
).value.first else { return }
|
||||||
|
|
||||||
let profileViewModel = ProfileViewModel(
|
let profileViewModel = ProfileViewModel(
|
||||||
context: AppContext.shared,
|
context: AppContext.shared,
|
||||||
authContext: authContext,
|
authContext: authContext,
|
||||||
account: account,
|
account: account,
|
||||||
relationship: relationship,
|
relationship: relationship,
|
||||||
me: me
|
me: me
|
||||||
)
|
)
|
||||||
|
|
||||||
self.coordinator?.present(
|
self.coordinator?.present(
|
||||||
scene: .profile(viewModel: profileViewModel),
|
scene: .profile(viewModel: profileViewModel),
|
||||||
from: nil,
|
from: nil,
|
||||||
transition: .show
|
transition: .show
|
||||||
)
|
)
|
||||||
} catch {
|
} catch {
|
||||||
// fail silently
|
// fail silently
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case "status":
|
}
|
||||||
let components = url.pathComponents
|
case "status":
|
||||||
guard
|
let components = url.pathComponents
|
||||||
components.count == 2,
|
guard
|
||||||
components[0] == "/",
|
components.count == 2,
|
||||||
let authContext = coordinator?.authContext
|
components[0] == "/",
|
||||||
else { return }
|
let authContext = coordinator?.authContext
|
||||||
let statusId = components[1]
|
else { return }
|
||||||
// View post from user
|
let statusId = components[1]
|
||||||
let threadViewModel = RemoteThreadViewModel(
|
// View post from user
|
||||||
context: AppContext.shared,
|
let threadViewModel = RemoteThreadViewModel(
|
||||||
authContext: authContext,
|
context: AppContext.shared,
|
||||||
statusID: statusId
|
authContext: authContext,
|
||||||
)
|
statusID: statusId
|
||||||
coordinator?.present(scene: .thread(viewModel: threadViewModel), from: nil, transition: .show)
|
)
|
||||||
case "search":
|
coordinator?.present(scene: .thread(viewModel: threadViewModel), from: nil, transition: .show)
|
||||||
let queryItems = URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems
|
case "search":
|
||||||
guard
|
let queryItems = URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems
|
||||||
let authContext = coordinator?.authContext,
|
guard
|
||||||
let searchQuery = queryItems?.first(where: { $0.name == "query" })?.value
|
let authContext = coordinator?.authContext,
|
||||||
else { return }
|
let searchQuery = queryItems?.first(where: { $0.name == "query" })?.value
|
||||||
|
else { return }
|
||||||
|
|
||||||
let viewModel = SearchDetailViewModel(authContext: authContext, initialSearchText: searchQuery)
|
let viewModel = SearchDetailViewModel(authContext: authContext, initialSearchText: searchQuery)
|
||||||
coordinator?.present(scene: .searchDetail(viewModel: viewModel), from: nil, transition: .show)
|
coordinator?.present(scene: .searchDetail(viewModel: viewModel), from: nil, transition: .show)
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public enum Persistence {
|
||||||
private var filename: String {
|
private var filename: String {
|
||||||
switch self {
|
switch self {
|
||||||
case .searchHistory(let userIdentifier):
|
case .searchHistory(let userIdentifier):
|
||||||
return "search_history_\(uniqueUserDomainIdentifier(for: userIdentifier))" // todo: @zeitschlag should this be user-scoped as well?
|
return "search_history_\(uniqueUserDomainIdentifier(for: userIdentifier))"
|
||||||
case let .homeTimeline(userIdentifier):
|
case let .homeTimeline(userIdentifier):
|
||||||
return "home_timeline_\(uniqueUserDomainIdentifier(for: userIdentifier))"
|
return "home_timeline_\(uniqueUserDomainIdentifier(for: userIdentifier))"
|
||||||
case let .notificationsMentions(userIdentifier):
|
case let .notificationsMentions(userIdentifier):
|
||||||
|
|
|
@ -97,33 +97,30 @@ extension NotificationService {
|
||||||
extension NotificationService {
|
extension NotificationService {
|
||||||
public func unreadApplicationShortcutItems() async throws -> [UIApplicationShortcutItem] {
|
public func unreadApplicationShortcutItems() async throws -> [UIApplicationShortcutItem] {
|
||||||
guard let authenticationService = self.authenticationService else { return [] }
|
guard let authenticationService = self.authenticationService else { return [] }
|
||||||
let managedObjectContext = authenticationService.managedObjectContext
|
|
||||||
return try await managedObjectContext.perform {
|
|
||||||
var items: [UIApplicationShortcutItem] = []
|
|
||||||
for authentication in AuthenticationServiceProvider.shared.authentications {
|
|
||||||
guard let account = authentication.account() else { continue }
|
|
||||||
let accessToken = authentication.userAccessToken
|
|
||||||
let count = UserDefaults.shared.getNotificationCountWithAccessToken(accessToken: accessToken)
|
|
||||||
guard count > 0 else { continue }
|
|
||||||
|
|
||||||
let title = "@\(account.acctWithDomain)"
|
var items: [UIApplicationShortcutItem] = []
|
||||||
let subtitle = L10n.A11y.Plural.Count.Unread.notification(count)
|
for authentication in AuthenticationServiceProvider.shared.authentications {
|
||||||
|
guard let account = authentication.account() else { continue }
|
||||||
|
let accessToken = authentication.userAccessToken
|
||||||
|
let count = UserDefaults.shared.getNotificationCountWithAccessToken(accessToken: accessToken)
|
||||||
|
guard count > 0 else { continue }
|
||||||
|
|
||||||
let item = UIApplicationShortcutItem(
|
let title = "@\(account.acctWithDomain)"
|
||||||
type: NotificationService.unreadShortcutItemIdentifier,
|
let subtitle = L10n.A11y.Plural.Count.Unread.notification(count)
|
||||||
localizedTitle: title,
|
|
||||||
localizedSubtitle: subtitle,
|
let item = UIApplicationShortcutItem(
|
||||||
icon: nil,
|
type: NotificationService.unreadShortcutItemIdentifier,
|
||||||
userInfo: [
|
localizedTitle: title,
|
||||||
"accessToken": accessToken as NSSecureCoding
|
localizedSubtitle: subtitle,
|
||||||
]
|
icon: nil,
|
||||||
)
|
userInfo: [
|
||||||
items.append(item)
|
"accessToken": accessToken as NSSecureCoding
|
||||||
}
|
]
|
||||||
return items
|
)
|
||||||
|
items.append(item)
|
||||||
}
|
}
|
||||||
}
|
return items
|
||||||
}
|
}}
|
||||||
|
|
||||||
extension NotificationService {
|
extension NotificationService {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue