mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 17:12:45 +02:00
Load the thread list using server-side sorting and pagination
This commit is contained in:
@@ -162,7 +162,7 @@ final class ThreadListViewController: UIViewController {
|
||||
|
||||
private func renderLoading() {
|
||||
emptyView.isHidden = true
|
||||
threadsTableView.isHidden = true
|
||||
threadsTableView.isHidden = viewModel.numberOfThreads == 0
|
||||
self.activityPresenter.presentActivityIndicator(on: self.view, animated: true)
|
||||
}
|
||||
|
||||
@@ -352,6 +352,10 @@ extension ThreadListViewController: UITableViewDelegate {
|
||||
cell.backgroundColor = theme.backgroundColor
|
||||
cell.selectedBackgroundView = UIView()
|
||||
cell.selectedBackgroundView?.backgroundColor = theme.selectedBackgroundColor
|
||||
|
||||
if indexPath.row == viewModel.numberOfThreads - 1 {
|
||||
viewModel.process(viewAction: .loadData)
|
||||
}
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
|
||||
@@ -29,7 +29,7 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
|
||||
private var threads: [MXThreadProtocol] = []
|
||||
private var eventFormatter: MXKEventFormatter?
|
||||
private var roomState: MXRoomState?
|
||||
|
||||
private var nextBatch: String?
|
||||
private var currentOperation: MXHTTPOperation?
|
||||
private var longPressedThread: MXThreadProtocol?
|
||||
|
||||
@@ -71,6 +71,7 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
|
||||
viewState = .showingFilterTypes
|
||||
case .selectFilterType(let type):
|
||||
selectedFilterType = type
|
||||
resetData()
|
||||
loadData()
|
||||
case .selectThread(let index):
|
||||
selectThread(index)
|
||||
@@ -230,7 +231,15 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
|
||||
)
|
||||
}
|
||||
|
||||
private func resetData() {
|
||||
nextBatch = nil
|
||||
threads = []
|
||||
}
|
||||
|
||||
private func loadData(showLoading: Bool = true) {
|
||||
guard threads.isEmpty || nextBatch != nil else {
|
||||
return
|
||||
}
|
||||
|
||||
if showLoading {
|
||||
viewState = .loading
|
||||
@@ -245,12 +254,12 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
|
||||
onlyParticipated = true
|
||||
}
|
||||
|
||||
session.threadingService.allThreads(inRoom: roomId,
|
||||
onlyParticipated: onlyParticipated) { [weak self] response in
|
||||
session.threadingService.allThreads(inRoom: roomId, from: nextBatch, onlyParticipated: onlyParticipated) { [weak self] response in
|
||||
guard let self = self else { return }
|
||||
switch response {
|
||||
case .success(let threads):
|
||||
self.threads = threads
|
||||
case .success(let value):
|
||||
self.threads = self.threads + value.threads
|
||||
self.nextBatch = value.nextBatch
|
||||
self.threadsLoaded()
|
||||
case .failure(let error):
|
||||
MXLog.error("[ThreadListViewModel] loadData", context: error)
|
||||
|
||||
Reference in New Issue
Block a user