[Chat] Set the sender avatar as the group image in NSE (#10600)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import UserNotifications
|
||||
import UIKit
|
||||
import Intents
|
||||
import UIKit
|
||||
import UserNotifications
|
||||
|
||||
let APP_GROUP = "group.app.bsky"
|
||||
typealias ContentHandler = (UNNotificationContent) -> Void
|
||||
@@ -30,7 +30,10 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
private var contentHandler: ContentHandler?
|
||||
private var bestAttempt: UNMutableNotificationContent?
|
||||
|
||||
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
|
||||
override func didReceive(
|
||||
_ request: UNNotificationRequest,
|
||||
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
|
||||
) {
|
||||
self.contentHandler = contentHandler
|
||||
|
||||
guard let bestAttempt = NSEUtil.createCopy(request.content),
|
||||
@@ -72,7 +75,8 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
|
||||
override func serviceExtensionTimeWillExpire() {
|
||||
guard let contentHandler = self.contentHandler,
|
||||
let bestAttempt = self.bestAttempt else {
|
||||
let bestAttempt = self.bestAttempt
|
||||
else {
|
||||
return
|
||||
}
|
||||
contentHandler(bestAttempt)
|
||||
@@ -86,7 +90,7 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
) -> UNNotificationContent {
|
||||
let senderDisplayName = userInfo["senderDisplayName"] as? String ?? "Unknown"
|
||||
let convoId = userInfo["convoId"] as? String
|
||||
var avatarImage: INImage? = nil
|
||||
var avatarImage: INImage?
|
||||
if let avatarUrlString = userInfo["senderAvatarUrl"] as? String {
|
||||
avatarImage = downloadAvatarImage(from: avatarUrlString)
|
||||
}
|
||||
@@ -102,7 +106,7 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
customIdentifier: nil
|
||||
)
|
||||
|
||||
var speakableGroupName: INSpeakableString? = nil
|
||||
var speakableGroupName: INSpeakableString?
|
||||
if userInfo["convoKind"] as? String == "group",
|
||||
let groupName = userInfo["groupName"] as? String,
|
||||
!groupName.isEmpty {
|
||||
@@ -143,6 +147,12 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
// intent.setImage(groupImage, forParameterNamed: \.speakableGroupName)
|
||||
// }
|
||||
|
||||
// Set the group image to the sender avatar instead
|
||||
if userInfo["convoKind"] as? String == "group",
|
||||
let avatarImage {
|
||||
intent.setImage(avatarImage, forParameterNamed: \.speakableGroupName)
|
||||
}
|
||||
|
||||
let interaction = INInteraction(intent: intent, response: nil)
|
||||
interaction.direction = .incoming
|
||||
interaction.donate(completion: nil)
|
||||
@@ -165,10 +175,10 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
var request = URLRequest(url: url)
|
||||
request.timeoutInterval = 5
|
||||
|
||||
var imageData: Data? = nil
|
||||
var imageData: Data?
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
|
||||
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
||||
let task = URLSession.shared.dataTask(with: request) { data, response, _ in
|
||||
if let data = data,
|
||||
let httpResponse = response as? HTTPURLResponse,
|
||||
httpResponse.statusCode == 200 {
|
||||
@@ -211,7 +221,8 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
) {
|
||||
guard userInfo["convoKind"] as? String == "group",
|
||||
let groupName = userInfo["groupName"] as? String,
|
||||
!groupName.isEmpty else {
|
||||
!groupName.isEmpty
|
||||
else {
|
||||
return
|
||||
}
|
||||
content.subtitle = groupName
|
||||
@@ -228,7 +239,8 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
) {
|
||||
guard let messageKind = userInfo["messageKind"] as? String,
|
||||
messageKind != "message",
|
||||
!content.title.isEmpty else {
|
||||
!content.title.isEmpty
|
||||
else {
|
||||
return
|
||||
}
|
||||
content.body = content.title
|
||||
|
||||
Reference in New Issue
Block a user