Commit f8a33d0f authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

fix: handle notifications actions

This patch switch current account to match account from notifications
when user open app from notification.

Change-Id: Ie926e4dfcb2be9dc6f7fc49b2e9d6828de52a625
parent 918d99fe
......@@ -354,6 +354,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}
func handleNotificationActions(data: [AnyHashable: Any], responseIdentifier: String) {
guard let currentAccount = self.accountService
.currentAccount,
let accountId = data[NotificationUserInfoKeys.accountID.rawValue] as? String,
let account = self.accountService.getAccount(fromAccountId: accountId) else { return }
if currentAccount.id != accountId && responseIdentifier != CallAcition.refuse.rawValue {
self.accountService.currentAccount = account
}
// if notification contains messageContent this is message notification
if let participantID = data[NotificationUserInfoKeys.participantID.rawValue] as? String {
self.appCoordinator.openConversation(participantID: participantID)
......
......@@ -143,7 +143,7 @@ class ContactRequestsViewModel: Stateable, ViewModel {
return
}
guard let conversation = self.conversationService.findConversation(withRingId: uri, withAccountId: account.id) else {
guard let conversation = self.conversationService.findConversation(withUri: uri, withAccountId: account.id) else {
return
}
conversationViewModel.conversation = Variable<ConversationModel>(conversation)
......
......@@ -188,7 +188,10 @@ class ConversationsCoordinator: Coordinator, StateableResponsive, ConversationNa
guard let account = accountService.currentAccount else {
return
}
guard let conversation = self.conversationService.findConversation(withRingId: participantId, withAccountId: account.id) else {
guard let uriString = JamiURI(schema: URIType.ring, infoHach: participantId).uriString else {
return
}
guard let conversation = self.conversationService.findConversation(withUri: uriString, withAccountId: account.id) else {
return
}
conversationViewModel.conversation = Variable<ConversationModel>(conversation)
......@@ -243,6 +246,7 @@ class ConversationsCoordinator: Coordinator, StateableResponsive, ConversationNa
var data = [String: String]()
data [NotificationUserInfoKeys.name.rawValue] = call.displayName
data [NotificationUserInfoKeys.callID.rawValue] = call.callId
data [NotificationUserInfoKeys.accountID.rawValue] = call.accountId
let helper = LocalNotificationsHelper()
helper.presentCallNotification(data: data, callService: self.callService)
}
......
......@@ -154,6 +154,7 @@ class ConversationsManager: MessagesAdapterDelegate {
var data = [String: String]()
data [NotificationUserInfoKeys.messageContent.rawValue] = content
data [NotificationUserInfoKeys.participantID.rawValue] = peerUri
data [NotificationUserInfoKeys.accountID.rawValue] = accountId
if let name = peerName {
data [NotificationUserInfoKeys.name.rawValue] = name
self.notificationHandler.presentMessageNotification(data: data)
......
......@@ -190,11 +190,11 @@ class ConversationsService {
})
}
func findConversation(withRingId ringId: String,
func findConversation(withUri uri: String,
withAccountId accountId: String) -> ConversationModel? {
return self.conversations.value
.filter({ conversation in
return conversation.participantUri == ringId && conversation.accountId == accountId
return conversation.participantUri == uri && conversation.accountId == accountId
})
.first
}
......
......@@ -92,7 +92,7 @@ class GeneratedInteractionsManager {
contactRingId: String,
shouldUpdateConversation: Bool) {
guard let conversation = self.conversationService.findConversation(withRingId: contactRingId, withAccountId: accountId) else {
guard let conversation = self.conversationService.findConversation(withUri: contactRingId, withAccountId: accountId) else {
return
}
// remove conversation if it contain only generated messages
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment