implemented in RoomInfoListViewController

This commit is contained in:
Mauro Romito
2025-07-24 17:07:29 +02:00
parent 5301244b7f
commit 492bc8c2cd
6 changed files with 61 additions and 2 deletions
@@ -75,6 +75,17 @@ final class RoomInfoListViewController: UIViewController {
return controller
}()
private lazy var isLastOwnerAlertController: UIAlertController = {
let title = VectorL10n.error
let message = VectorL10n.roomParticipantsLeaveNotAllowedForLastOwnerMsg
let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)
controller.addAction(UIAlertAction(title: VectorL10n.ok, style: .default, handler: nil))
controller.mxk_setAccessibilityIdentifier("RoomSettingsVCLastOwnerAlert")
return controller
}()
private enum RowType {
case `default`
case destructive
@@ -216,7 +227,11 @@ final class RoomInfoListViewController: UIViewController {
VectorL10n.roomParticipantsLeavePromptTitleForDm :
VectorL10n.roomParticipantsLeavePromptTitle
let rowLeave = Row(type: .destructive, icon: Asset.Images.roomActionLeave.image, text: leaveTitle, accessoryType: .none) {
self.present(self.leaveAlertController, animated: true, completion: nil)
if viewData.isLastOwner {
self.present(self.isLastOwnerAlertController, animated: true, completion: nil)
} else {
self.present(self.leaveAlertController, animated: true, completion: nil)
}
}
let sectionLeave = Section(header: nil,
rows: [rowLeave],
@@ -24,4 +24,5 @@ struct RoomInfoListViewData {
let isEncrypted: Bool
let isDirect: Bool
let basicInfoViewData: RoomInfoBasicViewData
let isLastOwner: Bool
}
@@ -26,6 +26,7 @@ final class RoomInfoListViewModel: NSObject, RoomInfoListViewModelType {
private let session: MXSession
private let room: MXRoom
private var isLastOwner = false
// MARK: Public
@@ -51,7 +52,8 @@ final class RoomInfoListViewModel: NSObject, RoomInfoListViewModelType {
return RoomInfoListViewData(numberOfMembers: Int(room.summary.membersCount.joined),
isEncrypted: room.summary.isEncrypted,
isDirect: room.isDirect,
basicInfoViewData: basicInfoViewData)
basicInfoViewData: basicInfoViewData,
isLastOwner: isLastOwner)
}
// MARK: - Setup
@@ -97,6 +99,9 @@ final class RoomInfoListViewModel: NSObject, RoomInfoListViewModelType {
@objc private func roomSummaryUpdated(_ notification: Notification) {
// force update view
self.update(viewState: .loaded(viewData: viewData))
Task {
isLastOwner = (try? await room.isLastOwner()) == true
}
}
private func loadData() {