mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
WIP
This commit is contained in:
parent
f6b78f9e99
commit
a88ce33ee0
|
@ -1,5 +1,7 @@
|
||||||
import SessionUtilitiesKit
|
import SessionUtilitiesKit
|
||||||
|
|
||||||
|
// TODO: Cancel when a message is deleted
|
||||||
|
|
||||||
@objc(SNMessageSendJob)
|
@objc(SNMessageSendJob)
|
||||||
public final class MessageSendJob : NSObject, Job, NSCoding { // NSObject/NSCoding conformance is needed for YapDatabase compatibility
|
public final class MessageSendJob : NSObject, Job, NSCoding { // NSObject/NSCoding conformance is needed for YapDatabase compatibility
|
||||||
public let message: Message
|
public let message: Message
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
outgoingMessageWithTimestamp: visibleMessage.sentTimestamp!,
|
outgoingMessageWithTimestamp: visibleMessage.sentTimestamp!,
|
||||||
in: thread,
|
in: thread,
|
||||||
messageBody: visibleMessage.text,
|
messageBody: visibleMessage.text,
|
||||||
attachmentIds: NSMutableArray(array: visibleMessage.attachmentIDs),
|
attachmentIds: NSMutableArray(),
|
||||||
expiresInSeconds: expiration,
|
expiresInSeconds: expiration,
|
||||||
expireStartedAt: 0,
|
expireStartedAt: 0,
|
||||||
isVoiceMessage: false,
|
isVoiceMessage: false,
|
||||||
|
|
|
@ -47,6 +47,10 @@ public final class VisibleMessage : Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func toProto() -> SNProtoContent? {
|
public override func toProto() -> SNProtoContent? {
|
||||||
|
preconditionFailure("Use toProto(using:) instead.")
|
||||||
|
}
|
||||||
|
|
||||||
|
public func toProto(using transaction: YapDatabaseReadWriteTransaction) -> SNProtoContent? {
|
||||||
let proto = SNProtoContent.builder()
|
let proto = SNProtoContent.builder()
|
||||||
let dataMessage: SNProtoDataMessage.SNProtoDataMessageBuilder
|
let dataMessage: SNProtoDataMessage.SNProtoDataMessageBuilder
|
||||||
if let profile = profile, let profileProto = profile.toProto() {
|
if let profile = profile, let profileProto = profile.toProto() {
|
||||||
|
@ -55,13 +59,13 @@ public final class VisibleMessage : Message {
|
||||||
dataMessage = SNProtoDataMessage.builder()
|
dataMessage = SNProtoDataMessage.builder()
|
||||||
}
|
}
|
||||||
if let text = text { dataMessage.setBody(text) }
|
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 !attachments.allSatisfy({ $0.isUploaded }) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
preconditionFailure("Sending a message before all associated attachments have been uploaded.")
|
preconditionFailure("Sending a message before all associated attachments have been uploaded.")
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
let attachmentProtos = attachments.compactMap { TSAttachmentStream.buildProto(forAttachmentId: $0.uniqueId!) }
|
let attachmentProtos = attachments.compactMap { $0.buildProto() }
|
||||||
dataMessage.setAttachments(attachmentProtos)
|
dataMessage.setAttachments(attachmentProtos)
|
||||||
if let quote = quote, let quoteProto = quote.toProto() { dataMessage.setQuote(quoteProto) }
|
if let quote = quote, let quoteProto = quote.toProto() { dataMessage.setQuote(quoteProto) }
|
||||||
if let linkPreview = linkPreview, let linkPreviewProto = linkPreview.toProto() { dataMessage.setPreview([ linkPreviewProto ]) }
|
if let linkPreview = linkPreview, let linkPreviewProto = linkPreview.toProto() { dataMessage.setPreview([ linkPreviewProto ]) }
|
||||||
|
|
|
@ -84,7 +84,13 @@ public final class MessageSender : NSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Convert it to protobuf
|
// 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
|
// Serialize the protobuf
|
||||||
let plaintext: Data
|
let plaintext: Data
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -22,6 +22,7 @@ extension MessageSender : SharedSenderKeysDelegate {
|
||||||
stream.save(with: transaction)
|
stream.save(with: transaction)
|
||||||
}
|
}
|
||||||
message.attachmentIDs = streams.map { $0.uniqueId! }
|
message.attachmentIDs = streams.map { $0.uniqueId! }
|
||||||
|
tsMessage.attachmentIds.addObjects(from: message.attachmentIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc(send:withAttachments:inThread:usingTransaction:)
|
@objc(send:withAttachments:inThread:usingTransaction:)
|
||||||
|
|
Loading…
Reference in a new issue