Merge pull request #480 from RyanRory/filtered-push-notification
Push Notification Improvements
This commit is contained in:
commit
6820accb49
|
@ -515,7 +515,7 @@ CGFloat kIconViewLength = 24;
|
||||||
[weakSelf.navigationController pushViewController:vc animated:YES];
|
[weakSelf.navigationController pushViewController:vc animated:YES];
|
||||||
}]];
|
}]];
|
||||||
|
|
||||||
if (self.isOpenGroup) {
|
if (self.isGroupThread) {
|
||||||
// Notification Settings
|
// Notification Settings
|
||||||
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
||||||
UITableViewCell *cell = [OWSTableItem newCell];
|
UITableViewCell *cell = [OWSTableItem newCell];
|
||||||
|
|
|
@ -14,7 +14,7 @@ public final class MentionUtilities : NSObject {
|
||||||
MentionsManager.populateUserPublicKeyCacheIfNeeded(for: threadID, in: transaction)
|
MentionsManager.populateUserPublicKeyCacheIfNeeded(for: threadID, in: transaction)
|
||||||
}
|
}
|
||||||
var string = string
|
var string = string
|
||||||
let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]*", options: [])
|
let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]{66}", options: [])
|
||||||
let knownPublicKeys = MentionsManager.userPublicKeyCache[threadID] ?? [] // Should always be populated at this point
|
let knownPublicKeys = MentionsManager.userPublicKeyCache[threadID] ?? [] // Should always be populated at this point
|
||||||
var mentions: [(range: NSRange, publicKey: String)] = []
|
var mentions: [(range: NSRange, publicKey: String)] = []
|
||||||
var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.utf16.count))
|
var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.utf16.count))
|
||||||
|
@ -44,9 +44,4 @@ public final class MentionUtilities : NSObject {
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func isUserMentioned(in string: String) -> Bool {
|
|
||||||
let userPublicKey = getUserHexEncodedPublicKey()
|
|
||||||
return string.contains("@\(userPublicKey)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>com.apple.developer.usernotifications.filtering</key>
|
||||||
|
<true/>
|
||||||
<key>aps-environment</key>
|
<key>aps-environment</key>
|
||||||
<string>development</string>
|
<string>development</string>
|
||||||
<key>com.apple.security.application-groups</key>
|
<key>com.apple.security.application-groups</key>
|
||||||
|
|
|
@ -14,6 +14,7 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
|
||||||
override public func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
|
override public func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
|
||||||
self.contentHandler = contentHandler
|
self.contentHandler = contentHandler
|
||||||
self.notificationContent = request.content.mutableCopy() as? UNMutableNotificationContent
|
self.notificationContent = request.content.mutableCopy() as? UNMutableNotificationContent
|
||||||
|
let userPublicKey = SNGeneralUtilities.getUserPublicKey()
|
||||||
|
|
||||||
// Abort if the main app is running
|
// Abort if the main app is running
|
||||||
var isMainAppAndActive = false
|
var isMainAppAndActive = false
|
||||||
|
@ -36,6 +37,10 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
|
||||||
do {
|
do {
|
||||||
let (message, proto) = try MessageReceiver.parse(envelopeAsData, openGroupMessageServerID: nil, using: transaction)
|
let (message, proto) = try MessageReceiver.parse(envelopeAsData, openGroupMessageServerID: nil, using: transaction)
|
||||||
let senderPublicKey = message.sender!
|
let senderPublicKey = message.sender!
|
||||||
|
if (senderPublicKey == userPublicKey) {
|
||||||
|
// Ignore PNs of messages sent from current user.
|
||||||
|
return self.completeSilenty()
|
||||||
|
}
|
||||||
var senderDisplayName = Storage.shared.getContact(with: senderPublicKey)?.displayName(for: .regular) ?? senderPublicKey
|
var senderDisplayName = Storage.shared.getContact(with: senderPublicKey)?.displayName(for: .regular) ?? senderPublicKey
|
||||||
let snippet: String
|
let snippet: String
|
||||||
var userInfo: [String:Any] = [ NotificationServiceExtension.isFromRemoteKey : true ]
|
var userInfo: [String:Any] = [ NotificationServiceExtension.isFromRemoteKey : true ]
|
||||||
|
@ -56,6 +61,10 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
|
||||||
if let thread = TSThread.fetch(uniqueId: threadID, transaction: transaction), let group = thread as? TSGroupThread,
|
if let thread = TSThread.fetch(uniqueId: threadID, transaction: transaction), let group = thread as? TSGroupThread,
|
||||||
group.groupModel.groupType == .closedGroup { // Should always be true because we don't get PNs for open groups
|
group.groupModel.groupType == .closedGroup { // Should always be true because we don't get PNs for open groups
|
||||||
senderDisplayName = String(format: NotificationStrings.incomingGroupMessageTitleFormat, senderDisplayName, group.groupModel.groupName ?? MessageStrings.newGroupDefaultTitle)
|
senderDisplayName = String(format: NotificationStrings.incomingGroupMessageTitleFormat, senderDisplayName, group.groupModel.groupName ?? MessageStrings.newGroupDefaultTitle)
|
||||||
|
if group.isOnlyNotifyingForMentions && !tsIncomingMessage.isUserMentioned {
|
||||||
|
// Ignore PNs if the group is set to only notify mentions
|
||||||
|
return self.completeSilenty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case let closedGroupControlMessage as ClosedGroupControlMessage:
|
case let closedGroupControlMessage as ClosedGroupControlMessage:
|
||||||
// TODO: We could consider actually handling the update here. Not sure if there's enough time though, seeing as though
|
// TODO: We could consider actually handling the update here. Not sure if there's enough time though, seeing as though
|
||||||
|
@ -192,7 +201,7 @@ private extension String {
|
||||||
func replacingMentions(for threadID: String, using transaction: YapDatabaseReadWriteTransaction) -> String {
|
func replacingMentions(for threadID: String, using transaction: YapDatabaseReadWriteTransaction) -> String {
|
||||||
MentionsManager.populateUserPublicKeyCacheIfNeeded(for: threadID, in: transaction)
|
MentionsManager.populateUserPublicKeyCacheIfNeeded(for: threadID, in: transaction)
|
||||||
var result = self
|
var result = self
|
||||||
let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]*", options: [])
|
let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]{66}", options: [])
|
||||||
let knownPublicKeys = MentionsManager.userPublicKeyCache[threadID] ?? []
|
let knownPublicKeys = MentionsManager.userPublicKeyCache[threadID] ?? []
|
||||||
var mentions: [(range: NSRange, publicKey: String)] = []
|
var mentions: [(range: NSRange, publicKey: String)] = []
|
||||||
var m0 = regex.firstMatch(in: result, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: result.utf16.count))
|
var m0 = regex.firstMatch(in: result, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: result.utf16.count))
|
||||||
|
|
Loading…
Reference in New Issue