diff --git a/Session/Notifications/AppNotifications.swift b/Session/Notifications/AppNotifications.swift index 3ba8d5e62..42280c493 100644 --- a/Session/Notifications/AppNotifications.swift +++ b/Session/Notifications/AppNotifications.swift @@ -165,6 +165,13 @@ public class NotificationPresenter: NSObject, NotificationsProtocol { // see https://developer.apple.com/documentation/uikit/uilocalnotification/1616646-alertbody // for more details. let messageText = DisplayableText.filterNotificationText(rawMessageText) + + // Do not fire the notification wihtout mentioning current user, + // if current user sets isOnlyNotifyMentions on. + let isUserMentioned = MentionUtilities.isUserMentioned(in: messageText ?? "") + if let groupThread = thread as? TSGroupThread, groupThread.isOnlyNotifyMentions && !isUserMentioned { + return + } let context = Contact.context(for: thread) let senderName = Storage.shared.getContact(with: incomingMessage.authorId)?.displayName(for: context) ?? incomingMessage.authorId diff --git a/Session/Utilities/MentionUtilities.swift b/Session/Utilities/MentionUtilities.swift index 1a39cb1fa..5c888b09d 100644 --- a/Session/Utilities/MentionUtilities.swift +++ b/Session/Utilities/MentionUtilities.swift @@ -44,4 +44,9 @@ public final class MentionUtilities : NSObject { } return result } + + public static func isUserMentioned(in string: String) -> Bool { + let userPublicKey = getUserHexEncodedPublicKey() + return string.contains("@\(userPublicKey)") + } }