|
|
|
@ -5,12 +5,14 @@ public extension MessageSender {
|
|
|
|
|
@objc(send:withAttachments:inThread:usingTransaction:)
|
|
|
|
|
static func send(_ message: Message, with attachments: [SignalAttachment] = [], in thread: TSThread, using transaction: YapDatabaseReadWriteTransaction) {
|
|
|
|
|
if let message = message as? VisibleMessage {
|
|
|
|
|
let streams = attachments.map {
|
|
|
|
|
return TSAttachmentStream(contentType: $0.mimeType, byteCount: UInt32($0.dataLength), sourceFilename: $0.sourceFilename,
|
|
|
|
|
caption: $0.captionText, albumMessageId: nil
|
|
|
|
|
)
|
|
|
|
|
var streams: [TSAttachmentStream] = []
|
|
|
|
|
attachments.forEach {
|
|
|
|
|
let stream = TSAttachmentStream(contentType: $0.mimeType, byteCount: UInt32($0.dataLength), sourceFilename: $0.sourceFilename,
|
|
|
|
|
caption: $0.captionText, albumMessageId: nil)
|
|
|
|
|
streams.append(stream)
|
|
|
|
|
stream.write($0.dataSource)
|
|
|
|
|
stream.save(with: transaction)
|
|
|
|
|
}
|
|
|
|
|
streams.forEach { $0.save(with: transaction) }
|
|
|
|
|
message.attachmentIDs = streams.map { $0.uniqueId! }
|
|
|
|
|
}
|
|
|
|
|
message.threadID = thread.uniqueId!
|
|
|
|
|