From 66500e42b59107f4c211aea552c2b8f00bf50637 Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Fri, 6 Sep 2024 17:55:22 +0200 Subject: [PATCH] Error management for meeting scheduling: unreachable network, missing subject/participant, fail to send some or all ICS invitations --- .../Viewmodel/AccountLoginViewModel.swift | 2 +- Linphone/UI/Main/Fragments/ToastView.swift | 16 +++++++- .../Meetings/ViewModel/MeetingViewModel.swift | 39 ++++++++++++++----- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/Linphone/UI/Assistant/Viewmodel/AccountLoginViewModel.swift b/Linphone/UI/Assistant/Viewmodel/AccountLoginViewModel.swift index 7b0e9a1e3..822236ef1 100644 --- a/Linphone/UI/Assistant/Viewmodel/AccountLoginViewModel.swift +++ b/Linphone/UI/Assistant/Viewmodel/AccountLoginViewModel.swift @@ -37,7 +37,7 @@ class AccountLoginViewModel: ObservableObject { guard self.coreContext.networkStatusIsConnected else { DispatchQueue.main.async { self.coreContext.loggingInProgress = false - ToastViewModel.shared.toastMessage = "Registration_failed_no_network" + ToastViewModel.shared.toastMessage = "Unavailable_network" ToastViewModel.shared.displayToast = true } return diff --git a/Linphone/UI/Main/Fragments/ToastView.swift b/Linphone/UI/Main/Fragments/ToastView.swift index 24a0c551b..de4886ef6 100644 --- a/Linphone/UI/Main/Fragments/ToastView.swift +++ b/Linphone/UI/Main/Fragments/ToastView.swift @@ -129,7 +129,7 @@ struct ToastView: View { .default_text_style(styleSize: 15) .padding(8) - case "Registration_failed_no_network": + case "Unavailable_network": Text("Could not reach network") .multilineTextAlignment(.center) .foregroundStyle(Color.redDanger500) @@ -253,6 +253,20 @@ struct ToastView: View { .default_text_style(styleSize: 15) .padding(8) + case "Failed_meeting_invitations_not_sent": + Text("Could not send ICS invitations to meeting to any participant") + .multilineTextAlignment(.center) + .foregroundStyle(Color.redDanger500) + .default_text_style(styleSize: 15) + .padding(8) + + case "Failed_no_subject_or_participant": + Text("A subject and at least one participant is required to create a meeting") + .multilineTextAlignment(.center) + .foregroundStyle(Color.redDanger500) + .default_text_style(styleSize: 15) + .padding(8) + default: Text("Error") .multilineTextAlignment(.center) diff --git a/Linphone/UI/Main/Meetings/ViewModel/MeetingViewModel.swift b/Linphone/UI/Main/Meetings/ViewModel/MeetingViewModel.swift index e5d31b496..41ba92152 100644 --- a/Linphone/UI/Main/Meetings/ViewModel/MeetingViewModel.swift +++ b/Linphone/UI/Main/Meetings/ViewModel/MeetingViewModel.swift @@ -216,13 +216,23 @@ class MeetingViewModel: ObservableObject { Log.info("\(MeetingViewModel.TAG) All invitations have been sent") } else if cbVal.failedInvitations.count == self.participants.count { Log.error("\(MeetingViewModel.TAG) No invitation sent!") - // TODO: show error toast - } else { - Log.warn("\(MeetingViewModel.TAG) \(cbVal.failedInvitations.count) invitations couldn't have been sent for:") - for failInv in cbVal.failedInvitations { - Log.warn(failInv.asStringUriOnly()) + DispatchQueue.main.async { + ToastViewModel.shared.toastMessage = "Failed_meeting_invitations_not_sent" + ToastViewModel.shared.displayToast = true + } + } else { + var failInvList = "" + for failInv in cbVal.failedInvitations { + if !failInvList.isEmpty { + failInvList += ", " + } + failInvList.append(failInv.asStringUriOnly()) + } + Log.warn("\(MeetingViewModel.TAG) \(cbVal.failedInvitations.count) invitations couldn't have been sent to: \(failInvList)") + DispatchQueue.main.async { + ToastViewModel.shared.toastMessage = "Error: \(cbVal.failedInvitations.count) invitations couldn't be sent to \(failInvList)" + ToastViewModel.shared.displayToast = true } - // TODO: show error toast } DispatchQueue.main.async { @@ -233,13 +243,24 @@ class MeetingViewModel: ObservableObject { } func schedule() { - if subject.isEmpty || participants.isEmpty { + guard !subject.isEmpty && participants.isEmpty else { Log.error("\(MeetingViewModel.TAG) Either no subject was set or no participant was selected, can't schedule meeting.") - // TODO: show red toast + DispatchQueue.main.async { + ToastViewModel.shared.toastMessage = "Failed_no_subject_or_participant" + ToastViewModel.shared.displayToast = true + } return } - operationInProgress = true + guard CoreContext.shared.networkStatusIsConnected else { + DispatchQueue.main.async { + ToastViewModel.shared.toastMessage = "Unavailable_network" + ToastViewModel.shared.displayToast = true + } + return + } + + operationInProgress = true CoreContext.shared.doOnCoreQueue { core in Log.info("\(MeetingViewModel.TAG) Scheduling \(self.isBroadcastSelected ? "broadcast" : "meeting")")