Enable phone number calls in contact details

This commit is contained in:
Benoit Martins 2025-10-30 10:59:46 +01:00
parent 8cd322ff0e
commit bb4134ede0
2 changed files with 81 additions and 43 deletions

View file

@ -81,6 +81,7 @@ struct ContactInnerActionsFragment: View {
.lineLimit(1) .lineLimit(1)
.fixedSize(horizontal: false, vertical: true) .fixedSize(horizontal: false, vertical: true)
} }
Spacer() Spacer()
Image("phone") Image("phone")
@ -95,13 +96,13 @@ struct ContactInnerActionsFragment: View {
} }
.background(.white) .background(.white)
.onTapGesture { .onTapGesture {
do { CoreContext.shared.doOnCoreQueue { core in
let address = try Factory.Instance.createAddress(addr: contactAvatarModel.addresses[index]) do {
withAnimation { let address = try Factory.Instance.createAddress(addr: contactAvatarModel.addresses[index])
telecomManager.doCallOrJoinConf(address: address) telecomManager.doCallOrJoinConf(address: address)
} catch {
Log.error("[ContactInnerActionsFragment] unable to create address for a new outgoing call : \(contactAvatarModel.addresses[index]) \(error) ")
} }
} catch {
Log.error("[ContactInnerActionsFragment] unable to create address for a new outgoing call : \(contactAvatarModel.addresses[index]) \(error) ")
} }
} }
.onLongPressGesture(minimumDuration: 0.2) { .onLongPressGesture(minimumDuration: 0.2) {
@ -139,12 +140,28 @@ struct ContactInnerActionsFragment: View {
.lineLimit(1) .lineLimit(1)
.fixedSize(horizontal: false, vertical: true) .fixedSize(horizontal: false, vertical: true)
} }
Spacer() Spacer()
Image("phone")
.renderingMode(.template)
.resizable()
.foregroundStyle(Color.grayMain2c600)
.frame(width: 25, height: 25)
.padding(.all, 10)
} }
.padding(.vertical, 15) .padding(.vertical, 15)
.padding(.horizontal, 20) .padding(.horizontal, 20)
} }
.background(.white) .background(.white)
.onTapGesture {
CoreContext.shared.doOnCoreQueue { core in
let address = core.interpretUrl(url: contactAvatarModel.phoneNumbersWithLabel[index].phoneNumber, applyInternationalPrefix: true)
if address != nil {
TelecomManager.shared.doCallOrJoinConf(address: address!)
}
}
}
.onLongPressGesture(minimumDuration: 0.2) { .onLongPressGesture(minimumDuration: 0.2) {
contactsListViewModel.stringToCopy = entry.phoneNumber contactsListViewModel.stringToCopy = entry.phoneNumber
showingSheet.toggle() showingSheet.toggle()

View file

@ -144,16 +144,24 @@ struct ContactInnerFragment: View {
Spacer() Spacer()
Button(action: { Button(action: {
if contactAvatarModel.addresses.count <= 1 { CoreContext.shared.doOnCoreQueue { core in
do { if contactAvatarModel.addresses.count == 1 {
let address = try Factory.Instance.createAddress(addr: contactAvatarModel.address) do {
telecomManager.doCallOrJoinConf(address: address, isVideo: false) let address = try Factory.Instance.createAddress(addr: contactAvatarModel.address)
} catch { telecomManager.doCallOrJoinConf(address: address, isVideo: false)
Log.error("[ContactInnerFragment] unable to create address for a new outgoing call : \(contactAvatarModel.address) \(error) ") } catch {
Log.error("[ContactInnerFragment] unable to create address for a new outgoing call : \(contactAvatarModel.address) \(error) ")
}
} else if contactAvatarModel.addresses.count < 1 && contactAvatarModel.phoneNumbersWithLabel.count == 1 {
if let firstPhoneNumbersWithLabel = contactAvatarModel.phoneNumbersWithLabel.first, let address = core.interpretUrl(url: firstPhoneNumbersWithLabel.phoneNumber, applyInternationalPrefix: true) {
telecomManager.doCallOrJoinConf(address: address, isVideo: false)
}
} else {
DispatchQueue.main.async {
isShowSipAddressesPopupType = 0
isShowSipAddressesPopup = true
}
} }
} else {
isShowSipAddressesPopupType = 0
isShowSipAddressesPopup = true
} }
}, label: { }, label: {
VStack { VStack {
@ -161,67 +169,81 @@ struct ContactInnerFragment: View {
Image("phone") Image("phone")
.renderingMode(.template) .renderingMode(.template)
.resizable() .resizable()
.foregroundStyle(contactAvatarModel.address.isEmpty ? Color.grayMain2c400 : Color.grayMain2c600) .foregroundStyle(Color.grayMain2c600)
.frame(width: 25, height: 25) .frame(width: 25, height: 25)
} }
.padding(16) .padding(16)
.background(contactAvatarModel.address.isEmpty ? Color.grayMain2c100 : Color.grayMain2c200) .background(Color.grayMain2c200)
.cornerRadius(40) .cornerRadius(40)
Text("contact_call_action") Text("contact_call_action")
.default_text_style(styleSize: 14) .default_text_style(styleSize: 14)
} }
}) })
.disabled(contactAvatarModel.address.isEmpty)
if !CorePreferences.disableChatFeature { if !CorePreferences.disableChatFeature {
Spacer() Spacer()
Button(action: { Button(action: {
if contactAvatarModel.addresses.count <= 1 { CoreContext.shared.doOnCoreQueue { core in
do { if contactAvatarModel.addresses.count == 1 {
let address = try Factory.Instance.createAddress(addr: contactAvatarModel.address) do {
contactsListViewModel.createOneToOneChatRoomWith(remote: address) let address = try Factory.Instance.createAddress(addr: contactAvatarModel.address)
} catch { contactsListViewModel.createOneToOneChatRoomWith(remote: address)
Log.error("[ContactInnerFragment] unable to create address for a new outgoing call : \(contactAvatarModel.address) \(error) ") } catch {
} Log.error("[ContactInnerFragment] unable to create address for a new outgoing call : \(contactAvatarModel.address) \(error) ")
} else { }
isShowSipAddressesPopupType = 1 } else if contactAvatarModel.addresses.count < 1 && contactAvatarModel.phoneNumbersWithLabel.count == 1 {
isShowSipAddressesPopup = true if let firstPhoneNumbersWithLabel = contactAvatarModel.phoneNumbersWithLabel.first, let address = core.interpretUrl(url: firstPhoneNumbersWithLabel.phoneNumber, applyInternationalPrefix: true) {
} contactsListViewModel.createOneToOneChatRoomWith(remote: address)
}
} else {
DispatchQueue.main.async {
isShowSipAddressesPopupType = 1
isShowSipAddressesPopup = true
}
}
}
}, label: { }, label: {
VStack { VStack {
HStack(alignment: .center) { HStack(alignment: .center) {
Image("chat-teardrop-text") Image("chat-teardrop-text")
.renderingMode(.template) .renderingMode(.template)
.resizable() .resizable()
.foregroundStyle(contactAvatarModel.address.isEmpty ? Color.grayMain2c400 : Color.grayMain2c600) .foregroundStyle(Color.grayMain2c600)
.frame(width: 25, height: 25) .frame(width: 25, height: 25)
} }
.padding(16) .padding(16)
.background(contactAvatarModel.address.isEmpty ? Color.grayMain2c100 : Color.grayMain2c200) .background(Color.grayMain2c200)
.cornerRadius(40) .cornerRadius(40)
Text("contact_message_action") Text("contact_message_action")
.default_text_style(styleSize: 14) .default_text_style(styleSize: 14)
} }
}) })
.disabled(contactAvatarModel.address.isEmpty)
} }
Spacer() Spacer()
Button(action: { Button(action: {
if contactAvatarModel.addresses.count <= 1 { CoreContext.shared.doOnCoreQueue { core in
do { if contactAvatarModel.addresses.count == 1 {
let address = try Factory.Instance.createAddress(addr: contactAvatarModel.address) do {
telecomManager.doCallOrJoinConf(address: address, isVideo: true) let address = try Factory.Instance.createAddress(addr: contactAvatarModel.address)
} catch { telecomManager.doCallOrJoinConf(address: address, isVideo: true)
Log.error("[ContactInnerFragment] unable to create address for a new outgoing call : \(contactAvatarModel.address) \(error) ") } catch {
Log.error("[ContactInnerFragment] unable to create address for a new outgoing call : \(contactAvatarModel.address) \(error) ")
}
} else if contactAvatarModel.addresses.count < 1 && contactAvatarModel.phoneNumbersWithLabel.count == 1 {
if let firstPhoneNumbersWithLabel = contactAvatarModel.phoneNumbersWithLabel.first, let address = core.interpretUrl(url: firstPhoneNumbersWithLabel.phoneNumber, applyInternationalPrefix: true) {
telecomManager.doCallOrJoinConf(address: address, isVideo: true)
}
} else {
DispatchQueue.main.async {
isShowSipAddressesPopupType = 2
isShowSipAddressesPopup = true
}
} }
} else {
isShowSipAddressesPopupType = 2
isShowSipAddressesPopup = true
} }
}, label: { }, label: {
VStack { VStack {
@ -229,18 +251,17 @@ struct ContactInnerFragment: View {
Image("video-camera") Image("video-camera")
.renderingMode(.template) .renderingMode(.template)
.resizable() .resizable()
.foregroundStyle(contactAvatarModel.address.isEmpty ? Color.grayMain2c400 : Color.grayMain2c600) .foregroundStyle(Color.grayMain2c600)
.frame(width: 25, height: 25) .frame(width: 25, height: 25)
} }
.padding(16) .padding(16)
.background(contactAvatarModel.address.isEmpty ? Color.grayMain2c100 : Color.grayMain2c200) .background(Color.grayMain2c200)
.cornerRadius(40) .cornerRadius(40)
Text("contact_video_call_action") Text("contact_video_call_action")
.default_text_style(styleSize: 14) .default_text_style(styleSize: 14)
} }
}) })
.disabled(contactAvatarModel.address.isEmpty)
Spacer() Spacer()
} }