2022-01-27 14:23:39 +01:00
|
|
|
//
|
|
|
|
// RecommendAccountSection.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/4/1.
|
|
|
|
//
|
|
|
|
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import Foundation
|
|
|
|
import MastodonSDK
|
|
|
|
import UIKit
|
|
|
|
import MetaTextKit
|
|
|
|
import MastodonMeta
|
|
|
|
import Combine
|
2022-10-08 07:43:06 +02:00
|
|
|
import MastodonCore
|
2022-01-27 14:23:39 +01:00
|
|
|
|
|
|
|
enum RecommendAccountSection: Equatable, Hashable {
|
|
|
|
case main
|
|
|
|
}
|
|
|
|
|
2022-02-10 12:30:41 +01:00
|
|
|
extension RecommendAccountSection {
|
|
|
|
|
|
|
|
struct Configuration {
|
2022-10-09 14:07:57 +02:00
|
|
|
let authContext: AuthContext
|
2022-02-10 12:30:41 +01:00
|
|
|
weak var suggestionAccountTableViewCellDelegate: SuggestionAccountTableViewCellDelegate?
|
|
|
|
}
|
|
|
|
|
|
|
|
static func tableViewDiffableDataSource(
|
|
|
|
tableView: UITableView,
|
|
|
|
context: AppContext,
|
|
|
|
configuration: Configuration
|
|
|
|
) -> UITableViewDiffableDataSource<RecommendAccountSection, RecommendAccountItem> {
|
|
|
|
UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item -> UITableViewCell? in
|
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SuggestionAccountTableViewCell.self)) as! SuggestionAccountTableViewCell
|
|
|
|
switch item {
|
|
|
|
case .account(let record):
|
2023-05-22 13:28:18 +02:00
|
|
|
cell.delegate = configuration.suggestionAccountTableViewCellDelegate
|
2022-02-10 12:30:41 +01:00
|
|
|
context.managedObjectContext.performAndWait {
|
|
|
|
guard let user = record.object(in: context.managedObjectContext) else { return }
|
2023-05-22 13:30:05 +02:00
|
|
|
cell.configure(viewModel:
|
2023-05-22 16:14:06 +02:00
|
|
|
SuggestionAccountTableViewCell.ViewModel(
|
|
|
|
user: user,
|
|
|
|
followedUsers: configuration.authContext.mastodonAuthenticationBox.inMemoryCache.followingUserIds,
|
|
|
|
blockedUsers: configuration.authContext.mastodonAuthenticationBox.inMemoryCache.blockedUserIds,
|
|
|
|
followRequestedUsers: configuration.authContext.mastodonAuthenticationBox.inMemoryCache.followRequestedUserIDs)
|
2023-05-22 13:30:05 +02:00
|
|
|
)
|
2022-02-10 12:30:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return cell
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|