fix an issue where closed groups stop to be updated part 1

pull/614/head
Ryan Zhao 4 years ago
parent a12e86a36b
commit f9bb1517a1

@ -9,11 +9,14 @@ public final class CallMessage : ControlMessage {
public var sdps: [String]? public var sdps: [String]?
public override var isSelfSendValid: Bool { public override var isSelfSendValid: Bool {
if case .answer = kind { return true } switch kind {
if case .endCall = kind { return true } case .answer, .endCall: return true
return false default: return false
}
} }
public override var shouldBeRetryable: Bool { true }
// NOTE: Multiple ICE candidates may be batched together for performance // NOTE: Multiple ICE candidates may be batched together for performance
// MARK: Kind // MARK: Kind

@ -12,6 +12,13 @@ public final class ClosedGroupControlMessage : ControlMessage {
public override var isSelfSendValid: Bool { true } public override var isSelfSendValid: Bool { true }
public override var shouldBeRetryable: Bool {
switch kind {
case .new, .encryptionKeyPair: return true
default: return false
}
}
// MARK: Kind // MARK: Kind
public enum Kind : CustomStringConvertible { public enum Kind : CustomStringConvertible {
case new(publicKey: Data, name: String, encryptionKeyPair: ECKeyPair, members: [Data], admins: [Data], expirationTimer: UInt32) case new(publicKey: Data, name: String, encryptionKeyPair: ECKeyPair, members: [Data], admins: [Data], expirationTimer: UInt32)

@ -16,6 +16,8 @@ public class Message : NSObject, NSCoding { // NSObject/NSCoding conformance is
public var ttl: UInt64 { 14 * 24 * 60 * 60 * 1000 } public var ttl: UInt64 { 14 * 24 * 60 * 60 * 1000 }
public var isSelfSendValid: Bool { false } public var isSelfSendValid: Bool { false }
public var shouldBeRetryable: Bool { false }
public override init() { } public override init() { }
// MARK: Validation // MARK: Validation

@ -168,14 +168,14 @@ public enum MessageReceiver {
// If the message failed to process the first time around we retry it later (if the error is retryable). In this case the timestamp // If the message failed to process the first time around we retry it later (if the error is retryable). In this case the timestamp
// will already be in the database but we don't want to treat the message as a duplicate. The isRetry flag is a simple workaround // will already be in the database but we don't want to treat the message as a duplicate. The isRetry flag is a simple workaround
// for this issue. // for this issue.
if let message = message as? ClosedGroupControlMessage, case .new = message.kind { if message.shouldBeRetryable {
// Allow duplicates in this case to avoid the following situation: // Allow duplicates for new closed group & encryption key pair update:
// The app performed a background poll or received a push notification // The app performed a background poll or received a push notification
// This method was invoked and the received message timestamps table was updated // This method was invoked and the received message timestamps table was updated
// Processing wasn't finished // Processing wasn't finished
// The user doesn't see the new closed group // The user doesn't see the new closed group
} else if message.isKind(of: CallMessage.self) {
// Allow duplicates for all call messages // Allow duplicates for all call messages,
// The double checking will be done on message handling to make sure the messages are for the same ongoing call // The double checking will be done on message handling to make sure the messages are for the same ongoing call
} else { } else {
guard !Set(storage.getReceivedMessageTimestamps(using: transaction)).contains(envelope.timestamp) || isRetry else { throw Error.duplicateMessage } guard !Set(storage.getReceivedMessageTimestamps(using: transaction)).contains(envelope.timestamp) || isRetry else { throw Error.duplicateMessage }

@ -110,6 +110,7 @@ extension Storage {
if now >= expirationDate { if now >= expirationDate {
Storage.writeSync { transaction in Storage.writeSync { transaction in
self.removeLastMessageHashInfo(for: snode, associatedWith: publicKey, using: transaction) self.removeLastMessageHashInfo(for: snode, associatedWith: publicKey, using: transaction)
self.setReceivedMessages(to: Set(), for: publicKey, using: transaction)
} }
} }
} }

Loading…
Cancel
Save