Revert "WIP: make the attachment download work in NSE"

This reverts commit 7295c14e17.
This commit is contained in:
ryanzhao 2021-08-30 10:00:04 +10:00
parent 7295c14e17
commit 454003c027
5 changed files with 22 additions and 23 deletions

View File

@ -208,6 +208,6 @@ SPEC CHECKSUMS:
YYImage: 6db68da66f20d9f169ceb94dfb9947c3867b9665 YYImage: 6db68da66f20d9f169ceb94dfb9947c3867b9665
ZXingObjC: fdbb269f25dd2032da343e06f10224d62f537bdb ZXingObjC: fdbb269f25dd2032da343e06f10224d62f537bdb
PODFILE CHECKSUM: 71474628a9c2c3e57bdb0992668809a4369452f1 PODFILE CHECKSUM: 50e6a35c838ba28d2ee02bc6018fdd297c04e55f
COCOAPODS: 1.10.1 COCOAPODS: 1.10.1

View File

@ -73,11 +73,13 @@ extension Storage {
return result.first return result.first
} }
public func getAttachmentDownloadJob(for attachmentID: String, with transaction: YapDatabaseReadTransaction) -> AttachmentDownloadJob? { public func getAttachmentDownloadJob(for attachmentID: String) -> AttachmentDownloadJob? {
var result: [AttachmentDownloadJob] = [] var result: [AttachmentDownloadJob] = []
transaction.enumerateRows(inCollection: AttachmentDownloadJob.collection) { _, object, _, _ in Storage.read { transaction in
guard let job = object as? AttachmentDownloadJob, job.attachmentID == attachmentID else { return } transaction.enumerateRows(inCollection: AttachmentDownloadJob.collection) { _, object, _, _ in
result.append(job) guard let job = object as? AttachmentDownloadJob, job.attachmentID == attachmentID else { return }
result.append(job)
}
} }
#if DEBUG #if DEBUG
assert(result.isEmpty || result.count == 1) assert(result.isEmpty || result.count == 1)

View File

@ -5,7 +5,7 @@ import PromiseKit
public final class PushNotificationAPI : NSObject { public final class PushNotificationAPI : NSObject {
// MARK: Settings // MARK: Settings
public static let server = "https://dev.apns.getsession.org" public static let server = "https://live.apns.getsession.org"
public static let serverPublicKey = "642a6585919742e5a2d4dc51244964fbcd8bcab2b75612407de58b810740d049" public static let serverPublicKey = "642a6585919742e5a2d4dc51244964fbcd8bcab2b75612407de58b810740d049"
private static let maxRetryCount: UInt = 4 private static let maxRetryCount: UInt = 4
private static let tokenExpirationInterval: TimeInterval = 12 * 60 * 60 private static let tokenExpirationInterval: TimeInterval = 12 * 60 * 60

View File

@ -1,6 +1,5 @@
import PromiseKit import PromiseKit
import Sodium import Sodium
import YapDatabase
public protocol SessionMessagingKitStorageProtocol { public protocol SessionMessagingKitStorageProtocol {
@ -34,7 +33,7 @@ public protocol SessionMessagingKitStorageProtocol {
func markJobAsFailed(_ job: Job, using transaction: Any) func markJobAsFailed(_ job: Job, using transaction: Any)
func getAllPendingJobs(of type: Job.Type) -> [Job] func getAllPendingJobs(of type: Job.Type) -> [Job]
func getAttachmentUploadJob(for attachmentID: String) -> AttachmentUploadJob? func getAttachmentUploadJob(for attachmentID: String) -> AttachmentUploadJob?
func getAttachmentDownloadJob(for attachmentID: String, with transaction: YapDatabaseReadTransaction) -> AttachmentDownloadJob? func getAttachmentDownloadJob(for attachmentID: String) -> AttachmentDownloadJob?
func getMessageSendJob(for messageSendJobID: String) -> MessageSendJob? func getMessageSendJob(for messageSendJobID: String) -> MessageSendJob?
func resumeMessageSendJobIfNeeded(_ messageSendJobID: String) func resumeMessageSendJobIfNeeded(_ messageSendJobID: String)
func isJobCanceled(_ job: Job) -> Bool func isJobCanceled(_ job: Job) -> Bool

View File

@ -34,9 +34,9 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
let envelope = try? MessageWrapper.unwrap(data: data), let envelopeAsData = try? envelope.serializedData() else { let envelope = try? MessageWrapper.unwrap(data: data), let envelopeAsData = try? envelope.serializedData() else {
return self.handleFailure(for: notificationContent) return self.handleFailure(for: notificationContent)
} }
var attachmentDownloadJobs: [AttachmentDownloadJob] = []
Storage.write { transaction in // Intentionally capture self Storage.write { transaction in // Intentionally capture self
do { do {
var attachmentDownloadJobs: [AttachmentDownloadJob] = []
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) { if (senderPublicKey == userPublicKey) {
@ -72,10 +72,10 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
// Store the notification ID for unsend requests to later cancel this notification // Store the notification ID for unsend requests to later cancel this notification
tsIncomingMessage.setNotificationIdentifier(request.identifier, transaction: transaction) tsIncomingMessage.setNotificationIdentifier(request.identifier, transaction: transaction)
let storage = SNMessagingKitConfiguration.shared.storage let storage = SNMessagingKitConfiguration.shared.storage
let attachments = visibleMessage.attachmentIDs.compactMap { TSAttachment.fetch(uniqueId: $0, transaction: transaction) as? TSAttachmentPointer } let attachments = visibleMessage.attachmentIDs.compactMap { TSAttachment.fetch(uniqueId: $0) as? TSAttachmentPointer }
let attachmentsToDownload = attachments.filter { !$0.isDownloaded } let attachmentsToDownload = attachments.filter { !$0.isDownloaded }
attachmentsToDownload.forEach { attachment in attachmentsToDownload.forEach { attachment in
if let attachmentID = attachment.uniqueId, let job = storage.getAttachmentDownloadJob(for: attachmentID, with: transaction) { if let attachmentID = attachment.uniqueId, let job = storage.getAttachmentDownloadJob(for: attachmentID) {
attachmentDownloadJobs.append(job) attachmentDownloadJobs.append(job)
} }
} }
@ -106,21 +106,20 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
notificationContent.body = "You've got a new message" notificationContent.body = "You've got a new message"
default: break default: break
} }
if attachmentDownloadJobs.isEmpty {
self.handleSuccess(for: notificationContent)
} else {
let promises = attachmentDownloadJobs.map { $0.executeAsync() }
when(fulfilled: promises).map { attachments in
self.handleSuccess(for: notificationContent)
}.catch { error in
self.handleSuccess(for: notificationContent)
}.retainUntilComplete()
}
} catch { } catch {
self.handleFailure(for: notificationContent) self.handleFailure(for: notificationContent)
} }
} }
// if attachmentDownloadJobs.isEmpty {
// self.handleSuccess(for: notificationContent)
// } else {
// let promises = attachmentDownloadJobs.map { $0.executeAsync() }
// when(fulfilled: promises).map { attachments in
// self.handleSuccess(for: notificationContent)
// }.catch { error in
// self.handleSuccess(for: notificationContent)
// }.retainUntilComplete()
// }
} }
} }
@ -164,7 +163,6 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
override public func serviceExtensionTimeWillExpire() { override public func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system. // Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
print("serviceExtensionTimeWillExpire")
let userInfo: [String:Any] = [ NotificationServiceExtension.isFromRemoteKey : true ] let userInfo: [String:Any] = [ NotificationServiceExtension.isFromRemoteKey : true ]
let notificationContent = self.notificationContent! let notificationContent = self.notificationContent!
notificationContent.userInfo = userInfo notificationContent.userInfo = userInfo