Browse Source

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

This reverts commit 7295c14e17.
pull/500/head
ryanzhao 3 months ago
parent
commit
454003c027
  1. 2
      Podfile.lock
  2. 10
      SessionMessagingKit/Database/Storage+Jobs.swift
  3. 2
      SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift
  4. 3
      SessionMessagingKit/Storage.swift
  5. 28
      SessionNotificationServiceExtension/NotificationServiceExtension.swift

2
Podfile.lock

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

10
SessionMessagingKit/Database/Storage+Jobs.swift

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

2
SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift

@ -5,7 +5,7 @@ import PromiseKit
public final class PushNotificationAPI : NSObject {
// 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"
private static let maxRetryCount: UInt = 4
private static let tokenExpirationInterval: TimeInterval = 12 * 60 * 60

3
SessionMessagingKit/Storage.swift

@ -1,6 +1,5 @@
import PromiseKit
import Sodium
import YapDatabase
public protocol SessionMessagingKitStorageProtocol {
@ -34,7 +33,7 @@ public protocol SessionMessagingKitStorageProtocol {
func markJobAsFailed(_ job: Job, using transaction: Any)
func getAllPendingJobs(of type: Job.Type) -> [Job]
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 resumeMessageSendJobIfNeeded(_ messageSendJobID: String)
func isJobCanceled(_ job: Job) -> Bool

28
SessionNotificationServiceExtension/NotificationServiceExtension.swift

@ -34,9 +34,9 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
let envelope = try? MessageWrapper.unwrap(data: data), let envelopeAsData = try? envelope.serializedData() else {
return self.handleFailure(for: notificationContent)
}
var attachmentDownloadJobs: [AttachmentDownloadJob] = []
Storage.write { transaction in // Intentionally capture self
do {
var attachmentDownloadJobs: [AttachmentDownloadJob] = []
let (message, proto) = try MessageReceiver.parse(envelopeAsData, openGroupMessageServerID: nil, using: transaction)
let senderPublicKey = message.sender!
if (senderPublicKey == userPublicKey) {
@ -72,10 +72,10 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
// Store the notification ID for unsend requests to later cancel this notification
tsIncomingMessage.setNotificationIdentifier(request.identifier, transaction: transaction)
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 }
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)
}
}
@ -106,21 +106,20 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
notificationContent.body = "You've got a new message"
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 {
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() {
// 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.
print("serviceExtensionTimeWillExpire")
let userInfo: [String:Any] = [ NotificationServiceExtension.isFromRemoteKey : true ]
let notificationContent = self.notificationContent!
notificationContent.userInfo = userInfo

Loading…
Cancel
Save