Skip to content

Commit

Permalink
Show ungrouped notifications as before, but using the new MastodonFee…
Browse files Browse the repository at this point in the history
…dItemIdentifiers

Contributes to IOS-253
Contributes to IOS-355
Contributes to IOS-357
  • Loading branch information
shannon committed Jan 10, 2025
1 parent 1009371 commit 1ec772d
Show file tree
Hide file tree
Showing 16 changed files with 592 additions and 59 deletions.
10 changes: 10 additions & 0 deletions Mastodon/Diffable/Status/StatusSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ extension StatusSection {
switch item {
case .history:
return nil
case .pollOption(let option):
// Fix cell reuse animation issue
let cell: PollOptionTableViewCell = {
let _cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PollOptionTableViewCell.self) + "@\(indexPath.row)#\(indexPath.section)") as? PollOptionTableViewCell
_cell?.prepareForReuse()
return _cell ?? PollOptionTableViewCell()
}()
return cell
case .option(let record):
// Fix cell reuse animation issue
let cell: PollOptionTableViewCell = {
Expand Down Expand Up @@ -175,6 +183,8 @@ extension StatusSection {
) {
statusView.pollTableViewDiffableDataSource = UITableViewDiffableDataSource<PollSection, PollItem>(tableView: statusView.pollTableView) { tableView, indexPath, item in
switch item {
case .pollOption:
return nil
case .option:
return nil
case let .history(option):
Expand Down
22 changes: 11 additions & 11 deletions Mastodon/Protocol/Provider/DataSourceFacade+Status.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ extension DataSourceFacade {
authenticationBox: dependency.authenticationBox,
account: menuContext.author,
relationship: relationship,
status: menuContext.statusViewModel?.originalStatus,
status: menuContext.statusViewModel?._originalStatus,
contentDisplayMode: .neverConceal
)

Expand All @@ -270,7 +270,7 @@ extension DataSourceFacade {
transition: .activityViewControllerPresent(animated: true, completion: nil)
)
case .bookmarkStatus:
guard let status = menuContext.statusViewModel?.originalStatus else {
guard let status = menuContext.statusViewModel?._originalStatus else {
assertionFailure()
return
}
Expand All @@ -279,7 +279,7 @@ extension DataSourceFacade {
status: status
)
case .shareStatus:
guard let status: MastodonStatus = menuContext.statusViewModel?.originalStatus?.reblog ?? menuContext.statusViewModel?.originalStatus else {
guard let status: MastodonStatus = menuContext.statusViewModel?._originalStatus?.reblog ?? menuContext.statusViewModel?._originalStatus else {
assertionFailure()
return
}
Expand Down Expand Up @@ -310,19 +310,19 @@ extension DataSourceFacade {
style: .destructive
) { [weak dependency] _ in
guard let dependency else { return }
guard let status = menuContext.statusViewModel?.originalStatus else { return }
guard let status = menuContext.statusViewModel?._originalStatus else { return }
performDeletion(of: status, with: dependency)
}
alertController.addAction(confirmAction)
let cancelAction = UIAlertAction(title: L10n.Common.Controls.Actions.cancel, style: .cancel)
alertController.addAction(cancelAction)
dependency.present(alertController, animated: true)
} else {
guard let status = menuContext.statusViewModel?.originalStatus else { return }
guard let status = menuContext.statusViewModel?._originalStatus else { return }
performDeletion(of: status, with: dependency)
}
case .translateStatus:
guard let status = menuContext.statusViewModel?.originalStatus?.reblog ?? menuContext.statusViewModel?.originalStatus else { return }
guard let status = menuContext.statusViewModel?._originalStatus?.reblog ?? menuContext.statusViewModel?._originalStatus else { return }

do {
let translation = try await DataSourceFacade.translateStatus(provider: dependency, status: status)
Expand All @@ -336,7 +336,7 @@ extension DataSourceFacade {
}
case .editStatus:

guard let status = menuContext.statusViewModel?.originalStatus else { return }
guard let status = menuContext.statusViewModel?._originalStatus else { return }

let statusSource = try await APIService.shared.getStatusSource(
forStatusID: status.id,
Expand Down Expand Up @@ -391,29 +391,29 @@ extension DataSourceFacade {
alertController.addAction(cancelAction)
dependency.present(alertController, animated: true)
case .boostStatus(_):
guard let status: MastodonStatus = menuContext.statusViewModel?.originalStatus?.reblog ?? menuContext.statusViewModel?.originalStatus else {
guard let status: MastodonStatus = menuContext.statusViewModel?._originalStatus?.reblog ?? menuContext.statusViewModel?._originalStatus else {
assertionFailure()
return
}

try await responseToStatusReblogAction(provider: dependency, status: status)
case .favoriteStatus(_):
guard let status: MastodonStatus = menuContext.statusViewModel?.originalStatus?.reblog ?? menuContext.statusViewModel?.originalStatus else {
guard let status: MastodonStatus = menuContext.statusViewModel?._originalStatus?.reblog ?? menuContext.statusViewModel?._originalStatus else {
assertionFailure()
return
}

try await responseToStatusFavoriteAction(provider: dependency, status: status)
case .copyStatusLink:
guard let status: MastodonStatus = menuContext.statusViewModel?.originalStatus?.reblog ?? menuContext.statusViewModel?.originalStatus else {
guard let status: MastodonStatus = menuContext.statusViewModel?._originalStatus?.reblog ?? menuContext.statusViewModel?._originalStatus else {
assertionFailure()
return
}

UIPasteboard.general.string = status.entity.url
case .openStatusInBrowser:
guard
let status: MastodonStatus = menuContext.statusViewModel?.originalStatus?.reblog ?? menuContext.statusViewModel?.originalStatus,
let status: MastodonStatus = menuContext.statusViewModel?._originalStatus?.reblog ?? menuContext.statusViewModel?._originalStatus,
let urlString = status.entity.url,
let url = URL(string: urlString)
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,15 @@ extension NotificationTimelineViewController: UITableViewDelegate, AutoGenerateT
}

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
guard let item = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else {

let sectionCount = viewModel.diffableDataSource?.numberOfSections(in: tableView) ?? 0
let rowCount = viewModel.diffableDataSource?.tableView(tableView, numberOfRowsInSection: indexPath.section) ?? 0

let isLastItem = indexPath.section == sectionCount - 1 && indexPath.row == rowCount - 1

guard isLastItem, let item = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else {
return
}

// check item type inside `loadMore`
Task {
await viewModel.loadMore(item: item)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extension NotificationTimelineViewModel {

Task {
let oldSnapshot = diffableDataSource.snapshot()
var newSnapshot: NSDiffableDataSourceSnapshot<NotificationSection, NotificationItem> = {
let newSnapshot: NSDiffableDataSourceSnapshot<NotificationSection, NotificationItem> = {
let newItems = records.map { record in
NotificationItem.notification(record)
}
Expand Down
Loading

0 comments on commit 1ec772d

Please sign in to comment.