Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Mastodon/Diffable/Report/ReportSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ extension ReportSection {
return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item -> UITableViewCell? in
switch item {
case .header(let headerContext):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportHeadlineTableViewCell.self), for: indexPath) as! ReportHeadlineTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportHeadlineTableViewCell.self), for: indexPath) as? ReportHeadlineTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
cell.primaryLabel.text = headerContext.primaryLabelText
cell.secondaryLabel.text = headerContext.secondaryLabelText
return cell
case .status(let status):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportStatusTableViewCell.self), for: indexPath) as! ReportStatusTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportStatusTableViewCell.self), for: indexPath) as? ReportStatusTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
configure(
tableView: tableView,
cell: cell,
Expand All @@ -54,7 +60,10 @@ extension ReportSection {
)
return cell
case .comment(let commentContext):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportCommentTableViewCell.self), for: indexPath) as! ReportCommentTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportCommentTableViewCell.self), for: indexPath) as? ReportCommentTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
cell.commentTextView.text = commentContext.comment
NotificationCenter.default.publisher(for: UITextView.textDidChangeNotification, object: cell.commentTextView)
.receive(on: DispatchQueue.main)
Expand All @@ -71,7 +80,9 @@ extension ReportSection {
.store(in: &cell.disposeBag)
return cell
case .bottomLoader:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { assertionFailure("unexpected cell dequeued")
return nil
}
cell.activityIndicatorView.startAnimating()
return cell
}
Expand Down
55 changes: 40 additions & 15 deletions Mastodon/Diffable/Status/StatusSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ extension StatusSection {
return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item -> UITableViewCell? in
switch item {
case .feed(let feed):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as! StatusTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? StatusTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
let displayItem = StatusTableViewCell.StatusTableViewCellViewModel.DisplayItem.feed(feed)
let contentConcealModel = StatusView.ContentConcealViewModel(status: feed.status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: configuration.filterContext)
configure(
Expand All @@ -53,15 +56,21 @@ extension StatusSection {
)
return cell
case .feedLoader(let feed):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineMiddleLoaderTableViewCell.self), for: indexPath) as! TimelineMiddleLoaderTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineMiddleLoaderTableViewCell.self), for: indexPath) as? TimelineMiddleLoaderTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
configure(
cell: cell,
feed: feed,
configuration: configuration
)
return cell
case .status(let status):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as! StatusTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? StatusTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
let displayItem = StatusTableViewCell.StatusTableViewCellViewModel.DisplayItem.status(status)
let contentConcealModel = StatusView.ContentConcealViewModel(status: status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: configuration.filterContext)
configure(
Expand All @@ -82,11 +91,15 @@ extension StatusSection {
)
return cell
case .topLoader:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { assertionFailure("unexpected cell dequeued")
return nil
}
cell.activityIndicatorView.startAnimating()
return cell
case .bottomLoader:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { assertionFailure("unexpected cell dequeued")
return nil
}
cell.activityIndicatorView.startAnimating()
return cell
}
Expand All @@ -109,7 +122,10 @@ extension StatusSection {
) -> UITableViewCell {
switch configuration.thread {
case .root(let threadContext):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusThreadRootTableViewCell.self), for: indexPath) as! StatusThreadRootTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusThreadRootTableViewCell.self), for: indexPath) as? StatusThreadRootTableViewCell else {
assertionFailure("unexpected cell dequeued")
return UITableViewCell()
}
let contentConcealModel = StatusView.ContentConcealViewModel(status: threadContext.status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: .thread)
StatusSection.configure(
tableView: tableView,
Expand All @@ -120,7 +136,10 @@ extension StatusSection {
return cell
case .reply(let threadContext),
.leaf(let threadContext):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as! StatusTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? StatusTableViewCell else {
assertionFailure("unexpected cell dequeued")
return UITableViewCell()
}
let displayItem = StatusTableViewCell.StatusTableViewCellViewModel.DisplayItem.status(threadContext.status)
let contentConcealModel = StatusView.ContentConcealViewModel(status: threadContext.status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: configuration.configuration.filterContext)
assert(configuration.configuration.filterContext == .thread)
Expand All @@ -147,12 +166,15 @@ extension StatusSection {
return nil
case .option(let record):
// Fix cell reuse animation issue
let cell: PollOptionTableViewCell = {
guard 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
}() else {
assertionFailure("unexpected cell dequeued")
return nil
}

cell.pollOptionView.viewModel.authenticationBox = authenticationBox

cell.pollOptionView.configure(pollOption: record)
Expand All @@ -179,12 +201,15 @@ extension StatusSection {
return nil
case let .history(option):
// Fix cell reuse animation issue
let cell: PollOptionTableViewCell = {
guard 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
}() else {
assertionFailure("unexpected cell dequeued")
return nil
}

cell.pollOptionView.configure(historyPollOption: option)

return cell
Expand Down
14 changes: 11 additions & 3 deletions Mastodon/Diffable/User/UserSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ extension UserSection {
item -> UITableViewCell? in
switch item {
case .account(let account, let relationship):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UserTableViewCell.self), for: indexPath) as! UserTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UserTableViewCell.self), for: indexPath) as? UserTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}

guard let me = authenticationBox.cachedAccount else { return cell }

Expand All @@ -49,11 +52,16 @@ extension UserSection {

return cell
case .bottomLoader:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { assertionFailure("unexpected cell dequeued")
return nil
}
cell.startAnimating()
return cell
case .bottomHeader(let text):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineFooterTableViewCell.self), for: indexPath) as! TimelineFooterTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineFooterTableViewCell.self), for: indexPath) as? TimelineFooterTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
cell.messageLabel.text = text
return cell
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ extension UITableViewDelegate where Self: DataSourceProvider & MediaPreviewableV
indexPath: IndexPath, point: CGPoint
) -> UIContextMenuConfiguration? {

guard let cell = tableView.cellForRow(at: indexPath) as? StatusViewContainerTableViewCell else { return nil }
guard let cell = tableView.cellForRow(at: indexPath) as? StatusViewContainerTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}

let mediaViews = cell.statusView.mediaGridContainerView.mediaViews

Expand Down
15 changes: 12 additions & 3 deletions Mastodon/Scene/Account/AccountListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ extension AccountListViewModel {
diffableDataSource = UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item in
switch item {
case .authentication(let record):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AccountListTableViewCell.self), for: indexPath) as! AccountListTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AccountListTableViewCell.self), for: indexPath) as? AccountListTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
if let activeAuthentication = AuthenticationServiceProvider.shared.currentActiveUser.value
{
AccountListViewModel.configure(
Expand All @@ -84,10 +87,16 @@ extension AccountListViewModel {
}
return cell
case .addAccount:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AddAccountTableViewCell.self), for: indexPath) as! AddAccountTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AddAccountTableViewCell.self), for: indexPath) as? AddAccountTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
return cell
case .logoutOfAllAccounts:
let cell = tableView.dequeueReusableCell(withIdentifier: LogoutOfAllAccountsCell.reuseIdentifier, for: indexPath) as! LogoutOfAllAccountsCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: LogoutOfAllAccountsCell.reuseIdentifier, for: indexPath) as? LogoutOfAllAccountsCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
return cell
}
}
Expand Down
21 changes: 17 additions & 4 deletions Mastodon/Scene/Discovery/DiscoverySection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,25 @@ extension DiscoverySection {
item in
switch item {
case .hashtag(let tag):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TrendTableViewCell.self), for: indexPath) as! TrendTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TrendTableViewCell.self), for: indexPath) as? TrendTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
cell.trendView.configure(tag: tag)
return cell
case .link(let link):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: NewsTableViewCell.self), for: indexPath) as! NewsTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: NewsTableViewCell.self), for: indexPath) as? NewsTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
cell.newsView.configure(link: link)
return cell
case .account(let account, relationship: let relationship):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ProfileCardTableViewCell.self), for: indexPath) as! ProfileCardTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ProfileCardTableViewCell.self), for: indexPath) as?
ProfileCardTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}

cell.configure(
tableView: tableView,
Expand All @@ -80,7 +90,10 @@ extension DiscoverySection {

return cell
case .bottomLoader:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else {
assertionFailure("unexpected cell dequeued")
return nil
}
cell.activityIndicatorView.startAnimating()
return cell
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class NotificationPolicyViewController: UIViewController {

let dataSource = UITableViewDiffableDataSource<NotificationFilterSection, NotificationFilterItem>(tableView: tableView) { [weak self] tableView, indexPath, itemIdentifier in
guard let self, let cell = tableView.dequeueReusableCell(withIdentifier: NotificationPolicyFilterTableViewCell.reuseIdentifier, for: indexPath) as? NotificationPolicyFilterTableViewCell else {
fatalError("No NotificationPolicyFilterTableViewCell")
assertionFailure("unexpected cell dequeued")
return nil
}

let item = items[indexPath.row]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class NotificationRequestsTableViewController: UIViewController {

let dataSource = UITableViewDiffableDataSource<NotificationRequestsSection, NotificationRequestItem>(tableView: tableView) { tableView, indexPath, itemIdentifier in
guard let cell = tableView.dequeueReusableCell(withIdentifier: NotificationRequestTableViewCell.reuseIdentifier, for: indexPath) as? NotificationRequestTableViewCell else {
fatalError("No NotificationRequestTableViewCell")
assertionFailure("unexpected cell dequeued")
return nil
}

let request = viewModel.requests[indexPath.row]
Expand Down
Loading