mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Show notifications always for incoming group calls
This commit is contained in:
parent
615387c7ee
commit
27b69914f3
3 changed files with 39 additions and 7 deletions
|
@ -323,6 +323,20 @@ Matrix session observer used to detect new opened sessions.
|
|||
|
||||
#pragma mark - UNUserNotificationCenterDelegate
|
||||
|
||||
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
|
||||
{
|
||||
if (notification.request.content.userInfo[Constants.userInfoKeyPresentNotificationAlways])
|
||||
{
|
||||
completionHandler(UNNotificationPresentationOptionBadge
|
||||
| UNNotificationPresentationOptionSound
|
||||
| UNNotificationPresentationOptionAlert);
|
||||
}
|
||||
else
|
||||
{
|
||||
completionHandler(UNNotificationPresentationOptionNone);
|
||||
}
|
||||
}
|
||||
|
||||
// iOS 10+, see application:handleActionWithIdentifier:forLocalNotification:withResponseInfo:completionHandler:
|
||||
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
|
||||
{
|
||||
|
|
|
@ -16,9 +16,13 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
enum Constants {
|
||||
@objcMembers
|
||||
class Constants: NSObject {
|
||||
|
||||
static let toBeRemovedNotificationCategoryIdentifier = "TO_BE_REMOVED"
|
||||
static let callInviteNotificationCategoryIdentifier = "CALL_INVITE"
|
||||
static let toBeRemovedNotificationCategoryIdentifier: String = "TO_BE_REMOVED"
|
||||
static let callInviteNotificationCategoryIdentifier: String = "CALL_INVITE"
|
||||
|
||||
/// Notification userInfo key to present a notification even if the app is on foreground. Value should be set as a Bool for this key.
|
||||
static let userInfoKeyPresentNotificationAlways: String = "ALWAYS_PRESENT_NOTIFICATION"
|
||||
|
||||
}
|
||||
|
|
|
@ -269,6 +269,7 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
case .success(let roomState):
|
||||
var notificationTitle: String?
|
||||
var notificationBody: String?
|
||||
var additionalUserInfo: [AnyHashable: Any]?
|
||||
|
||||
var threadIdentifier: String? = roomId
|
||||
let eventSenderName = roomState.members.memberName(event.sender)
|
||||
|
@ -384,6 +385,8 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
// only send VoIP pushes if ringing is enabled for group calls
|
||||
if RiotSettings.shared.enableRingingForGroupCalls {
|
||||
self.sendVoipPush(forEvent: event)
|
||||
} else {
|
||||
additionalUserInfo = [Constants.userInfoKeyPresentNotificationAlways: true]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -409,7 +412,8 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
threadIdentifier: threadIdentifier,
|
||||
userId: currentUserId,
|
||||
event: event,
|
||||
pushRule: pushRule)
|
||||
pushRule: pushRule,
|
||||
additionalInfo: additionalUserInfo)
|
||||
|
||||
NSLog("[NotificationService] notificationContentForEvent: Calling onComplete.")
|
||||
onComplete(notificationContent)
|
||||
|
@ -425,7 +429,8 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
threadIdentifier: String?,
|
||||
userId: String?,
|
||||
event: MXEvent,
|
||||
pushRule: MXPushRule?) -> UNNotificationContent {
|
||||
pushRule: MXPushRule?,
|
||||
additionalInfo: [AnyHashable: Any]? = nil) -> UNNotificationContent {
|
||||
let notificationContent = UNMutableNotificationContent()
|
||||
|
||||
if let title = title {
|
||||
|
@ -443,12 +448,16 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
if let soundName = notificationSoundName(fromPushRule: pushRule) {
|
||||
notificationContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: soundName))
|
||||
}
|
||||
notificationContent.userInfo = notificationUserInfo(forEvent: event, andUserId: userId)
|
||||
notificationContent.userInfo = notificationUserInfo(forEvent: event,
|
||||
andUserId: userId,
|
||||
additionalInfo: additionalInfo)
|
||||
|
||||
return notificationContent
|
||||
}
|
||||
|
||||
private func notificationUserInfo(forEvent event: MXEvent, andUserId userId: String?) -> [AnyHashable: Any] {
|
||||
private func notificationUserInfo(forEvent event: MXEvent,
|
||||
andUserId userId: String?,
|
||||
additionalInfo: [AnyHashable: Any]? = nil) -> [AnyHashable: Any] {
|
||||
var notificationUserInfo: [AnyHashable: Any] = [
|
||||
"type": "full",
|
||||
"room_id": event.roomId as Any,
|
||||
|
@ -457,6 +466,11 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
if let userId = userId {
|
||||
notificationUserInfo["user_id"] = userId
|
||||
}
|
||||
if let additionalInfo = additionalInfo {
|
||||
for (key, value) in additionalInfo {
|
||||
notificationUserInfo[key] = value
|
||||
}
|
||||
}
|
||||
return notificationUserInfo
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue