Potentially fix attachment issue
This commit is contained in:
parent
1dc8a8270f
commit
73bbaf9ce7
|
@ -512,7 +512,6 @@
|
|||
C3471ECB2555356A00297E91 /* MessageSender+Encryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3471ECA2555356A00297E91 /* MessageSender+Encryption.swift */; };
|
||||
C3471ED42555386B00297E91 /* AESGCM.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5D72553860B00C340D1 /* AESGCM.swift */; };
|
||||
C3471F4C25553AB000297E91 /* MessageReceiver+Decryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3471F4B25553AB000297E91 /* MessageReceiver+Decryption.swift */; };
|
||||
C3471FA42555439E00297E91 /* Notification+MessageSender.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3471FA32555439E00297E91 /* Notification+MessageSender.swift */; };
|
||||
C34A977425A3E34A00852C71 /* ClosedGroupControlMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C34A977325A3E34A00852C71 /* ClosedGroupControlMessage.swift */; };
|
||||
C34C8F7423A7830B00D82669 /* SpaceMono-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C34C8F7323A7830A00D82669 /* SpaceMono-Bold.ttf */; };
|
||||
C352A2F525574B4700338F3E /* Job.swift in Sources */ = {isa = PBXBuildFile; fileRef = C352A2F425574B4700338F3E /* Job.swift */; };
|
||||
|
@ -1509,7 +1508,6 @@
|
|||
C33FDC1B255A581F00E217F9 /* OWSBackgroundTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSBackgroundTask.m; sourceTree = "<group>"; };
|
||||
C3471ECA2555356A00297E91 /* MessageSender+Encryption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MessageSender+Encryption.swift"; sourceTree = "<group>"; };
|
||||
C3471F4B25553AB000297E91 /* MessageReceiver+Decryption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MessageReceiver+Decryption.swift"; sourceTree = "<group>"; };
|
||||
C3471FA32555439E00297E91 /* Notification+MessageSender.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Notification+MessageSender.swift"; sourceTree = "<group>"; };
|
||||
C34A977325A3E34A00852C71 /* ClosedGroupControlMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClosedGroupControlMessage.swift; sourceTree = "<group>"; };
|
||||
C34C8F7323A7830A00D82669 /* SpaceMono-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SpaceMono-Bold.ttf"; sourceTree = "<group>"; };
|
||||
C352A2F425574B4700338F3E /* Job.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Job.swift; sourceTree = "<group>"; };
|
||||
|
@ -2445,7 +2443,6 @@
|
|||
C32C5ADE256DBF7F003C73A2 /* Read Tracking */,
|
||||
C32C5995256DAF85003C73A2 /* Typing Indicators */,
|
||||
B8D0A25825E367AC00C1835E /* Notification+MessageReceiver.swift */,
|
||||
C3471FA32555439E00297E91 /* Notification+MessageSender.swift */,
|
||||
C300A5F12554B09800555489 /* MessageSender.swift */,
|
||||
C38D5E8C2575011E00B6A65C /* MessageSender+ClosedGroups.swift */,
|
||||
B8D8F1EF256621180092EF10 /* MessageSender+Convenience.swift */,
|
||||
|
@ -4799,7 +4796,6 @@
|
|||
B8D0A25925E367AC00C1835E /* Notification+MessageReceiver.swift in Sources */,
|
||||
C32C5D2E256DD4EA003C73A2 /* TSUnreadIndicatorInteraction.m in Sources */,
|
||||
C32C599E256DB02B003C73A2 /* TypingIndicators.swift in Sources */,
|
||||
C3471FA42555439E00297E91 /* Notification+MessageSender.swift in Sources */,
|
||||
C32C5BEF256DC8EE003C73A2 /* OWSDisappearingMessagesJob.m in Sources */,
|
||||
C3A7222A2558C1E40043A11F /* DotNetAPI.swift in Sources */,
|
||||
C34A977425A3E34A00852C71 /* ClosedGroupControlMessage.swift in Sources */,
|
||||
|
|
|
@ -570,8 +570,6 @@ static const int kYapDatabaseRangeMaxLength = 25000;
|
|||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
OWSLogVerbose(@"");
|
||||
|
||||
// External database modifications (e.g. changes from another process such as the SAE)
|
||||
// are "flushed" using touchDbAsync when the app re-enters the foreground.
|
||||
}
|
||||
|
@ -585,8 +583,6 @@ static const int kYapDatabaseRangeMaxLength = 25000;
|
|||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
OWSLogVerbose(@"");
|
||||
|
||||
NSArray<NSNotification *> *notifications = notification.userInfo[OWSUIDatabaseConnectionNotificationsKey];
|
||||
OWSAssertDebug([notifications isKindOfClass:[NSArray class]]);
|
||||
|
||||
|
|
|
@ -49,7 +49,12 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
|
|||
|
||||
// MARK: Running
|
||||
public func execute() {
|
||||
guard let pointer = TSAttachmentPointer.fetch(uniqueId: attachmentID) else {
|
||||
if TSAttachment.fetch(uniqueId: attachmentID) is TSAttachmentStream {
|
||||
// FIXME: It's not clear * how * this happens, but apparently we can get to this point
|
||||
// from time to time with an already downloaded attachment.
|
||||
return handleSuccess()
|
||||
}
|
||||
guard let pointer = TSAttachment.fetch(uniqueId: attachmentID) as? TSAttachmentPointer else {
|
||||
return handleFailure(error: Error.noAttachment)
|
||||
}
|
||||
let storage = SNMessagingKitConfiguration.shared.storage
|
||||
|
|
|
@ -57,7 +57,7 @@ public final class AttachmentUploadJob : NSObject, Job, NSCoding { // NSObject/N
|
|||
|
||||
// MARK: Running
|
||||
public func execute() {
|
||||
guard let stream = TSAttachmentStream.fetch(uniqueId: attachmentID) else {
|
||||
guard let stream = TSAttachment.fetch(uniqueId: attachmentID) as? TSAttachmentStream else {
|
||||
return handleFailure(error: Error.noAttachment)
|
||||
}
|
||||
guard !stream.isUploaded else { return handleSuccess() } // Should never occur
|
||||
|
|
|
@ -64,7 +64,7 @@ public final class MessageSendJob : NSObject, Job, NSCoding { // NSObject/NSCodi
|
|||
let storage = SNMessagingKitConfiguration.shared.storage
|
||||
if let message = message as? VisibleMessage {
|
||||
guard TSOutgoingMessage.find(withTimestamp: message.sentTimestamp!) != nil else { return } // The message has been deleted
|
||||
let attachments = message.attachmentIDs.compactMap { TSAttachmentStream.fetch(uniqueId: $0) }
|
||||
let attachments = message.attachmentIDs.compactMap { TSAttachment.fetch(uniqueId: $0) as? TSAttachmentStream }
|
||||
let attachmentsToUpload = attachments.filter { !$0.isUploaded }
|
||||
attachmentsToUpload.forEach { attachment in
|
||||
if storage.getAttachmentUploadJob(for: attachment.uniqueId!) != nil {
|
||||
|
|
|
@ -45,7 +45,7 @@ public extension VisibleMessage {
|
|||
}
|
||||
let linkPreviewProto = SNProtoDataMessagePreview.builder(url: url)
|
||||
if let title = title { linkPreviewProto.setTitle(title) }
|
||||
if let attachmentID = attachmentID, let stream = TSAttachmentStream.fetch(uniqueId: attachmentID, transaction: transaction),
|
||||
if let attachmentID = attachmentID, let stream = TSAttachment.fetch(uniqueId: attachmentID, transaction: transaction) as? TSAttachmentStream,
|
||||
let attachmentProto = stream.buildProto() {
|
||||
linkPreviewProto.setImage(attachmentProto)
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public extension VisibleMessage {
|
|||
|
||||
private func addAttachmentsIfNeeded(to quoteProto: SNProtoDataMessageQuote.SNProtoDataMessageQuoteBuilder, using transaction: YapDatabaseReadWriteTransaction) {
|
||||
guard let attachmentID = attachmentID else { return }
|
||||
guard let stream = TSAttachmentStream.fetch(uniqueId: attachmentID, transaction: transaction), stream.isUploaded else {
|
||||
guard let stream = TSAttachment.fetch(uniqueId: attachmentID, transaction: transaction) as? TSAttachmentStream, stream.isUploaded else {
|
||||
#if DEBUG
|
||||
preconditionFailure("Sending a message before all associated attachments have been uploaded.")
|
||||
#else
|
||||
|
|
|
@ -86,7 +86,7 @@ public final class VisibleMessage : Message {
|
|||
}
|
||||
if let linkPreview = linkPreview, let linkPreviewProto = linkPreview.toProto(using: transaction) { dataMessage.setPreview([ linkPreviewProto ]) }
|
||||
// Attachments
|
||||
let attachments = attachmentIDs.compactMap { TSAttachmentStream.fetch(uniqueId: $0, transaction: transaction) }
|
||||
let attachments = attachmentIDs.compactMap { TSAttachment.fetch(uniqueId: $0, transaction: transaction) as? TSAttachmentStream }
|
||||
if !attachments.allSatisfy({ $0.isUploaded }) {
|
||||
#if DEBUG
|
||||
preconditionFailure("Sending a message before all associated attachments have been uploaded.")
|
||||
|
|
|
@ -29,7 +29,7 @@ internal extension OpenGroupMessage {
|
|||
// Link preview
|
||||
if let linkPreview = message.linkPreview {
|
||||
guard linkPreview.isValid, let attachmentID = linkPreview.attachmentID,
|
||||
let attachment = TSAttachmentStream.fetch(uniqueId: attachmentID, transaction: transaction) else { return nil }
|
||||
let attachment = TSAttachment.fetch(uniqueId: attachmentID, transaction: transaction) as? TSAttachmentStream else { return nil }
|
||||
if let index = attachmentIDs.firstIndex(of: attachmentID) {
|
||||
attachmentIDs.remove(at: index)
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ internal extension OpenGroupMessage {
|
|||
}
|
||||
// Attachments
|
||||
let attachments: [OpenGroupMessage.Attachment] = attachmentIDs.compactMap { attachmentID in
|
||||
guard let attachment = TSAttachmentStream.fetch(uniqueId: attachmentID, transaction: transaction) else { return nil } // Should never occur
|
||||
guard let attachment = TSAttachment.fetch(uniqueId: attachmentID, transaction: transaction) as? TSAttachmentStream else { return nil } // Should never occur
|
||||
let fileName = attachment.sourceFilename ?? UUID().uuidString
|
||||
let width = attachment.shouldHaveImageSize() ? attachment.imageSize().width : 0
|
||||
let height = attachment.shouldHaveImageSize() ? attachment.imageSize().height : 0
|
||||
|
|
|
@ -128,11 +128,6 @@ public final class MessageSender : NSObject {
|
|||
// Set the failure handler (need it here already for precondition failure handling)
|
||||
func handleFailure(with error: Swift.Error, using transaction: YapDatabaseReadWriteTransaction) {
|
||||
MessageSender.handleFailedMessageSend(message, with: error, using: transaction)
|
||||
if case .contact(_) = destination, message is VisibleMessage, !isSelfSend {
|
||||
DispatchQueue.main.async {
|
||||
NotificationCenter.default.post(name: .messageSendingFailed, object: NSNumber(value: message.sentTimestamp!))
|
||||
}
|
||||
}
|
||||
seal.reject(error)
|
||||
}
|
||||
// Validate the message
|
||||
|
@ -170,11 +165,6 @@ public final class MessageSender : NSObject {
|
|||
return promise
|
||||
}
|
||||
// Encrypt the serialized protobuf
|
||||
if case .contact(_) = destination, message is VisibleMessage, !isSelfSend {
|
||||
DispatchQueue.main.async {
|
||||
NotificationCenter.default.post(name: .encryptingMessage, object: NSNumber(value: message.sentTimestamp!))
|
||||
}
|
||||
}
|
||||
let ciphertext: Data
|
||||
do {
|
||||
switch destination {
|
||||
|
@ -211,11 +201,6 @@ public final class MessageSender : NSObject {
|
|||
return promise
|
||||
}
|
||||
// Calculate proof of work
|
||||
if case .contact(_) = destination, message is VisibleMessage, !isSelfSend {
|
||||
DispatchQueue.main.async {
|
||||
NotificationCenter.default.post(name: .calculatingMessagePoW, object: NSNumber(value: message.sentTimestamp!))
|
||||
}
|
||||
}
|
||||
let recipient = message.recipient!
|
||||
let base64EncodedData = wrappedMessage.base64EncodedString()
|
||||
guard let (timestamp, nonce) = ProofOfWork.calculate(ttl: message.ttl, publicKey: recipient, data: base64EncodedData) else {
|
||||
|
@ -224,11 +209,6 @@ public final class MessageSender : NSObject {
|
|||
return promise
|
||||
}
|
||||
// Send the result
|
||||
if case .contact(_) = destination, message is VisibleMessage, !isSelfSend {
|
||||
DispatchQueue.main.async {
|
||||
NotificationCenter.default.post(name: .messageSending, object: NSNumber(value: message.sentTimestamp!))
|
||||
}
|
||||
}
|
||||
let snodeMessage = SnodeMessage(recipient: recipient, data: base64EncodedData, ttl: message.ttl, timestamp: timestamp, nonce: nonce)
|
||||
SnodeAPI.sendMessage(snodeMessage).done(on: DispatchQueue.global(qos: .userInitiated)) { promises in
|
||||
var isSuccess = false
|
||||
|
@ -238,11 +218,6 @@ public final class MessageSender : NSObject {
|
|||
let _ = $0.done(on: DispatchQueue.global(qos: .userInitiated)) { _ in
|
||||
guard !isSuccess else { return } // Succeed as soon as the first promise succeeds
|
||||
isSuccess = true
|
||||
if case .contact(_) = destination, message is VisibleMessage, !isSelfSend {
|
||||
DispatchQueue.main.async {
|
||||
NotificationCenter.default.post(name: .messageSent, object: NSNumber(value: message.sentTimestamp!))
|
||||
}
|
||||
}
|
||||
storage.write(with: { transaction in
|
||||
MessageSender.handleSuccessfulMessageSend(message, to: destination, isSyncMessage: isSyncMessage, using: transaction)
|
||||
var shouldNotify = (message is VisibleMessage && !isSyncMessage)
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
|
||||
public extension Notification.Name {
|
||||
|
||||
static let encryptingMessage = Notification.Name("encryptingMessage")
|
||||
static let calculatingMessagePoW = Notification.Name("calculatingPoW")
|
||||
static let messageSending = Notification.Name("messageSending")
|
||||
static let messageSent = Notification.Name("messageSent")
|
||||
static let messageSendingFailed = Notification.Name("messageSendingFailed")
|
||||
}
|
||||
|
||||
@objc public extension NSNotification {
|
||||
|
||||
@objc static let encryptingMessage = Notification.Name.encryptingMessage.rawValue as NSString
|
||||
@objc static let calculatingMessagePoW = Notification.Name.calculatingMessagePoW.rawValue as NSString
|
||||
@objc static let messageSending = Notification.Name.messageSending.rawValue as NSString
|
||||
@objc static let messageSent = Notification.Name.messageSent.rawValue as NSString
|
||||
@objc static let messageSendingFailed = Notification.Name.messageSendingFailed.rawValue as NSString
|
||||
}
|
|
@ -15,13 +15,6 @@ extension MessageSender {
|
|||
let destination = Message.Destination.from(thread)
|
||||
let job = MessageSendJob(message: message, destination: destination)
|
||||
JobQueue.shared.add(job, using: transaction)
|
||||
guard let userPublicKey = SNMessagingKitConfiguration.shared.storage.getUserPublicKey() else { return }
|
||||
if case .contact(let recipientPublicKey) = destination, message is VisibleMessage, recipientPublicKey != userPublicKey {
|
||||
DispatchQueue.main.async {
|
||||
// Not strictly true, but nicer from a UX perspective
|
||||
NotificationCenter.default.post(name: .encryptingMessage, object: NSNumber(value: message.sentTimestamp!))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Non-Durable
|
||||
|
@ -46,7 +39,7 @@ extension MessageSender {
|
|||
}
|
||||
|
||||
public static func sendNonDurably(_ message: VisibleMessage, with attachmentIDs: [String], in thread: TSThread, using transaction: YapDatabaseReadWriteTransaction) -> Promise<Void> {
|
||||
let attachments = attachmentIDs.compactMap { TSAttachmentStream.fetch(uniqueId: $0, transaction: transaction) }
|
||||
let attachments = attachmentIDs.compactMap { TSAttachment.fetch(uniqueId: $0, transaction: transaction) as? TSAttachmentStream }
|
||||
let attachmentsToUpload = attachments.filter { !$0.isUploaded }
|
||||
let attachmentUploadPromises: [Promise<Void>] = attachmentsToUpload.map { stream in
|
||||
let openGroup = SNMessagingKitConfiguration.shared.storage.getOpenGroup(for: thread.uniqueId!)
|
||||
|
|
Loading…
Reference in New Issue