diff --git a/Linphone/Localizable/en.lproj/Localizable.strings b/Linphone/Localizable/en.lproj/Localizable.strings index 6c17e6d19..412afea03 100644 --- a/Linphone/Localizable/en.lproj/Localizable.strings +++ b/Linphone/Localizable/en.lproj/Localizable.strings @@ -268,6 +268,24 @@ "conversation_info_participant_is_admin_label" = "Admin"; "conversation_info_participants_list_title" = "Group members (%d)"; "conversation_invalid_participant_due_to_security_mode_toast" = "Can't create conversation with a participant not on the same domain due to security restrictions!"; + + +"conversation_info_dialog_delete_all_call_logs_title" = "Do you really want to delete all messages?"; +"conversation_info_dialog_delete_all_message" = "All messages will be removed from the history"; +"conversation_info_delete_history_confirm" = "Delete"; +"conversation_info_history_deleted_toast" = "History has been successfully deleted"; + +"conversation_info_dialog_leave_chatroom_title" = "Leave this conversation?"; +"conversation_info_dialog_leave_chatroom_message" = "You will leave this conversation. You can be added again later."; +"conversation_info_leave_chatroom_confirm" = "Leave"; +"conversation_info_left_chatroom_toast" = "You have left the conversation"; + +"conversation_info_dialog_delete_chatroom_title" = "Delete this conversation?"; +"conversation_info_dialog_delete_chatroom_message" = "This conversation will be permanently deleted for all participants."; +"conversation_info_delete_chatroom_confirm" = "Delete"; +"conversation_info_chatroom_deleted_toast" = "Conversation deleted"; + + "conversation_menu_search_in_messages" = "Search"; "conversation_menu_go_to_info" = "Conversation info"; "conversation_menu_configure_ephemeral_messages" = "Ephemeral messages"; diff --git a/Linphone/Localizable/fr.lproj/Localizable.strings b/Linphone/Localizable/fr.lproj/Localizable.strings index a8a7e3c9a..95faf2dbc 100644 --- a/Linphone/Localizable/fr.lproj/Localizable.strings +++ b/Linphone/Localizable/fr.lproj/Localizable.strings @@ -265,6 +265,24 @@ "conversation_info_participant_is_admin_label" = "Administrateur"; "conversation_info_participants_list_title" = "Participants (%d)"; "conversation_invalid_participant_due_to_security_mode_toast" = "Pour des raisons de sécurité, la création d'une conversation avec un participant d'un domaine tiers est désactivé."; + + +"conversation_info_dialog_delete_all_call_logs_title" = "Supprimer l'historique ?"; +"conversation_info_dialog_delete_all_message" = "Tous les messages de cette conversation seront supprimés."; +"conversation_info_delete_history_confirm" = "Supprimer"; +"conversation_info_history_deleted_toast" = "Historique supprimé"; + +"conversation_info_dialog_leave_chatroom_title" = "Quitter la conversation ?"; +"conversation_info_dialog_leave_chatroom_message" = "Vous allez quitter cette conversation. Vous pourrez y être ajouté à nouveau plus tard."; +"conversation_info_leave_chatroom_confirm" = "Quitter"; +"conversation_info_left_chatroom_toast" = "Vous avez quitté la conversation"; + +"conversation_info_dialog_delete_chatroom_title" = "Supprimer la conversation ?"; +"conversation_info_dialog_delete_chatroom_message" = "Cette conversation sera définitivement supprimée pour tous les participants."; +"conversation_info_delete_chatroom_confirm" = "Supprimer"; +"conversation_info_chatroom_deleted_toast" = "Conversation supprimée"; + + "conversation_menu_search_in_messages" = "Chercher"; "conversation_menu_go_to_info" = "Informations"; "conversation_menu_configure_ephemeral_messages" = "Messages éphémères"; diff --git a/Linphone/UI/Main/ContentView.swift b/Linphone/UI/Main/ContentView.swift index a9feaf894..4fbf81ad7 100644 --- a/Linphone/UI/Main/ContentView.swift +++ b/Linphone/UI/Main/ContentView.swift @@ -91,6 +91,10 @@ struct ContentView: View { @State var isShowUpdatePasswordPopup: Bool = false @State var passwordUpdateAddress: String = "" + @State var showLeaveConversationPopup: Bool = false + @State var showDeleteConversationPopup: Bool = false + @State var showDeleteConversationHistoryPopup: Bool = false + var body: some View { GeometryReader { geometry in VStack(spacing: 0) { @@ -1337,6 +1341,7 @@ struct ContentView: View { if let historyListVM = historyListViewModel { historyListVM.removeCallLogs() } + self.isShowDeleteAllHistoryPopup.toggle() sharedMainViewModel.displayedCall = nil @@ -1357,6 +1362,90 @@ struct ContentView: View { } } + if showLeaveConversationPopup { + PopupView( + isShowPopup: $isShowDeleteContactPopup, + title: Text("conversation_info_dialog_leave_chatroom_title"), + content: Text("conversation_info_dialog_leave_chatroom_message"), + titleFirstButton: nil, + actionFirstButton: {}, + titleSecondButton: Text("conversation_info_leave_chatroom_confirm"), + actionSecondButton: { + if let conversationsListVM = conversationsListViewModel, let targetConversation = conversationsListVM.targetConversation { + targetConversation.deleteHistory() + } + self.isShowDeleteAllHistoryPopup.toggle() + }, + titleThirdButton: Text("dialog_cancel"), + actionThirdButton: { + self.showLeaveConversationPopup.toggle() + } + ) + .background(.black.opacity(0.65)) + .zIndex(3) + .onTapGesture { + self.showLeaveConversationPopup.toggle() + } + } + + if showDeleteConversationPopup { + PopupView( + isShowPopup: $isShowDeleteContactPopup, + title: Text("conversation_info_dialog_delete_chatroom_title"), + content: Text("conversation_info_dialog_delete_chatroom_message"), + titleFirstButton: nil, + actionFirstButton: {}, + titleSecondButton: Text("conversation_info_delete_chatroom_confirm"), + actionSecondButton: { + if let historyListVM = historyListViewModel { + historyListVM.removeCallLogs() + } + self.isShowDeleteAllHistoryPopup.toggle() + sharedMainViewModel.displayedCall = nil + + ToastViewModel.shared.show("Success_remove_call_logs") + }, + titleThirdButton: Text("dialog_cancel"), + actionThirdButton: { + self.showDeleteConversationPopup.toggle() + } + ) + .background(.black.opacity(0.65)) + .zIndex(3) + .onTapGesture { + self.showDeleteConversationPopup.toggle() + } + } + + if showDeleteConversationHistoryPopup { + PopupView( + isShowPopup: $isShowDeleteContactPopup, + title: Text("conversation_info_dialog_delete_all_call_logs_title"), + content: Text("conversation_info_dialog_delete_all_message"), + titleFirstButton: nil, + actionFirstButton: {}, + titleSecondButton: Text("conversation_info_delete_history_confirm"), + actionSecondButton: { + if let historyListVM = historyListViewModel { + historyListVM.removeCallLogs() + } + self.isShowDeleteAllHistoryPopup.toggle() + sharedMainViewModel.displayedCall = nil + + ToastViewModel.shared.show("Success_remove_call_logs") + }, + titleThirdButton: Text("dialog_cancel"), + actionThirdButton: { + self.showDeleteConversationHistoryPopup.toggle() + } + ) + .background(.black.opacity(0.65)) + .zIndex(3) + .onTapGesture { + self.showDeleteConversationHistoryPopup.toggle() + } + } + if isShowDismissPopup { PopupView( isShowPopup: $isShowDismissPopup, diff --git a/Linphone/UI/Main/Conversations/Model/ConversationModel.swift b/Linphone/UI/Main/Conversations/Model/ConversationModel.swift index 8bdd45197..56ecb1f55 100644 --- a/Linphone/UI/Main/Conversations/Model/ConversationModel.swift +++ b/Linphone/UI/Main/Conversations/Model/ConversationModel.swift @@ -414,15 +414,35 @@ class ConversationModel: ObservableObject, Identifiable { func deleteChatRoom() { CoreContext.shared.doOnCoreQueue { core in + Log.info("\(ConversationModel.TAG) Deleting conversation \(LinphoneUtils.getConversationId(chatRoom: self.chatRoom))") core.deleteChatRoom(chatRoom: self.chatRoom) - } + + DispatchQueue.main.async { + ToastViewModel.shared.show("Success_remove_call_logs") + } + } } - - + func deleteHistory() { - CoreContext.shared.doOnCoreQueue { core in - Log.info("\(ConversationModel.TAG) Cleaning conversation \(LinphoneUtils.getConversationId(chatRoom: self.chatRoom)) history") + CoreContext.shared.doOnCoreQueue { _ in + Log.info("\(ConversationModel.TAG) Deleting history for conversation \(LinphoneUtils.getConversationId(chatRoom: self.chatRoom))") self.chatRoom.deleteHistory() + + DispatchQueue.main.async { + ToastViewModel.shared.show("Success_remove_call_logs") + } + } + } + + func leaveChatRoom() { + CoreContext.shared.doOnCoreQueue { _ in + Log.info("\(ConversationModel.TAG) Leaving conversation \(LinphoneUtils.getConversationId(chatRoom: self.chatRoom))") + self.chatRoom.leave() + + DispatchQueue.main.async { + self.isReadOnly = true + ToastViewModel.shared.show("Success_remove_call_logs") + } } } } diff --git a/Linphone/UI/Main/Conversations/ViewModel/ConversationsListViewModel.swift b/Linphone/UI/Main/Conversations/ViewModel/ConversationsListViewModel.swift index f78fd9bcf..9ec7e7b3d 100644 --- a/Linphone/UI/Main/Conversations/ViewModel/ConversationsListViewModel.swift +++ b/Linphone/UI/Main/Conversations/ViewModel/ConversationsListViewModel.swift @@ -37,6 +37,7 @@ class ConversationsListViewModel: ObservableObject { @Published var displayedConversation: ConversationModel? @Published var conversationsList: [ConversationModel] = [] + var targetConversation: ConversationModel? var selectedConversation: ConversationModel? private var chatRoomDelegate: ChatRoomDelegate?