MESSENGER-4039 new layout - add last admin function

This commit is contained in:
JanNiklas Grabowski
2023-01-25 11:06:00 +00:00
committed by Frank Rotermund
parent 4d55fd8513
commit 73ded73d25
3 changed files with 133 additions and 61 deletions
@@ -140,15 +140,12 @@ class RoomContextActionService: NSObject, RoomContextActionServiceProtocol {
return
}
let title = room.isDirect ? VectorL10n.roomParticipantsLeavePromptTitleForDm : VectorL10n.roomParticipantsLeavePromptTitle
let message = room.isDirect ? VectorL10n.roomParticipantsLeavePromptMsgForDm : VectorL10n.roomParticipantsLeavePromptMsg
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: VectorL10n.cancel, style: .cancel, handler: nil))
alertController.addAction(UIAlertAction(title: VectorL10n.leave, style: .default, handler: { action in
self.leaveRoom()
}))
self.delegate?.roomContextActionService(self, presentAlert: alertController)
// bwi: admins can only leave if there is at least one other admin or the admin is the only member
if BWIBuildSettings.shared.lastAdminIsNotAllowedToLeaveRoom {
self.delegate?.roomContextActionService(self, presentAlert: self.getLeaveAlertController())
} else {
self.delegate?.roomContextActionService(self, presentAlert: self.leaveAlertController)
}
}
func joinRoom() {
@@ -183,4 +180,53 @@ class RoomContextActionService: NSObject, RoomContextActionServiceProtocol {
}
}
}
// MARK: bwi leave room alerts
private lazy var leaveAlertController: UIAlertController = {
var title = self.isRoomDirect ? VectorL10n.roomParticipantsLeavePromptTitleForDm : VectorL10n.roomParticipantsLeavePromptTitle
var message = self.isRoomDirect ? VectorL10n.roomParticipantsLeavePromptMsgForDm : VectorL10n.roomParticipantsLeavePromptMsg
let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)
controller.addAction(UIAlertAction(title: VectorL10n.cancel, style: .cancel, handler: nil))
controller.addAction(UIAlertAction(title: VectorL10n.leave, style: .default, handler: { [weak self] (action) in
guard let self = self else { return }
self.leaveRoom()
}))
controller.mxk_setAccessibilityIdentifier("RoomContextActionServiceAlert")
return controller
}()
private func getLeaveAlertController() -> UIAlertController {
if LeaveRoomHelper.canLeaveRoom(self.session, self.room) {
let title = self.isRoomDirect ? VectorL10n.roomParticipantsLeavePromptTitleForDm : VectorL10n.roomParticipantsLeavePromptTitle
let message = self.isRoomDirect ? VectorL10n.roomParticipantsLeavePromptMsgForDm : VectorL10n.roomParticipantsLeavePromptMsg
let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)
controller.addAction(UIAlertAction(title: VectorL10n.cancel, style: .cancel, handler: nil))
controller.addAction(UIAlertAction(title: VectorL10n.leave, style: .default, handler: { [weak self] (action) in
guard let self = self else { return }
self.leaveRoom()
}))
controller.mxk_setAccessibilityIdentifier("RoomContextActionServiceAlert")
return controller
} else {
return self.doNotLeaveUIAlertController()
}
}
private func doNotLeaveUIAlertController() -> UIAlertController {
let title = VectorL10n.roomParticipantsLeavePromptTitle
let message = BWIL10n.roomParticipantsCantLeavePromptMessage
let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)
controller.addAction(UIAlertAction(title: VectorL10n.cancel, style: .cancel, handler: nil))
controller.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
controller.mxk_setAccessibilityIdentifier("RoomContextActionServiceAlert")
return controller
}
}