add additional logic
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import UserNotifications
|
import UserNotifications
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import Intents
|
||||||
|
|
||||||
let APP_GROUP = "group.app.bsky"
|
let APP_GROUP = "group.app.bsky"
|
||||||
typealias ContentHandler = (UNNotificationContent) -> Void
|
typealias ContentHandler = (UNNotificationContent) -> Void
|
||||||
@@ -46,8 +47,9 @@ class NotificationService: UNNotificationServiceExtension {
|
|||||||
|
|
||||||
if isReasonDm() {
|
if isReasonDm() {
|
||||||
mutateWithChatMessage(bestAttempt)
|
mutateWithChatMessage(bestAttempt)
|
||||||
// contentHandler will be called within mutateWithAvatar's completion block
|
mutateWithAvatar(bestAttempt) {
|
||||||
mutateWithAvatar(bestAttempt)
|
contentHandler(bestAttempt)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mutateWithBadge(bestAttempt)
|
mutateWithBadge(bestAttempt)
|
||||||
contentHandler(bestAttempt)
|
contentHandler(bestAttempt)
|
||||||
@@ -95,21 +97,46 @@ class NotificationService: UNNotificationServiceExtension {
|
|||||||
content.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "dm.aiff"))
|
content.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "dm.aiff"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func mutateWithAvatar(_ content: UNMutableNotificationContent) {
|
func mutateWithAvatar(_ content: UNMutableNotificationContent, completion: @escaping () -> Void) {
|
||||||
// Here, the server will only give us an avatar uri if there is a
|
// Here, the server will only give us an avatar uri if there is a
|
||||||
// follow relationship. All we need to check is the preference.
|
// follow relationship. All we need to check is the preference.
|
||||||
guard let avatarUrlString = content.userInfo["avatar"] as? String,
|
guard NSEUtil.shared.prefs?.bool(forKey: "showAvatarDms") == true,
|
||||||
NSEUtil.shared.prefs?.bool(forKey: "showAvatarDms") == true,
|
#available (iOSApplicationExtension 15.0, *),
|
||||||
|
let avatarUrlString = content.userInfo["avatar"] as? String,
|
||||||
|
let displayName = content.userInfo["displayName"] as? String,
|
||||||
let avatarUrl = URL(string: avatarUrlString),
|
let avatarUrl = URL(string: avatarUrlString),
|
||||||
let subject = self.getSubject() else {
|
let subject = self.getSubject(),
|
||||||
|
let contentHandler = self.contentHandler else {
|
||||||
|
completion()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
NSEUtil.shared.downloadImageIfNecessary(avatarUrl, userId: subject) { imageUrl in
|
NSEUtil.shared.downloadImageIfNecessary(avatarUrl, userId: subject) { imageUrl in
|
||||||
guard let contentHandler = self.contentHandler else {
|
guard let imageUrl = imageUrl else {
|
||||||
|
completion()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.contentHandler?(content)
|
|
||||||
|
let handle = INPersonHandle(value: subject,
|
||||||
|
type: .unknown)
|
||||||
|
let image = INImage(url: imageUrl)
|
||||||
|
let sender = INPerson(personHandle: handle,
|
||||||
|
nameComponents: nil,
|
||||||
|
displayName: displayName,
|
||||||
|
image: image,
|
||||||
|
contactIdentifier: subject,
|
||||||
|
customIdentifier: nil)
|
||||||
|
let intent = INSendMessageIntent.init(recipients: nil,
|
||||||
|
outgoingMessageType: .outgoingMessageText,
|
||||||
|
content: content.body,
|
||||||
|
speakableGroupName: nil,
|
||||||
|
conversationIdentifier: subject,
|
||||||
|
serviceName: nil,
|
||||||
|
sender: sender,
|
||||||
|
attachments: nil)
|
||||||
|
|
||||||
|
_ = try? content.updating(from: intent)
|
||||||
|
completion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +155,9 @@ class NotificationService: UNNotificationServiceExtension {
|
|||||||
}
|
}
|
||||||
return subject
|
return subject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addPersonAndAvatar(_ content: UNMutableNotificationContent) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NSEUtil's purpose is to create a shared instance of `UserDefaults` across
|
// NSEUtil's purpose is to create a shared instance of `UserDefaults` across
|
||||||
@@ -166,7 +196,7 @@ private class NSEUtil {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.imageExists(outUrl)) {
|
if self.imageExists(outUrl) {
|
||||||
completion(outUrl)
|
completion(outUrl)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user