Fix coding issues
This commit is contained in:
parent
19c29b2bf9
commit
5e476e8330
|
@ -32,14 +32,19 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
|
|||
// MARK: Coding
|
||||
public init?(coder: NSCoder) {
|
||||
guard let attachmentID = coder.decodeObject(forKey: "attachmentID") as! String?,
|
||||
let tsIncomingMessageID = coder.decodeObject(forKey: "tsIncomingMessageID") as! String? else { return nil }
|
||||
let tsIncomingMessageID = coder.decodeObject(forKey: "tsIncomingMessageID") as! String?,
|
||||
let id = coder.decodeObject(forKey: "id") as! String? else { return nil }
|
||||
self.attachmentID = attachmentID
|
||||
self.tsIncomingMessageID = tsIncomingMessageID
|
||||
self.id = id
|
||||
self.failureCount = coder.decodeObject(forKey: "failureCount") as! UInt? ?? 0
|
||||
}
|
||||
|
||||
public func encode(with coder: NSCoder) {
|
||||
coder.encode(attachmentID, forKey: "attachmentID")
|
||||
coder.encode(tsIncomingMessageID, forKey: "tsIncomingMessageID")
|
||||
coder.encode(id, forKey: "id")
|
||||
coder.encode(failureCount, forKey: "failureCount")
|
||||
}
|
||||
|
||||
// MARK: Running
|
||||
|
|
|
@ -30,14 +30,19 @@ public final class AttachmentUploadJob : NSObject, Job, NSCoding { // NSObject/N
|
|||
// MARK: Coding
|
||||
public init?(coder: NSCoder) {
|
||||
guard let attachmentID = coder.decodeObject(forKey: "attachmentID") as! String?,
|
||||
let threadID = coder.decodeObject(forKey: "threadID") as! String? else { return nil }
|
||||
let threadID = coder.decodeObject(forKey: "threadID") as! String?,
|
||||
let id = coder.decodeObject(forKey: "id") as! String? else { return nil }
|
||||
self.attachmentID = attachmentID
|
||||
self.threadID = threadID
|
||||
self.id = id
|
||||
self.failureCount = coder.decodeObject(forKey: "failureCount") as! UInt? ?? 0
|
||||
}
|
||||
|
||||
public func encode(with coder: NSCoder) {
|
||||
coder.encode(attachmentID, forKey: "attachmentID")
|
||||
coder.encode(threadID, forKey: "threadID")
|
||||
coder.encode(id, forKey: "id")
|
||||
coder.encode(failureCount, forKey: "failureCount")
|
||||
}
|
||||
|
||||
// MARK: Running
|
||||
|
|
|
@ -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!
|
||||
|
|
Loading…
Reference in New Issue