forked from mirrors/linphone-iphone
Display chat notification when app is on foreground if the message comes from elsewhere that the currently displayed chatroom
This commit is contained in:
parent
cc1bcd1666
commit
efa34110c2
3 changed files with 29 additions and 3 deletions
|
|
@ -22,6 +22,7 @@ import linphonesw
|
|||
import UserNotifications
|
||||
|
||||
let accountTokenNotification = Notification.Name("AccountCreationTokenReceived")
|
||||
var displayedChatroomPeerAddr: String?
|
||||
|
||||
class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
|
||||
|
||||
|
|
@ -81,6 +82,19 @@ class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDele
|
|||
completionHandler()
|
||||
}
|
||||
|
||||
// Display notifications on foreground
|
||||
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
||||
let userInfo = notification.request.content.userInfo
|
||||
Log.info("Received push notification in foreground, payload= \(userInfo)")
|
||||
|
||||
if let callId = userInfo["CallId"] as? String, let peerAddr = userInfo["peer_addr"] as? String, let localAddr = userInfo["local_addr"] as? String {
|
||||
// Only display notification if we're not in the chatroom they come from
|
||||
if displayedChatroomPeerAddr != peerAddr {
|
||||
completionHandler([.banner, .sound])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
Log.info("IOS applicationWillTerminate")
|
||||
CoreContext.shared.doOnCoreQueue(synchronous: true) { core in
|
||||
|
|
|
|||
|
|
@ -1242,9 +1242,9 @@ struct ContentView: View {
|
|||
}
|
||||
|
||||
class NavigationManager: ObservableObject {
|
||||
@Published var selectedCallId: String? = nil
|
||||
@Published var peerAddr: String? = nil
|
||||
@Published var localAddr: String? = nil
|
||||
@Published var selectedCallId: String?
|
||||
@Published var peerAddr: String?
|
||||
@Published var localAddr: String?
|
||||
|
||||
func openChatRoom(callId: String, peerAddr: String, localAddr: String) {
|
||||
self.selectedCallId = callId
|
||||
|
|
|
|||
|
|
@ -69,7 +69,13 @@ struct ConversationFragment: View {
|
|||
.onRotate { newOrientation in
|
||||
orientation = newOrientation
|
||||
}
|
||||
.onAppear() {
|
||||
displayedChatroomPeerAddr = conversationViewModel.displayedConversation?.remoteSipUri
|
||||
Log.info("debugtrace = onAppear: displayedChatroomPeerAddr = \(displayedChatroomPeerAddr)")
|
||||
}
|
||||
.onDisappear {
|
||||
displayedChatroomPeerAddr = nil
|
||||
Log.info("debugtrace = onDisappear: displayedChatroomPeerAddr = nil")
|
||||
conversationViewModel.removeConversationDelegate()
|
||||
}
|
||||
.sheet(isPresented: $conversationViewModel.isShowSelectedMessageToDisplayDetails, onDismiss: {
|
||||
|
|
@ -109,7 +115,13 @@ struct ConversationFragment: View {
|
|||
.onRotate { newOrientation in
|
||||
orientation = newOrientation
|
||||
}
|
||||
.onAppear() {
|
||||
displayedChatroomPeerAddr = conversationViewModel.displayedConversation?.remoteSipUri
|
||||
Log.info("debugtrace = onAppear: displayedChatroomPeerAddr = \(displayedChatroomPeerAddr)")
|
||||
}
|
||||
.onDisappear {
|
||||
displayedChatroomPeerAddr = nil
|
||||
Log.info("debugtrace = onDisappear: displayedChatroomPeerAddr = nil")
|
||||
conversationViewModel.removeConversationDelegate()
|
||||
}
|
||||
.halfSheet(showSheet: $conversationViewModel.isShowSelectedMessageToDisplayDetails) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue