Files
session-ios/Session/Shared/SessionTableViewModel.swift
Morgan Pretty 73d59be6e0 Removed the old libSessionObservation, fixed a couple of bugs
• Added a mechanism to trigger an immediate event (it forces the debouncer to flush)
• Updated the ThreadNotificationSettingsViewModel to use the ObservationBuilder
• Updated the AppearanceViewModel to use the ObservationBuilder
• Updated the ConversationSettingsViewModel to use the ObservationBuilder
• Updated the NotificationContentViewModel to use the ObservationBuilder
• Updated the NotificationSettingsViewModel to use the ObservationBuilder
• Updated the PrivacySettingsViewModel to use the ObservationBuilder
• Updated the SettingsViewModel to use the ObservationBuilder
• Cleaned up the MessageRequestsViewModel and HomeViewModel to be consistent with the other refactored view models
• Removed the `libSessionObservation` logic (replaced with new ObservationBuilder)
• Fixed a bug where the notification sound setting might not work correctly
• Fixed a few incorrect events being sent
2025-07-14 16:44:03 +10:00

67 lines
2.8 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import UIKit
import Combine
import GRDB
import DifferenceKit
import SessionUIKit
import SessionMessagingKit
import SessionUtilitiesKit
protocol SessionTableViewModel: AnyObject, SectionedTableData {
var dependencies: Dependencies { get }
var searchable: Bool { get }
var title: String { get }
var subtitle: String? { get }
var initialLoadMessage: String? { get }
var cellType: SessionTableViewCellType { get }
var bannerInfo: AnyPublisher<InfoBanner.Info?, Never> { get }
var emptyStateTextPublisher: AnyPublisher<String?, Never> { get }
var state: TableDataState<Section, TableItem> { get }
var footerView: AnyPublisher<UIView?, Never> { get }
var footerButtonInfo: AnyPublisher<SessionButton.Info?, Never> { get }
// MARK: - Functions
func canEditRow(at indexPath: IndexPath) -> Bool
func leadingSwipeActionsConfiguration(forRowAt indexPath: IndexPath, in tableView: UITableView, of viewController: UIViewController) -> UISwipeActionsConfiguration?
func trailingSwipeActionsConfiguration(forRowAt indexPath: IndexPath, in tableView: UITableView, of viewController: UIViewController) -> UISwipeActionsConfiguration?
@MainActor func onAppear(targetViewController: BaseVC)
}
extension SessionTableViewModel {
var searchable: Bool { false }
var subtitle: String? { nil }
var initialLoadMessage: String? { nil }
var cellType: SessionTableViewCellType { .general }
var bannerInfo: AnyPublisher<InfoBanner.Info?, Never> { Just(nil).eraseToAnyPublisher() }
var emptyStateTextPublisher: AnyPublisher<String?, Never> { Just(nil).eraseToAnyPublisher() }
var tableData: [SectionModel] { state.tableData }
var footerView: AnyPublisher<UIView?, Never> { Just(nil).eraseToAnyPublisher() }
var footerButtonInfo: AnyPublisher<SessionButton.Info?, Never> { Just(nil).eraseToAnyPublisher() }
// MARK: - Functions
func updateTableData(_ updatedData: [SectionModel]) { state.updateTableData(updatedData) }
func canEditRow(at indexPath: IndexPath) -> Bool { false }
func leadingSwipeActionsConfiguration(forRowAt indexPath: IndexPath, in tableView: UITableView, of viewController: UIViewController) -> UISwipeActionsConfiguration? { nil }
func trailingSwipeActionsConfiguration(forRowAt indexPath: IndexPath, in tableView: UITableView, of viewController: UIViewController) -> UISwipeActionsConfiguration? { nil }
func onAppear(targetViewController: BaseVC) { }
}
// MARK: - SessionTableViewCellType
enum SessionTableViewCellType: CaseIterable {
case general
case fullConversation
var viewType: UITableViewCell.Type {
switch self {
case .general: return SessionCell.self
case .fullConversation: return FullConversationCell.self
}
}
}