Quick fix sync transcript duplication
This commit is contained in:
parent
8a30bab444
commit
1261be1d08
|
@ -2,6 +2,7 @@ import PromiseKit
|
|||
|
||||
@objc(LKAPI)
|
||||
public final class LokiAPI : NSObject {
|
||||
private static var syncMessageTimestamps: [String:Set<UInt64>] = [:]
|
||||
public static var lastDeviceLinkUpdate: [String:Date] = [:] // Hex encoded public key to date
|
||||
@objc public static var userHexEncodedPublicKeyCache: [String:Set<String>] = [:] // Thread ID to set of user hex encoded public keys
|
||||
|
||||
|
@ -117,7 +118,6 @@ public final class LokiAPI : NSObject {
|
|||
let deviceLinks = storage.getDeviceLinks(for: masterHexEncodedPublicKey, in: transaction)
|
||||
let slaveDestinations = deviceLinks.map { Destination(hexEncodedPublicKey: $0.slave.hexEncodedPublicKey, kind: .slave) }
|
||||
destinations.append(contentsOf: slaveDestinations)
|
||||
destinations = destinations.filter { $0.hexEncodedPublicKey != userHexEncodedPublicKey }
|
||||
seal.fulfill(destinations)
|
||||
}
|
||||
}
|
||||
|
@ -263,6 +263,14 @@ public final class LokiAPI : NSObject {
|
|||
return envelope
|
||||
}
|
||||
}
|
||||
|
||||
@objc public static func isDuplicateSyncMessage(_ syncMessage: SSKProtoSyncMessageSent, from hexEncodedPublicKey: String) -> Bool {
|
||||
var timestamps: Set<UInt64> = syncMessageTimestamps[hexEncodedPublicKey] ?? []
|
||||
let result = timestamps.contains(syncMessage.timestamp)
|
||||
timestamps.insert(syncMessage.timestamp)
|
||||
syncMessageTimestamps[hexEncodedPublicKey] = timestamps
|
||||
return result
|
||||
}
|
||||
|
||||
// MARK: Message Hash Caching
|
||||
private static func getLastMessageHashValue(for target: LokiAPITarget) -> String? {
|
||||
|
|
|
@ -27,7 +27,7 @@ public final class LokiStorageAPI : LokiDotNetAPI {
|
|||
public static func getDeviceLinks(associatedWith hexEncodedPublicKeys: Set<String>) -> Promise<Set<DeviceLink>> {
|
||||
let hexEncodedPublicKeysDescription = "[ \(hexEncodedPublicKeys.joined(separator: ", ")) ]"
|
||||
print("[Loki] Getting device links for: \(hexEncodedPublicKeysDescription).")
|
||||
return getAuthToken(for: server).then(on: DispatchQueue.main) { token -> Promise<Set<DeviceLink>> in
|
||||
return getAuthToken(for: server).then(on: DispatchQueue.global()) { token -> Promise<Set<DeviceLink>> in
|
||||
let queryParameters = "ids=\(hexEncodedPublicKeys.map { "@\($0)" }.joined(separator: ","))&include_user_annotations=1"
|
||||
let url = URL(string: "\(server)/users?\(queryParameters)")!
|
||||
let request = TSRequest(url: url)
|
||||
|
|
|
@ -497,7 +497,7 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
|
|||
|
||||
#pragma mark - Group Chat
|
||||
|
||||
- (BOOL) isGroupChatMessage {
|
||||
- (BOOL)isGroupChatMessage {
|
||||
return self.groupChatServerID > 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -433,6 +433,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
OWSLogInfo(@"handling content: <Content: %@>", [self descriptionForContent:contentProto]);
|
||||
|
||||
// Loki: Workaround for duplicate sync transcript issue
|
||||
if (contentProto.syncMessage != nil && contentProto.syncMessage.sent != nil) {
|
||||
BOOL isDuplicate = [LKAPI isDuplicateSyncMessage:contentProto.syncMessage.sent from:envelope.source];
|
||||
if (isDuplicate) { return; }
|
||||
}
|
||||
|
||||
// Loki: Handle device linking message if needed
|
||||
if (contentProto.lokiDeviceLinkMessage != nil) {
|
||||
NSString *masterHexEncodedPublicKey = contentProto.lokiDeviceLinkMessage.masterHexEncodedPublicKey;
|
||||
|
|
Loading…
Reference in New Issue