Improve restoration from seed

pull/61/head
Niels Andriesse 6 years ago
parent a6be41a2f9
commit 3c87da738d

@ -131,9 +131,19 @@ public final class LokiPublicChatPoller : NSObject {
} else { } else {
signalQuote = nil signalQuote = nil
} }
var attachmentIDs: [String] = []
// TODO: Restore attachments
let signalLinkPreview: OWSLinkPreview?
if let linkPreview = message.attachments.first(where: { $0.kind == .linkPreview }) {
let attachment = TSAttachmentPointer(serverId: linkPreview.serverID, encryptionKey: nil, byteCount: UInt32(linkPreview.size), contentType: linkPreview.contentType, sourceFilename: linkPreview.fileName, caption: linkPreview.caption, albumMessageId: nil)
attachment.save()
signalLinkPreview = OWSLinkPreview(urlString: linkPreview.linkPreviewURL!, title: linkPreview.linkPreviewTitle!, imageAttachmentId: attachment.uniqueId!, isDirectAttachment: false)
} else {
signalLinkPreview = nil
}
let body = (message.body == message.timestamp.description) ? "" : message.body // Workaround for the fact that the back-end doesn't accept messages without a body let body = (message.body == message.timestamp.description) ? "" : message.body // Workaround for the fact that the back-end doesn't accept messages without a body
let message = TSOutgoingMessage(outgoingMessageWithTimestamp: message.timestamp, in: thread, messageBody: body, attachmentIds: [], expiresInSeconds: 0, let message = TSOutgoingMessage(outgoingMessageWithTimestamp: message.timestamp, in: thread, messageBody: body, attachmentIds: NSMutableArray(array: attachmentIDs), expiresInSeconds: 0,
expireStartedAt: 0, isVoiceMessage: false, groupMetaMessage: .deliver, quotedMessage: signalQuote, contactShare: nil, linkPreview: nil) expireStartedAt: 0, isVoiceMessage: false, groupMetaMessage: .deliver, quotedMessage: signalQuote, contactShare: nil, linkPreview: signalLinkPreview)
storage.dbReadWriteConnection.readWrite { transaction in storage.dbReadWriteConnection.readWrite { transaction in
message.update(withSentRecipient: publicChat.server, wasSentByUD: false, transaction: transaction) message.update(withSentRecipient: publicChat.server, wasSentByUD: false, transaction: transaction)
message.saveGroupChatServerID(messageServerID, in: transaction) message.saveGroupChatServerID(messageServerID, in: transaction)

@ -366,7 +366,7 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
return [@"👤 " stringByAppendingString:self.contactShare.name.displayName]; return [@"👤 " stringByAppendingString:self.contactShare.name.displayName];
} }
} else { } else {
OWSFailDebug(@"message has neither body nor attachment."); // OWSFailDebug(@"message has neither body nor attachment.");
// TODO: We should do better here. // TODO: We should do better here.
return @""; return @"";
} }

Loading…
Cancel
Save