Fix closed group message status handling

pull/318/head
Niels Andriesse 4 years ago
parent 3cf87d40ab
commit 21810a0c4c

@ -79,7 +79,7 @@ public final class MessageSender : NSObject {
// Stop here if this is a self-send // Stop here if this is a self-send
guard !isSelfSend else { guard !isSelfSend else {
storage.withAsync({ transaction in storage.withAsync({ transaction in
MessageSender.handleSuccessfulMessageSend(message, using: transaction) MessageSender.handleSuccessfulMessageSend(message, to: destination, using: transaction)
}, completion: { }) }, completion: { })
seal.fulfill(()) seal.fulfill(())
return promise return promise
@ -192,7 +192,7 @@ public final class MessageSender : NSObject {
// Handle completion // Handle completion
let _ = promise.done(on: DispatchQueue.main) { let _ = promise.done(on: DispatchQueue.main) {
storage.withAsync({ transaction in storage.withAsync({ transaction in
MessageSender.handleSuccessfulMessageSend(message, using: transaction) MessageSender.handleSuccessfulMessageSend(message, to: destination,X using: transaction)
}, completion: { }) }, completion: { })
if case .contact(_) = destination, message is VisibleMessage, !isSelfSend { if case .contact(_) = destination, message is VisibleMessage, !isSelfSend {
NotificationCenter.default.post(name: .messageSent, object: NSNumber(value: message.sentTimestamp!)) NotificationCenter.default.post(name: .messageSent, object: NSNumber(value: message.sentTimestamp!))
@ -252,7 +252,7 @@ public final class MessageSender : NSObject {
// Handle completion // Handle completion
let _ = promise.done(on: DispatchQueue.global(qos: .userInitiated)) { let _ = promise.done(on: DispatchQueue.global(qos: .userInitiated)) {
storage.withAsync({ transaction in storage.withAsync({ transaction in
MessageSender.handleSuccessfulMessageSend(message, using: transaction) MessageSender.handleSuccessfulMessageSend(message, to: destination, using: transaction)
}, completion: { }) }, completion: { })
} }
// Return // Return

@ -74,11 +74,18 @@ extension MessageSender : SharedSenderKeysDelegate {
// MARK: - Success & Failure Handling // MARK: - Success & Failure Handling
public static func handleSuccessfulMessageSend(_ message: Message, using transaction: Any) { public static func handleSuccessfulMessageSend(_ message: Message, to destination: Message.Destination, using transaction: Any) {
guard let tsMessage = TSOutgoingMessage.find(withTimestamp: message.sentTimestamp!) else { return } guard let tsMessage = TSOutgoingMessage.find(withTimestamp: message.sentTimestamp!) else { return }
tsMessage.openGroupServerMessageID = message.openGroupServerMessageID ?? 0 tsMessage.openGroupServerMessageID = message.openGroupServerMessageID ?? 0
tsMessage.isOpenGroupMessage = tsMessage.openGroupServerMessageID != 0 tsMessage.isOpenGroupMessage = tsMessage.openGroupServerMessageID != 0
tsMessage.update(withSentRecipient: message.recipient!, wasSentByUD: true, transaction: transaction as! YapDatabaseReadWriteTransaction) var recipients = [ message.recipient! ]
if case .closedGroup(_) = destination, let threadID = message.threadID, // threadID should always be set at this point
let thread = TSGroupThread.fetch(uniqueId: threadID, transaction: transaction as! YapDatabaseReadTransaction), thread.usesSharedSenderKeys {
recipients = thread.groupModel.groupMemberIds
}
recipients.forEach { recipient in
tsMessage.update(withSentRecipient: recipient, wasSentByUD: true, transaction: transaction as! YapDatabaseReadWriteTransaction)
}
OWSDisappearingMessagesJob.shared().startAnyExpiration(for: tsMessage, expirationStartedAt: NSDate.millisecondTimestamp(), transaction: transaction as! YapDatabaseReadWriteTransaction) OWSDisappearingMessagesJob.shared().startAnyExpiration(for: tsMessage, expirationStartedAt: NSDate.millisecondTimestamp(), transaction: transaction as! YapDatabaseReadWriteTransaction)
} }

Loading…
Cancel
Save