added alert in the action context service and in the RecentsViewController

This commit is contained in:
Mauro Romito
2025-07-24 18:52:36 +02:00
parent 492bc8c2cd
commit a6022e1481
3 changed files with 176 additions and 131 deletions
@@ -132,19 +132,32 @@ class RoomContextActionService: NSObject, RoomContextActionServiceProtocol {
func leaveRoom(promptUser: Bool) {
guard promptUser else {
// Only used for declining an invite
self.leaveRoom()
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)
Task {
if try await room.isLastOwner() {
let alertController = await UIAlertController(title: VectorL10n.error, message: VectorL10n.roomParticipantsLeaveNotAllowedForLastOwnerMsg, preferredStyle: .alert)
await alertController.addAction(UIAlertAction(title: VectorL10n.ok, style: .cancel, handler: nil))
await MainActor.run {
self.delegate?.roomContextActionService(self, presentAlert: alertController)
}
} else {
let title = room.isDirect ? VectorL10n.roomParticipantsLeavePromptTitleForDm : VectorL10n.roomParticipantsLeavePromptTitle
let message = room.isDirect ? VectorL10n.roomParticipantsLeavePromptMsgForDm : VectorL10n.roomParticipantsLeavePromptMsg
let alertController = await UIAlertController(title: title, message: message, preferredStyle: .alert)
await alertController.addAction(UIAlertAction(title: VectorL10n.cancel, style: .cancel, handler: nil))
await alertController.addAction(UIAlertAction(title: VectorL10n.leave, style: .default, handler: { action in
self.leaveRoom()
}))
await MainActor.run {
self.delegate?.roomContextActionService(self, presentAlert: alertController)
}
}
}
}
func joinRoom() {