Commit 67180dc2 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

UI: notifications and alerts

- Add account name for incoming call
- fix peer display name for incoming messages notifications
- do not present notifications if proxy disabled

Change-Id: If09aa60baa416b23958b754d6777492d24ca8815
parent 506ace5d
......@@ -151,35 +151,53 @@ class ConversationsCoordinator: Coordinator, StateableResponsive, ConversationNa
}
private func showCallAlert(call: CallModel) {
if UIApplication.shared.applicationState != .active && !call.callId.isEmpty {
guard let account = self.accountService
.getAccount(fromAccountId: call.accountId) else {return}
if call.callId.isEmpty {
return
}
if UIApplication.shared.applicationState != .active {
if AccountModelHelper
.init(withAccount: account).isAccountSip() ||
!self.accountService.getCurrentProxyState(accountID: account.id) {
return
}
var data = [String: String]()
data [NotificationUserInfoKeys.name.rawValue] = call.participantUri
data [NotificationUserInfoKeys.name.rawValue] = call.displayName
data [NotificationUserInfoKeys.callID.rawValue] = call.callId
let helper = LocalNotificationsHelper()
helper.presentCallNotification(data: data, callService: self.callService)
} else {
let alertStyle = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad) ? UIAlertControllerStyle.alert : UIAlertControllerStyle.actionSheet
let alert = UIAlertController(title: L10n.Alerts.incomingCallAllertTitle + "\(call.displayName)", message: nil, preferredStyle: alertStyle)
alert.addAction(UIAlertAction(title: L10n.Alerts.incomingCallButtonAccept, style: UIAlertActionStyle.default, handler: { (_) in
self.answerIncomingCall(call: call)
alert.dismiss(animated: true, completion: nil)}))
alert.addAction(UIAlertAction(title: L10n.Alerts.incomingCallButtonIgnore, style: UIAlertActionStyle.default, handler: { (_) in
self.injectionBag.callService.refuse(callId: call.callId)
.subscribe({_ in
print("Call ignored")
}).disposed(by: self.disposeBag)
alert.dismiss(animated: true, completion: nil)
}))
self.present(viewController: alert, withStyle: .present, withAnimation: true, disposeBag: self.disposeBag)
self.callService.currentCall.takeUntil(alert.rx.controllerWasDismissed).filter({ currentCall in
return currentCall.callId == call.callId &&
(currentCall.state == .over || currentCall.state == .failure)
}).subscribe(onNext: { _ in
DispatchQueue.main.async {
alert.dismiss(animated: true, completion: nil)
}
}).disposed(by: self.disposeBag)
return
}
var accountName = !account.registeredName.isEmpty ?
account.registeredName : account.type == AccountType.sip ?
account.username : account.jamiId
if let accountProfie = self.accountService.getAccountProfile(accountId: account.id), let name = accountProfie.alias,
!name.isEmpty {
accountName = name
}
let message = accountName.isEmpty ? nil : "To: " + accountName
let alertStyle = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad) ? UIAlertControllerStyle.alert : UIAlertControllerStyle.actionSheet
let alert = UIAlertController(title: L10n.Alerts.incomingCallAllertTitle + "\(call.displayName)", message: message, preferredStyle: alertStyle)
alert.addAction(UIAlertAction(title: L10n.Alerts.incomingCallButtonAccept, style: UIAlertActionStyle.default, handler: { (_) in
self.answerIncomingCall(call: call)
alert.dismiss(animated: true, completion: nil)}))
alert.addAction(UIAlertAction(title: L10n.Alerts.incomingCallButtonIgnore, style: UIAlertActionStyle.default, handler: { (_) in
self.injectionBag.callService.refuse(callId: call.callId)
.subscribe({_ in
print("Call ignored")
}).disposed(by: self.disposeBag)
alert.dismiss(animated: true, completion: nil)
}))
self.present(viewController: alert, withStyle: .present, withAnimation: true, disposeBag: self.disposeBag)
self.callService.currentCall.takeUntil(alert.rx.controllerWasDismissed).filter({ currentCall in
return currentCall.callId == call.callId &&
(currentCall.state == .over || currentCall.state == .failure)
}).subscribe(onNext: { _ in
DispatchQueue.main.async {
alert.dismiss(animated: true, completion: nil)
}
}).disposed(by: self.disposeBag)
}
}
......@@ -247,6 +247,10 @@ class AccountsService: AccountAdapterDelegate {
}
}
func getAccountProfile(accountId: String) -> AccountProfile? {
return self.dbManager.accountProfile(for: accountId)
}
/// Adds a new Ring account.
///
/// - Parameters:
......
......@@ -142,34 +142,36 @@ class ConversationsManager: MessagesAdapterDelegate {
guard let accountForMessage = self.accountsService.getAccount(fromAccountId: accountId) else {
return
}
if UIApplication.shared.applicationState != .active {
if UIApplication.shared.applicationState != .active && AccountModelHelper
.init(withAccount: accountForMessage).isAccountRing() &&
accountsService.getCurrentProxyState(accountID: accountId) {
var data = [String: String]()
data [NotificationUserInfoKeys.messageContent.rawValue] = content
data [NotificationUserInfoKeys.participantID.rawValue] = peerUri
if let name = peerName {
data [NotificationUserInfoKeys.name.rawValue] = name
self.notificationHandler.presentMessageNotification(data: data)
} else if AccountModelHelper.init(withAccount: accountForMessage).isAccountSip() {
data [NotificationUserInfoKeys.name.rawValue] = peerUri
self.notificationHandler.presentMessageNotification(data: data)
} else {
} else {
// only for jami accounts
self.nameService.usernameLookupStatus.single()
.filter({ lookupNameResponse in
return lookupNameResponse.address != nil &&
lookupNameResponse.address == peerUri
})
.subscribe(onNext: { [weak self] lookupNameResponse in
if let name = lookupNameResponse.name, !name.isEmpty {
data [NotificationUserInfoKeys.name.rawValue] = name
self?.notificationHandler.presentMessageNotification(data: data)
} else if let address = lookupNameResponse.address {
data [NotificationUserInfoKeys.name.rawValue] = address
self?.notificationHandler.presentMessageNotification(data: data)
}
}).disposed(by: self.disposeBag)
self.nameService.lookupAddress(withAccount: "", nameserver: "", address: peerUri)
if let hash = JamiURI(schema: URIType.ring,
infoHach: peerUri).hash {
self.nameService.usernameLookupStatus.single()
.filter({ lookupNameResponse in
return lookupNameResponse.address != nil &&
lookupNameResponse.address == hash
})
.subscribe(onNext: { [weak self] lookupNameResponse in
if let name = lookupNameResponse.name, !name.isEmpty {
data [NotificationUserInfoKeys.name.rawValue] = name
self?.notificationHandler.presentMessageNotification(data: data)
} else if let address = lookupNameResponse.address {
data [NotificationUserInfoKeys.name.rawValue] = address
self?.notificationHandler.presentMessageNotification(data: data)
}
}).disposed(by: self.disposeBag)
self.nameService.lookupAddress(withAccount: "", nameserver: "", address: hash)
}
}
}
var shouldUpdateConversationsList = false
......
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