mirror of
https://github.com/mastodon/mastodon-ios
synced 2025-04-11 22:58:02 +02:00
Address PR Feedback (IOS-176)
This commit is contained in:
parent
405b175bdf
commit
bf433e332f
@ -569,7 +569,10 @@ public extension SceneCoordinator {
|
||||
@MainActor
|
||||
func showLoading(on viewController: UIViewController?) {
|
||||
guard let viewController else { return }
|
||||
|
||||
|
||||
/// Don't add HUD twice
|
||||
guard MBProgressHUD.forView(viewController.view) == nil else { return }
|
||||
|
||||
MBProgressHUD.showAdded(to: viewController.view, animated: true)
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,6 @@ extension DataSourceFacade {
|
||||
|
||||
await responseToURLAction(
|
||||
provider: provider,
|
||||
status: status,
|
||||
url: url
|
||||
)
|
||||
case .hashtag(_, let hashtag, _):
|
||||
|
@ -12,19 +12,21 @@ import MastodonSDK
|
||||
|
||||
extension DataSourceFacade {
|
||||
|
||||
@MainActor
|
||||
static func coordinateToProfileScene(
|
||||
provider: DataSourceProvider & AuthContextProvider,
|
||||
target: StatusTarget,
|
||||
status: MastodonStatus
|
||||
) async {
|
||||
let acct: String = {
|
||||
switch target {
|
||||
case .status:
|
||||
return status.reblog?.entity.account.acct ?? status.entity.account.acct
|
||||
case .reblog:
|
||||
return status.entity.account.acct
|
||||
}
|
||||
}()
|
||||
let acct: String
|
||||
switch target {
|
||||
case .status:
|
||||
acct = status.reblog?.entity.account.acct ?? status.entity.account.acct
|
||||
case .reblog:
|
||||
acct = status.entity.account.acct
|
||||
}
|
||||
|
||||
provider.coordinator.showLoading()
|
||||
|
||||
let _redirectRecord = try? await Mastodon.API.Account.lookupAccount(
|
||||
session: .shared,
|
||||
@ -35,6 +37,7 @@ extension DataSourceFacade {
|
||||
|
||||
guard let redirectRecord = _redirectRecord else {
|
||||
assertionFailure()
|
||||
provider.coordinator.hideLoading()
|
||||
return
|
||||
}
|
||||
await coordinateToProfileScene(
|
||||
@ -110,12 +113,9 @@ extension DataSourceFacade {
|
||||
return
|
||||
}
|
||||
|
||||
let managedObjectContext = provider.context.managedObjectContext
|
||||
let mentions = try? await managedObjectContext.perform {
|
||||
return status.entity.mentions ?? []
|
||||
}
|
||||
let mentions = status.entity.mentions ?? []
|
||||
|
||||
guard let mention = mentions?.first(where: { $0.url == href }) else {
|
||||
guard let mention = mentions.first(where: { $0.url == href }) else {
|
||||
_ = provider.coordinator.present(
|
||||
scene: .safari(url: url),
|
||||
from: provider,
|
||||
|
@ -14,7 +14,6 @@ import MastodonSDK
|
||||
extension DataSourceFacade {
|
||||
static func responseToURLAction(
|
||||
provider: DataSourceProvider & AuthContextProvider,
|
||||
status: MastodonStatus,
|
||||
url: URL
|
||||
) async {
|
||||
let domain = provider.authContext.mastodonAuthenticationBox.domain
|
||||
|
@ -182,9 +182,15 @@ extension NotificationTableViewCellDelegate where Self: DataSourceProvider & Med
|
||||
|
||||
let _mediaTransitionContext: NotificationMediaTransitionContext? = {
|
||||
guard let status = record.status?.reblog ?? record.status else { return nil }
|
||||
let needsToBeToggled: Bool = {
|
||||
guard let sensitive = status.entity.sensitive else {
|
||||
return false
|
||||
}
|
||||
return status.isSensitiveToggled ? !sensitive : sensitive
|
||||
}()
|
||||
return NotificationMediaTransitionContext(
|
||||
status: status,
|
||||
needsToggleMediaSensitive: status.isSensitiveToggled ? !(status.entity.sensitive == true) : (status.entity.sensitive == true)
|
||||
needsToggleMediaSensitive: needsToBeToggled
|
||||
)
|
||||
}()
|
||||
|
||||
|
@ -148,7 +148,6 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte
|
||||
|
||||
await DataSourceFacade.responseToURLAction(
|
||||
provider: self,
|
||||
status: status,
|
||||
url: url
|
||||
)
|
||||
}
|
||||
@ -173,7 +172,6 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte
|
||||
|
||||
await DataSourceFacade.responseToURLAction(
|
||||
provider: self,
|
||||
status: status,
|
||||
url: url
|
||||
)
|
||||
}
|
||||
|
@ -65,10 +65,7 @@ extension StatusTableViewControllerNavigateableCore where Self: DataSourceProvid
|
||||
case .status(let record):
|
||||
return record
|
||||
case .notification(let record):
|
||||
guard let statusRecord = record.status else {
|
||||
return nil
|
||||
}
|
||||
return statusRecord
|
||||
return record.status
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
@ -40,9 +40,7 @@ extension UITableViewDelegate where Self: DataSourceProvider & AuthContextProvid
|
||||
provider: self,
|
||||
tag: tag
|
||||
)
|
||||
case .notification(let notification):
|
||||
let managedObjectContext = context.managedObjectContext
|
||||
|
||||
case .notification(let notification):
|
||||
let _status: MastodonStatus? = notification.status
|
||||
if let status = _status {
|
||||
await DataSourceFacade.coordinateToStatusThreadScene(
|
||||
|
@ -22,15 +22,12 @@ extension HomeTimelineViewController: DataSourceProvider {
|
||||
|
||||
switch item {
|
||||
case .feed(let feed):
|
||||
let item: DataSourceItem? = {
|
||||
guard feed.kind == .home else { return nil }
|
||||
if let status = feed.status {
|
||||
return .status(record: status)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}()
|
||||
return item
|
||||
guard feed.kind == .home else { return nil }
|
||||
if let status = feed.status {
|
||||
return .status(record: status)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
@ -52,10 +52,7 @@ extension HomeTimelineViewModel.LoadOldestState {
|
||||
}
|
||||
|
||||
Task {
|
||||
let _maxID: Mastodon.Entity.Status.ID? = {
|
||||
guard let status = lastFeedRecord.status else { return nil }
|
||||
return status.id
|
||||
}()
|
||||
let _maxID = lastFeedRecord.status?.id
|
||||
|
||||
guard let maxID = _maxID else {
|
||||
await self.enter(state: Fail.self)
|
||||
|
@ -42,7 +42,7 @@ extension NotificationTimelineViewController: DataSourceProvider {
|
||||
}
|
||||
|
||||
func delete(status: MastodonStatus) {
|
||||
viewModel.feedFetchedResultsController
|
||||
viewModel.feedFetchedResultsController.delete(status: status)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
@ -111,18 +111,6 @@ extension NotificationTimelineViewModel {
|
||||
|
||||
// load timeline gap
|
||||
func loadMore(item: NotificationItem) async {
|
||||
// guard case let .feedLoader(record) = item else { return }
|
||||
|
||||
// guard let maxID = record.notification?.id else { return }
|
||||
|
||||
// // fetch data
|
||||
// if let notifications = try? await context.apiService.notifications(
|
||||
// maxID: maxID,
|
||||
// scope: scope,
|
||||
// authenticationBox: authContext.mastodonAuthenticationBox
|
||||
// ) {
|
||||
// self.feedFetchedResultsController.records += notifications.value.map { MastodonFeed.fromNotification($0, kind: record.kind) }
|
||||
// }
|
||||
switch scope {
|
||||
case .everything:
|
||||
feedFetchedResultsController.loadNext(kind: .notificationAll)
|
||||
|
@ -9,6 +9,7 @@ import UIKit
|
||||
import MastodonSDK
|
||||
|
||||
extension ReportStatusTableViewCell {
|
||||
// todo: refactor / remove this
|
||||
final class ViewModel {
|
||||
let value: MastodonStatus
|
||||
|
||||
|
@ -13,6 +13,12 @@ public protocol UserIdentifier {
|
||||
var userID: Mastodon.Entity.Account.ID { get }
|
||||
}
|
||||
|
||||
public extension UserIdentifier {
|
||||
var uniqueUserDomainIdentifier: String {
|
||||
"\(userID)@\(domain)"
|
||||
}
|
||||
}
|
||||
|
||||
public struct MastodonUserIdentifier: UserIdentifier {
|
||||
public let domain: String
|
||||
public var userID: Mastodon.Entity.Account.ID
|
||||
|
@ -14,20 +14,16 @@ public enum Persistence {
|
||||
case notificationsMentions(UserIdentifier)
|
||||
case notificationsAll(UserIdentifier)
|
||||
|
||||
private func uniqueUserDomainIdentifier(for userIdentifier: UserIdentifier) -> String {
|
||||
"\(userIdentifier.userID)@\(userIdentifier.domain)"
|
||||
}
|
||||
|
||||
private var filename: String {
|
||||
switch self {
|
||||
case .searchHistory:
|
||||
return "search_history" // todo: @zeitschlag should this be user-scoped as well?
|
||||
case let .homeTimeline(userIdentifier):
|
||||
return "home_timeline_\(uniqueUserDomainIdentifier(for: userIdentifier))"
|
||||
return "home_timeline_\(userIdentifier.uniqueUserDomainIdentifier)"
|
||||
case let .notificationsMentions(userIdentifier):
|
||||
return "notifications_mentions_\(uniqueUserDomainIdentifier(for: userIdentifier))"
|
||||
return "notifications_mentions_\(userIdentifier.uniqueUserDomainIdentifier)"
|
||||
case let .notificationsAll(userIdentifier):
|
||||
return "notifications_all_\(uniqueUserDomainIdentifier(for: userIdentifier))"
|
||||
return "notifications_all_\(userIdentifier.uniqueUserDomainIdentifier)"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,8 @@ extension APIService {
|
||||
for entity in response.value {
|
||||
guard let poll = entity.poll else { continue }
|
||||
_ = Persistence.Poll.createOrMerge(
|
||||
in: managedObjectContext,
|
||||
context: .init(domain: domain, entity: poll, me: me, networkDate: response.networkDate)
|
||||
in: managedObjectContext,
|
||||
context: .init(domain: domain, entity: poll, me: me, networkDate: response.networkDate)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ extension APIService {
|
||||
for entity in response.value {
|
||||
guard let poll = entity.poll else { continue }
|
||||
_ = Persistence.Poll.createOrMerge(
|
||||
in: managedObjectContext,
|
||||
context: .init(domain: domain, entity: poll, me: me, networkDate: response.networkDate)
|
||||
in: managedObjectContext,
|
||||
context: .init(domain: domain, entity: poll, me: me, networkDate: response.networkDate)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ extension APIService {
|
||||
for entity in response.value {
|
||||
guard let poll = entity.poll else { continue }
|
||||
_ = Persistence.Poll.createOrMerge(
|
||||
in: managedObjectContext,
|
||||
context: .init(domain: domain, entity: poll, me: me, networkDate: response.networkDate)
|
||||
in: managedObjectContext,
|
||||
context: .init(domain: domain, entity: poll, me: me, networkDate: response.networkDate)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -344,9 +344,12 @@ private extension Mastodon.Entity.Card {
|
||||
if !aspectRatio.isFinite {
|
||||
aspectRatio = 1
|
||||
}
|
||||
return (abs(aspectRatio - 1) < 0.05 || image == nil) && html == nil
|
||||
? .compact
|
||||
: .large(aspectRatio: aspectRatio)
|
||||
|
||||
if (abs(aspectRatio - 1) < 0.05 || image == nil) && html == nil {
|
||||
return .compact
|
||||
} else {
|
||||
return .large(aspectRatio: aspectRatio)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,6 @@ extension StatusView {
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
} // end if let
|
||||
// } // end else B2.
|
||||
} // end else B.
|
||||
|
||||
} else {
|
||||
@ -389,14 +388,17 @@ extension StatusView {
|
||||
|
||||
private func configurePoll(status: MastodonStatus) {
|
||||
let status = status.reblog ?? status
|
||||
|
||||
let predicate = Poll.predicate(domain: viewModel.authContext?.mastodonAuthenticationBox.domain ?? "", id: status.entity.poll?.id ?? "")
|
||||
|
||||
|
||||
guard
|
||||
let context = viewModel.context?.managedObjectContext,
|
||||
let poll = Poll.findOrFetch(in: context, matching: predicate)
|
||||
else { return }
|
||||
|
||||
let domain = viewModel.authContext?.mastodonAuthenticationBox.domain,
|
||||
let pollId = status.entity.poll?.id
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
let predicate = Poll.predicate(domain: domain, id: pollId)
|
||||
guard let poll = Poll.findOrFetch(in: context, matching: predicate) else { return }
|
||||
|
||||
viewModel.managedObjects.insert(poll)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user