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 override var isSelfSendValid: Bool {
if case .answer = kind { return true }
if case .endCall = kind { return true }
return false
switch kind {
case .answer, .endCall: return true
default: return false
}
}
public override var shouldBeRetryable: Bool { true }
// NOTE: Multiple ICE candidates may be batched together for performance
// MARK: Kind

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

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

@ -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
// 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.
if let message = message as? ClosedGroupControlMessage, case .new = message.kind {
// Allow duplicates in this case to avoid the following situation:
if message.shouldBeRetryable {
// Allow duplicates for new closed group & encryption key pair update:
// The app performed a background poll or received a push notification
// This method was invoked and the received message timestamps table was updated
// Processing wasn't finished
// 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
} else {
guard !Set(storage.getReceivedMessageTimestamps(using: transaction)).contains(envelope.timestamp) || isRetry else { throw Error.duplicateMessage }

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

Loading…
Cancel
Save