/* * Copyright (c) 2010-2023 Belledonne Communications SARL. * * This file is part of Linphone * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import SwiftUI import UniformTypeIdentifiers import linphonesw // swiftlint:disable type_body_length struct HistoryContactFragment: View { @State private var orientation = UIDevice.current.orientation @ObservedObject var contactsManager = ContactsManager.shared @ObservedObject private var telecomManager = TelecomManager.shared @ObservedObject private var sharedMainViewModel = SharedMainViewModel.shared @ObservedObject var contactAvatarModel: ContactAvatarModel @ObservedObject var historyViewModel: HistoryViewModel @ObservedObject var historyListViewModel: HistoryListViewModel @ObservedObject var contactViewModel: ContactViewModel @ObservedObject var editContactViewModel: EditContactViewModel @State var isMenuOpen = false @Binding var isShowDeleteAllHistoryPopup: Bool @Binding var isShowEditContactFragment: Bool @Binding var indexPage: Int var body: some View { NavigationView { if historyViewModel.displayedCall != nil { VStack(spacing: 1) { Rectangle() .foregroundColor(Color.orangeMain500) .edgesIgnoringSafeArea(.top) .frame(height: 0) HStack { if !(orientation == .landscapeLeft || orientation == .landscapeRight || UIScreen.main.bounds.size.width > UIScreen.main.bounds.size.height) { Image("caret-left") .renderingMode(.template) .resizable() .foregroundStyle(Color.orangeMain500) .frame(width: 25, height: 25, alignment: .leading) .padding(.all, 10) .padding(.top, 2) .padding(.leading, -10) .onTapGesture { withAnimation { historyViewModel.displayedCall = nil } } } Text("Call history") .default_text_style_orange_800(styleSize: 20) Spacer() Menu { if historyViewModel.displayedCall != nil && !historyViewModel.displayedCall!.isConf { Button { isMenuOpen = false if historyViewModel.displayedCall != nil && historyViewModel.displayedCall!.addressFriend != nil { let addressCall = historyViewModel.displayedCall!.addressFriend!.address if addressCall != nil { let friendIndex = contactsManager.lastSearch.firstIndex( where: {$0.friend!.addresses.contains(where: {$0.asStringUriOnly() == addressCall!.asStringUriOnly()})}) if friendIndex != nil { withAnimation { historyViewModel.displayedCall = nil indexPage = 0 contactViewModel.indexDisplayedFriend = friendIndex } } } } else { withAnimation { historyViewModel.displayedCall = nil indexPage = 0 isShowEditContactFragment.toggle() editContactViewModel.sipAddresses.removeAll() editContactViewModel.sipAddresses.append(String(historyViewModel.displayedCall?.address.dropFirst(4) ?? "")) editContactViewModel.sipAddresses.append("") } } } label: { HStack { Text(historyViewModel.displayedCall!.addressFriend != nil ? "See contact" : "Add to contacts") Spacer() Image(historyViewModel.displayedCall!.addressFriend != nil ? "user-circle" : "plus-circle") .resizable() .frame(width: 25, height: 25, alignment: .leading) .padding(.all, 10) } } } Button { isMenuOpen = false if historyViewModel.displayedCall != nil && historyViewModel.displayedCall!.isOutgoing { UIPasteboard.general.setValue( historyViewModel.displayedCall!.address.dropFirst(4), forPasteboardType: UTType.plainText.identifier ) } else { UIPasteboard.general.setValue( historyViewModel.displayedCall!.address.dropFirst(4), forPasteboardType: UTType.plainText.identifier ) } ToastViewModel.shared.toastMessage = "Success_address_copied_into_clipboard" ToastViewModel.shared.displayToast.toggle() } label: { HStack { Text("Copy SIP address") Spacer() Image("copy") .resizable() .frame(width: 25, height: 25, alignment: .leading) .padding(.all, 10) } } Button(role: .destructive) { isMenuOpen = false if historyViewModel.displayedCall != nil && historyViewModel.displayedCall!.isOutgoing { historyListViewModel.callLogsAddressToDelete = historyViewModel.displayedCall!.address } else { historyListViewModel.callLogsAddressToDelete = historyViewModel.displayedCall!.address } isShowDeleteAllHistoryPopup.toggle() } label: { HStack { Text("Delete history") Spacer() Image("trash-simple-red") .resizable() .frame(width: 25, height: 25, alignment: .leading) .padding(.all, 10) } } } label: { Image("dots-three-vertical") .renderingMode(.template) .resizable() .foregroundStyle(Color.orangeMain500) .frame(width: 25, height: 25, alignment: .leading) .padding(.all, 10) } .padding(.leading) .onTapGesture { isMenuOpen = true } } .frame(maxWidth: .infinity) .frame(height: 50) .padding(.horizontal) .padding(.bottom, 4) .background(.white) ScrollView { VStack(spacing: 0) { VStack(spacing: 0) { if #unavailable(iOS 16.0) { Rectangle() .foregroundColor(Color.gray100) .frame(height: 7) } VStack(spacing: 0) { if historyViewModel.displayedCall != nil && !historyViewModel.displayedCall!.isConf { if historyViewModel.displayedCall!.avatarModel != nil { Avatar(contactAvatarModel: historyViewModel.displayedCall!.avatarModel!, avatarSize: 100) } Text(historyViewModel.displayedCall!.addressName) .foregroundStyle(Color.grayMain2c700) .multilineTextAlignment(.center) .default_text_style(styleSize: 14) .frame(maxWidth: .infinity) .padding(.top, 10) Text(historyViewModel.displayedCall!.address) .foregroundStyle(Color.grayMain2c700) .multilineTextAlignment(.center) .default_text_style(styleSize: 14) .frame(maxWidth: .infinity) .padding(.top, 5) if historyViewModel.displayedCall!.avatarModel != nil { Text(contactAvatarModel.lastPresenceInfo) .foregroundStyle(contactAvatarModel.lastPresenceInfo == "Online" ? Color.greenSuccess500 : Color.orangeWarning600) .multilineTextAlignment(.center) .default_text_style_300(styleSize: 12) .frame(maxWidth: .infinity) .frame(height: 20) .padding(.top, 5) } else { Text("") .multilineTextAlignment(.center) .default_text_style_300(styleSize: 12) .frame(maxWidth: .infinity) .frame(height: 20) } } else { VStack { Image("users-three-square") .renderingMode(.template) .resizable() .frame(width: 60, height: 60) .foregroundStyle(Color.grayMain2c600) } .frame(width: 100, height: 100) .background(Color.grayMain2c200) .clipShape(Circle()) Text(historyViewModel.displayedCall!.subject) .foregroundStyle(Color.grayMain2c700) .multilineTextAlignment(.center) .default_text_style(styleSize: 14) .frame(maxWidth: .infinity) .padding(.top, 10) } } .frame(minHeight: 150) .frame(maxWidth: .infinity) .padding(.top, 10) .padding(.bottom, 2) .background(Color.gray100) HStack { Spacer() if historyViewModel.displayedCall != nil && !historyViewModel.displayedCall!.isConf { Button(action: { telecomManager.doCallOrJoinConf(address: historyViewModel.displayedCall!.addressLinphone) }, label: { VStack { HStack(alignment: .center) { Image("phone") .renderingMode(.template) .resizable() .foregroundStyle(Color.grayMain2c600) .frame(width: 25, height: 25) } .padding(16) .background(Color.grayMain2c200) .cornerRadius(40) Text("Appel") .default_text_style(styleSize: 14) .frame(minWidth: 80) } }) Spacer() Button(action: { contactViewModel.createOneToOneChatRoomWith(remote: historyViewModel.displayedCall!.addressLinphone) }, label: { VStack { HStack(alignment: .center) { Image("chat-teardrop-text") .renderingMode(.template) .resizable() .foregroundStyle(Color.grayMain2c600) .frame(width: 25, height: 25) } .padding(16) .background(Color.grayMain2c200) .cornerRadius(40) Text("Message") .default_text_style(styleSize: 14) .frame(minWidth: 80) } }) Spacer() Button(action: { telecomManager.doCallOrJoinConf(address: historyViewModel.displayedCall!.addressLinphone, isVideo: true) }, label: { VStack { HStack(alignment: .center) { Image("video-camera") .renderingMode(.template) .resizable() .foregroundStyle(Color.grayMain2c600) .frame(width: 25, height: 25) } .padding(16) .background(Color.grayMain2c200) .cornerRadius(40) Text("Video Call") .default_text_style(styleSize: 14) .frame(minWidth: 80) } }) } else { Button(action: { withAnimation { if historyViewModel.displayedCall != nil && historyViewModel.displayedCall!.address.hasPrefix("sip:conference-focus@sip.linphone.org") { do { let meetingAddress = try Factory.Instance.createAddress(addr: historyViewModel.displayedCall!.address) telecomManager.meetingWaitingRoomDisplayed = true telecomManager.meetingWaitingRoomSelected = meetingAddress } catch {} } else { telecomManager.doCallOrJoinConf(address: historyViewModel.displayedCall!.addressLinphone) } } }, label: { VStack { HStack(alignment: .center) { Image("users-three-square") .renderingMode(.template) .resizable() .foregroundStyle(Color.grayMain2c600) .frame(width: 25, height: 25) } .padding(16) .background(Color.grayMain2c200) .cornerRadius(40) Text("Rejoindre") .default_text_style(styleSize: 14) .frame(minWidth: 80) } }) } Spacer() } .padding(.top, 20) .padding(.bottom, 10) .frame(maxWidth: .infinity) .background(Color.gray100) VStack(spacing: 0) { let addressFriend = historyViewModel.displayedCall != nil ? historyViewModel.displayedCall!.address : nil let callLogsFilter = historyListViewModel.callLogs.filter({ $0.address == addressFriend}) ForEach(0..