Fix incorrect open group message timestamp

This commit is contained in:
nielsandriesse 2020-12-01 16:25:31 +11:00
parent e8661cf4d7
commit 71df0b84f0
2 changed files with 5 additions and 7 deletions

View File

@ -11,16 +11,12 @@ internal extension OpenGroupMessage {
let quote: OpenGroupMessage.Quote? = {
if let quote = message.quote {
guard quote.isValid else { return nil }
var quotedMessageServerID: UInt64?
TSDatabaseSecondaryIndexes.enumerateMessages(withTimestamp: quote.timestamp!, with: { _, key, _ in
guard let message = TSInteraction.fetch(uniqueId: key, transaction: transaction) as? TSMessage else { return }
quotedMessageServerID = message.openGroupServerMessageID
}, using: transaction)
let quotedMessageBody = quote.text ?? String(quote.timestamp!) // The back-end doesn't accept messages without a body so we use this as a workaround
if let quotedAttachmentID = quote.attachmentID, let index = attachmentIDs.firstIndex(of: quotedAttachmentID) {
attachmentIDs.remove(at: index)
}
return OpenGroupMessage.Quote(quotedMessageTimestamp: quote.timestamp!, quoteePublicKey: quote.publicKey!, quotedMessageBody: quotedMessageBody, quotedMessageServerID: quotedMessageServerID)
// FIXME: For some reason the server always returns a 500 if quotedMessageServerID is set...
return OpenGroupMessage.Quote(quotedMessageTimestamp: quote.timestamp!, quoteePublicKey: quote.publicKey!, quotedMessageBody: quotedMessageBody, quotedMessageServerID: nil)
} else {
return nil
}

View File

@ -246,7 +246,9 @@ public final class MessageSender : NSObject {
internal static func sendToOpenGroupDestination(_ destination: Message.Destination, message: Message, using transaction: Any) -> Promise<Void> {
let (promise, seal) = Promise<Void>.pending()
let storage = Configuration.shared.storage
message.sentTimestamp = NSDate.millisecondTimestamp()
if message.sentTimestamp == nil { // Visible messages will already have their sent timestamp set
message.sentTimestamp = NSDate.millisecondTimestamp()
}
message.sender = storage.getUserPublicKey()
switch destination {
case .contact(_): preconditionFailure()