notify mentions as settings

This commit is contained in:
ryanzhao 2021-07-26 15:43:03 +10:00
parent f0d2826403
commit 354b7e0dc3
2 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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)")
}
}