From ecf92ceeea6a1e25627426c78a428a5949a890bb Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 19 Oct 2021 15:11:47 +1100 Subject: [PATCH] fix PN sound settings not applying to remote PNs --- Session.xcodeproj/project.pbxproj | 4 ++++ Session/Notifications/UserNotificationsAdaptee.swift | 11 ----------- SessionMessagingKit/Utilities/OWSSounds.swift | 10 ++++++++++ .../NotificationServiceExtension.swift | 1 + 4 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 SessionMessagingKit/Utilities/OWSSounds.swift diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 10948e08f..6cb14edef 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -136,6 +136,7 @@ 768A1A2B17FC9CD300E00ED8 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 768A1A2A17FC9CD300E00ED8 /* libz.dylib */; }; 76C87F19181EFCE600C4ACAB /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 76C87F18181EFCE600C4ACAB /* MediaPlayer.framework */; }; 76EB054018170B33006006FC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB03C318170B33006006FC /* AppDelegate.m */; }; + 7B1581E2271E743B00848B49 /* OWSSounds.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1581E1271E743B00848B49 /* OWSSounds.swift */; }; 7B4C75CB26B37E0F0000AC89 /* UnsendRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4C75CA26B37E0F0000AC89 /* UnsendRequest.swift */; }; 7B4C75CD26BB92060000AC89 /* DeletedMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4C75CC26BB92060000AC89 /* DeletedMessageView.swift */; }; 7B7CB18B270591630079FF93 /* ShareLogsModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B7CB18A270591630079FF93 /* ShareLogsModal.swift */; }; @@ -1101,6 +1102,7 @@ 76C87F18181EFCE600C4ACAB /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; }; 76EB03C218170B33006006FC /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 76EB03C318170B33006006FC /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 7B1581E1271E743B00848B49 /* OWSSounds.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OWSSounds.swift; sourceTree = ""; }; 7B2DB2AD26F1B0FF0035B509 /* si */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = si; path = si.lproj/Localizable.strings; sourceTree = ""; }; 7B4C75CA26B37E0F0000AC89 /* UnsendRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnsendRequest.swift; sourceTree = ""; }; 7B4C75CC26BB92060000AC89 /* DeletedMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeletedMessageView.swift; sourceTree = ""; }; @@ -3148,6 +3150,7 @@ C38EF308255B6DBE007E1867 /* OWSPreferences.m */, C38EF288255B6D85007E1867 /* OWSSounds.h */, C38EF28B255B6D86007E1867 /* OWSSounds.m */, + 7B1581E1271E743B00848B49 /* OWSSounds.swift */, C38EF2FB255B6DBD007E1867 /* OWSWindowManager.h */, C38EF306255B6DBE007E1867 /* OWSWindowManager.m */, C38EF2EC255B6DBA007E1867 /* ProximityMonitoringManager.swift */, @@ -4613,6 +4616,7 @@ B8B32021258B1A650020074B /* Contact.swift in Sources */, C32C5C89256DD0D2003C73A2 /* Storage+Jobs.swift in Sources */, C300A5FC2554B0A000555489 /* MessageReceiver.swift in Sources */, + 7B1581E2271E743B00848B49 /* OWSSounds.swift in Sources */, C32C5A76256DBBCF003C73A2 /* SignalAttachment.swift in Sources */, C32C5CA4256DD1DC003C73A2 /* TSAccountManager.m in Sources */, C352A3892557876500338F3E /* JobQueue.swift in Sources */, diff --git a/Session/Notifications/UserNotificationsAdaptee.swift b/Session/Notifications/UserNotificationsAdaptee.swift index 8d8b6ec21..13c648fe6 100644 --- a/Session/Notifications/UserNotificationsAdaptee.swift +++ b/Session/Notifications/UserNotificationsAdaptee.swift @@ -242,14 +242,3 @@ public class UserNotificationActionHandler: NSObject { } } } - -extension OWSSound { - - func notificationSound(isQuiet: Bool) -> UNNotificationSound { - guard let filename = OWSSounds.filename(for: self, quiet: isQuiet) else { - owsFailDebug("filename was unexpectedly nil") - return UNNotificationSound.default - } - return UNNotificationSound(named: UNNotificationSoundName(rawValue: filename)) - } -} diff --git a/SessionMessagingKit/Utilities/OWSSounds.swift b/SessionMessagingKit/Utilities/OWSSounds.swift new file mode 100644 index 000000000..bd51d9345 --- /dev/null +++ b/SessionMessagingKit/Utilities/OWSSounds.swift @@ -0,0 +1,10 @@ +extension OWSSound { + + public func notificationSound(isQuiet: Bool) -> UNNotificationSound { + guard let filename = OWSSounds.filename(for: self, quiet: isQuiet) else { + owsFailDebug("filename was unexpectedly nil") + return UNNotificationSound.default + } + return UNNotificationSound(named: UNNotificationSoundName(rawValue: filename)) + } +} diff --git a/SessionNotificationServiceExtension/NotificationServiceExtension.swift b/SessionNotificationServiceExtension/NotificationServiceExtension.swift index 8ed9b243a..133c08736 100644 --- a/SessionNotificationServiceExtension/NotificationServiceExtension.swift +++ b/SessionNotificationServiceExtension/NotificationServiceExtension.swift @@ -77,6 +77,7 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension } semaphore.wait() } + notificationContent.sound = OWSSounds.notificationSound(for: thread).notificationSound(isQuiet: false) case let unsendRequest as UnsendRequest: MessageReceiver.handleUnsendRequest(unsendRequest, using: transaction) return self.completeSilenty()