From 354b7e0dc36cce4d3d0f73fcf2de60cb39a3570d Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Mon, 26 Jul 2021 15:43:03 +1000 Subject: [PATCH] notify mentions as settings --- Session/Notifications/AppNotifications.swift | 7 +++++++ Session/Utilities/MentionUtilities.swift | 5 +++++ 2 files changed, 12 insertions(+) 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)") + } }