Toast display when user records call

This commit is contained in:
Benoit Martins 2024-01-09 12:21:07 +01:00 committed by QuentinArguillere
parent 96bdf5150c
commit 8469e8583e
2 changed files with 40 additions and 11 deletions

View file

@ -342,12 +342,38 @@ class TelecomManager: ObservableObject {
isRemoteRecording = call.remoteParams?.isRecording ?? false isRemoteRecording = call.remoteParams?.isRecording ?? false
if isRemoteRecording && ToastViewModel.shared.toastMessage == "" { if isRemoteRecording && ToastViewModel.shared.toastMessage.isEmpty {
ToastViewModel.shared.toastMessage = "\(call.remoteAddress) is recording" DispatchQueue.main.async {
ToastViewModel.shared.displayToast.toggle() var displayName = ""
let friend = ContactsManager.shared.getFriendWithAddress(address: call.remoteAddress!)
if friend != nil && friend!.address != nil && friend!.address!.displayName != nil {
displayName = friend!.address!.displayName!
} else {
if call.remoteAddress!.displayName != nil {
displayName = call.remoteAddress!.displayName!
} else if call.remoteAddress!.username != nil {
displayName = call.remoteAddress!.username!
}
}
ToastViewModel.shared.toastMessage = "\(displayName) is recording"
ToastViewModel.shared.displayToast = true
}
Log.info("[Call] Call is recording by \(call.remoteAddress)") Log.info("[Call] Call is recording by \(call.remoteAddress!.asStringUriOnly())")
}
if !isRemoteRecording && ToastViewModel.shared.toastMessage.contains("is recording") {
DispatchQueue.main.async {
withAnimation {
ToastViewModel.shared.toastMessage = ""
ToastViewModel.shared.displayToast = false
}
}
Log.info("[Call] Call is recording Stop recording by \(call.remoteAddress!.asStringUriOnly())")
} }
if call.userData == nil { if call.userData == nil {

View file

@ -100,19 +100,22 @@ struct ToastView: View {
.stroke(toastViewModel.toastMessage.contains("Success") ? Color.greenSuccess500 : Color.redDanger500, lineWidth: 1) .stroke(toastViewModel.toastMessage.contains("Success") ? Color.greenSuccess500 : Color.redDanger500, lineWidth: 1)
) )
.onTapGesture { .onTapGesture {
withAnimation { if !toastViewModel.toastMessage.contains("is recording") {
toastViewModel.toastMessage = ""
toastViewModel.displayToast = false
}
}
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
withAnimation { withAnimation {
toastViewModel.toastMessage = "" toastViewModel.toastMessage = ""
toastViewModel.displayToast = false toastViewModel.displayToast = false
} }
} }
} }
.onAppear {
if !toastViewModel.toastMessage.contains("is recording") {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
withAnimation {
toastViewModel.toastMessage = ""
toastViewModel.displayToast = false
}
}
} }
Spacer() Spacer()
} }