fix mention in PNs
This commit is contained in:
parent
381cf10dce
commit
af2ca32986
|
@ -71,15 +71,15 @@ final class NotificationServiceExtension : UNNotificationServiceExtension {
|
||||||
}
|
}
|
||||||
let group: SSKProtoGroupContext = contentProto!.dataMessage!.group!
|
let group: SSKProtoGroupContext = contentProto!.dataMessage!.group!
|
||||||
let oldGroupModel = (thread as! TSGroupThread).groupModel
|
let oldGroupModel = (thread as! TSGroupThread).groupModel
|
||||||
var removedMembers = Set(arrayLiteral: oldGroupModel.groupMemberIds)
|
let removedMembers = NSMutableSet(array: oldGroupModel.groupMemberIds)
|
||||||
let newGroupModel = TSGroupModel.init(title: group.name,
|
let newGroupModel = TSGroupModel.init(title: group.name,
|
||||||
memberIds:group.members,
|
memberIds:group.members,
|
||||||
image: oldGroupModel.groupImage,
|
image: oldGroupModel.groupImage,
|
||||||
groupId: group.id,
|
groupId: group.id,
|
||||||
groupType: oldGroupModel.groupType,
|
groupType: oldGroupModel.groupType,
|
||||||
adminIds: group.admins)
|
adminIds: group.admins)
|
||||||
removedMembers.subtract(Set(arrayLiteral: newGroupModel.groupMemberIds))
|
removedMembers.minus(Set(newGroupModel.groupMemberIds))
|
||||||
newGroupModel.removedMembers = NSMutableSet(set: removedMembers)
|
newGroupModel.removedMembers = removedMembers
|
||||||
switch contentProto?.dataMessage?.group?.type {
|
switch contentProto?.dataMessage?.group?.type {
|
||||||
case .update:
|
case .update:
|
||||||
newNotificationBody = oldGroupModel.getInfoStringAboutUpdate(to: newGroupModel, contactsManager: SSKEnvironment.shared.contactsManager)
|
newNotificationBody = oldGroupModel.getInfoStringAboutUpdate(to: newGroupModel, contactsManager: SSKEnvironment.shared.contactsManager)
|
||||||
|
@ -100,7 +100,8 @@ final class NotificationServiceExtension : UNNotificationServiceExtension {
|
||||||
notificationContent.userInfo = userInfo
|
notificationContent.userInfo = userInfo
|
||||||
notificationContent.badge = 1
|
notificationContent.badge = 1
|
||||||
if newNotificationBody.count < 1 {
|
if newNotificationBody.count < 1 {
|
||||||
newNotificationBody = contentProto?.dataMessage?.body ?? "You've got a new message"
|
let rawMessageBody = contentProto?.dataMessage?.body ?? "You've got a new message"
|
||||||
|
newNotificationBody = handleMentionIfNecessary(rawMessageBody: rawMessageBody, threadID: thread.uniqueId!, transaction: transaction)
|
||||||
}
|
}
|
||||||
notificationContent.body = newNotificationBody
|
notificationContent.body = newNotificationBody
|
||||||
if notificationContent.body.count < 1 {
|
if notificationContent.body.count < 1 {
|
||||||
|
@ -109,6 +110,25 @@ final class NotificationServiceExtension : UNNotificationServiceExtension {
|
||||||
self.contentHandler!(notificationContent)
|
self.contentHandler!(notificationContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleMentionIfNecessary(rawMessageBody: String, threadID: String, transaction: YapDatabaseReadWriteTransaction) -> String {
|
||||||
|
var string = rawMessageBody
|
||||||
|
let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]*", options: [])
|
||||||
|
var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.count))
|
||||||
|
while let match = outerMatch {
|
||||||
|
let hexEncodedPublicKey = String((string as NSString).substring(with: match.range).dropFirst()) // Drop the @
|
||||||
|
let matchEnd: Int
|
||||||
|
let displayName: String? = OWSProfileManager.shared().profileNameForRecipient(withID: hexEncodedPublicKey, transaction: transaction)
|
||||||
|
if let displayName = displayName {
|
||||||
|
string = (string as NSString).replacingCharacters(in: match.range, with: "@\(displayName)")
|
||||||
|
matchEnd = match.range.location + displayName.count
|
||||||
|
} else {
|
||||||
|
matchEnd = match.range.location + match.range.length
|
||||||
|
}
|
||||||
|
outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: matchEnd, length: string.count - matchEnd))
|
||||||
|
}
|
||||||
|
return string
|
||||||
|
}
|
||||||
|
|
||||||
func setUpIfNecessary(completion: @escaping () -> Void) {
|
func setUpIfNecessary(completion: @escaping () -> Void) {
|
||||||
AssertIsOnMainThread()
|
AssertIsOnMainThread()
|
||||||
|
|
|
@ -13,6 +13,7 @@ public final class MentionUtilities : NSObject {
|
||||||
var publicChat: PublicChat?
|
var publicChat: PublicChat?
|
||||||
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
|
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
|
||||||
publicChat = LokiDatabaseUtilities.getPublicChat(for: threadID, in: transaction)
|
publicChat = LokiDatabaseUtilities.getPublicChat(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]*", options: [])
|
||||||
|
|
|
@ -357,7 +357,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
|
||||||
// it must be escaped.
|
// it must be escaped.
|
||||||
// see https://developer.apple.com/documentation/uikit/uilocalnotification/1616646-alertbody
|
// see https://developer.apple.com/documentation/uikit/uilocalnotification/1616646-alertbody
|
||||||
// for more details.
|
// for more details.
|
||||||
let messageText = DisplayableText.filterNotificationText(rawMessageText)
|
let messageText = MentionUtilities.highlightMentions(in: DisplayableText.filterNotificationText(rawMessageText)!, threadID: thread.uniqueId!)
|
||||||
|
|
||||||
let senderName = OWSUserProfile.fetch(uniqueId: incomingMessage.authorId, transaction: transaction)?.profileName ?? contactsManager.displayName(forPhoneIdentifier: incomingMessage.authorId)
|
let senderName = OWSUserProfile.fetch(uniqueId: incomingMessage.authorId, transaction: transaction)?.profileName ?? contactsManager.displayName(forPhoneIdentifier: incomingMessage.authorId)
|
||||||
|
|
||||||
|
|
|
@ -75,8 +75,8 @@ public final class MentionsManager : NSObject {
|
||||||
guard let message = object as? TSIncomingMessage, index < userIDScanLimit else { return }
|
guard let message = object as? TSIncomingMessage, index < userIDScanLimit else { return }
|
||||||
result.insert(message.authorId)
|
result.insert(message.authorId)
|
||||||
}
|
}
|
||||||
result.insert(getUserHexEncodedPublicKey())
|
|
||||||
}
|
}
|
||||||
|
result.insert(getUserHexEncodedPublicKey())
|
||||||
}
|
}
|
||||||
if let transaction = transaction {
|
if let transaction = transaction {
|
||||||
populate(in: transaction)
|
populate(in: transaction)
|
||||||
|
|
Loading…
Reference in New Issue