WIP
This commit is contained in:
parent
f6b78f9e99
commit
a88ce33ee0
|
@ -1,5 +1,7 @@
|
|||
import SessionUtilitiesKit
|
||||
|
||||
// TODO: Cancel when a message is deleted
|
||||
|
||||
@objc(SNMessageSendJob)
|
||||
public final class MessageSendJob : NSObject, Job, NSCoding { // NSObject/NSCoding conformance is needed for YapDatabase compatibility
|
||||
public let message: Message
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
outgoingMessageWithTimestamp: visibleMessage.sentTimestamp!,
|
||||
in: thread,
|
||||
messageBody: visibleMessage.text,
|
||||
attachmentIds: NSMutableArray(array: visibleMessage.attachmentIDs),
|
||||
attachmentIds: NSMutableArray(),
|
||||
expiresInSeconds: expiration,
|
||||
expireStartedAt: 0,
|
||||
isVoiceMessage: false,
|
||||
|
|
|
@ -47,6 +47,10 @@ public final class VisibleMessage : Message {
|
|||
}
|
||||
|
||||
public override func toProto() -> SNProtoContent? {
|
||||
preconditionFailure("Use toProto(using:) instead.")
|
||||
}
|
||||
|
||||
public func toProto(using transaction: YapDatabaseReadWriteTransaction) -> SNProtoContent? {
|
||||
let proto = SNProtoContent.builder()
|
||||
let dataMessage: SNProtoDataMessage.SNProtoDataMessageBuilder
|
||||
if let profile = profile, let profileProto = profile.toProto() {
|
||||
|
@ -55,13 +59,13 @@ public final class VisibleMessage : Message {
|
|||
dataMessage = SNProtoDataMessage.builder()
|
||||
}
|
||||
if let text = text { dataMessage.setBody(text) }
|
||||
let attachments = attachmentIDs.compactMap { TSAttachmentStream.fetch(uniqueId: $0) }
|
||||
let attachments = attachmentIDs.compactMap { TSAttachmentStream.fetch(uniqueId: $0, transaction: transaction) }
|
||||
if !attachments.allSatisfy({ $0.isUploaded }) {
|
||||
#if DEBUG
|
||||
preconditionFailure("Sending a message before all associated attachments have been uploaded.")
|
||||
#endif
|
||||
}
|
||||
let attachmentProtos = attachments.compactMap { TSAttachmentStream.buildProto(forAttachmentId: $0.uniqueId!) }
|
||||
let attachmentProtos = attachments.compactMap { $0.buildProto() }
|
||||
dataMessage.setAttachments(attachmentProtos)
|
||||
if let quote = quote, let quoteProto = quote.toProto() { dataMessage.setQuote(quoteProto) }
|
||||
if let linkPreview = linkPreview, let linkPreviewProto = linkPreview.toProto() { dataMessage.setPreview([ linkPreviewProto ]) }
|
||||
|
|
|
@ -84,7 +84,13 @@ public final class MessageSender : NSObject {
|
|||
}
|
||||
}
|
||||
// Convert it to protobuf
|
||||
guard let proto = message.toProto() else { seal.reject(Error.protoConversionFailed); return promise }
|
||||
let protoOrNil: SNProtoContent?
|
||||
if let message = message as? VisibleMessage {
|
||||
protoOrNil = message.toProto(using: transaction as! YapDatabaseReadWriteTransaction) // Needed because of how TSAttachmentStream works
|
||||
} else {
|
||||
protoOrNil = message.toProto()
|
||||
}
|
||||
guard let proto = protoOrNil else { seal.reject(Error.protoConversionFailed); return promise }
|
||||
// Serialize the protobuf
|
||||
let plaintext: Data
|
||||
do {
|
||||
|
|
|
@ -22,6 +22,7 @@ extension MessageSender : SharedSenderKeysDelegate {
|
|||
stream.save(with: transaction)
|
||||
}
|
||||
message.attachmentIDs = streams.map { $0.uniqueId! }
|
||||
tsMessage.attachmentIds.addObjects(from: message.attachmentIDs)
|
||||
}
|
||||
|
||||
@objc(send:withAttachments:inThread:usingTransaction:)
|
||||
|
|
Loading…
Reference in New Issue