From 33c239eae2447614366f146d61281346d2cb4e4e Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 20 Jan 2023 17:04:21 +1100 Subject: [PATCH] WIP: debug new endpoints --- .../Jobs/Types/DisappearingMessagesJob.swift | 25 +++++++++++++------ SessionSnodeKit/SnodeAPI.swift | 4 +-- SessionUtilitiesKit/General/Features.swift | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/SessionMessagingKit/Jobs/Types/DisappearingMessagesJob.swift b/SessionMessagingKit/Jobs/Types/DisappearingMessagesJob.swift index 82736c870..3d87d1e3f 100644 --- a/SessionMessagingKit/Jobs/Types/DisappearingMessagesJob.swift +++ b/SessionMessagingKit/Jobs/Types/DisappearingMessagesJob.swift @@ -4,6 +4,7 @@ import Foundation import GRDB import SessionUtilitiesKit import SessionSnodeKit +import PromiseKit public enum DisappearingMessagesJob: JobExecutor { public static let maxFailureCount: Int = -1 @@ -106,35 +107,45 @@ public extension DisappearingMessagesJob { // If there were no changes then none of the provided `interactionIds` are expiring messages guard (changeCount ?? 0) > 0 else { return nil } + let userPublicKey: String = getUserHexEncodedPublicKey(db) + interactionExpirationInfosByExpiresInSeconds.forEach { expiresInSeconds, expirationInfos in let expirationTimestampMs: Int64 = Int64(ceil(startedAtMs + expiresInSeconds * 1000)) SnodeAPI.updateExpiry( - publicKey: getUserHexEncodedPublicKey(db), + publicKey: userPublicKey, updatedExpiryMs: expirationTimestampMs, serverHashes: expirationInfos.map { $0.serverHash }, shortenOnly: true ).map { results in + print("Ryan Test expire: \(results)") var unchangedMessages: [String: UInt64] = [:] results.forEach { _, result in guard let unchanged = result.unchanged else { return } unchangedMessages.merge(unchanged) { (current, _) in current } } - + guard !unchangedMessages.isEmpty else { return } - + unchangedMessages.forEach { serverHash, serverExpirationTimestampMs in let expiresInSeconds: TimeInterval = (TimeInterval(serverExpirationTimestampMs) - startedAtMs) / 1000 - + _ = try? Interaction .filter(Interaction.Columns.serverHash == serverHash) .updateAll(db, Interaction.Columns.expiresInSeconds.set(to: expiresInSeconds)) } }.retainUntilComplete() - let swarm = SnodeAPI.swarmCache.wrappedValue[getUserHexEncodedPublicKey(db)] ?? [] - let snode = swarm.randomElement()! - SnodeAPI.getExpiries(from: snode, associatedWith: getUserHexEncodedPublicKey(db), of: expirationInfos.map { $0.serverHash }).retainUntilComplete() + SnodeAPI.getSwarm(for: userPublicKey) + .then2 { swarm -> Promise in + guard let snode = swarm.randomElement() else { return Promise(error: StorageError.objectNotFound) } + + return SnodeAPI.getExpiries(from: snode, associatedWith: getUserHexEncodedPublicKey(db), of: expirationInfos.map { $0.serverHash }) + .map{ result in + print("Ryan Test get_expiries: \(result)") + } + }.retainUntilComplete() + } return updateNextRunIfNeeded(db) diff --git a/SessionSnodeKit/SnodeAPI.swift b/SessionSnodeKit/SnodeAPI.swift index 3c2d6907e..47a226cc5 100644 --- a/SessionSnodeKit/SnodeAPI.swift +++ b/SessionSnodeKit/SnodeAPI.swift @@ -475,7 +475,7 @@ public final class SnodeAPI { SNLog("Getting swarm for: \((publicKey == getUserHexEncodedPublicKey()) ? "self" : publicKey).") let parameters: [String: Any] = [ - "pubKey": (Features.useTestnet ? publicKey.removingIdPrefixIfNeeded() : publicKey) + "pubKey": publicKey ] return getRandomSnode() @@ -510,7 +510,7 @@ public final class SnodeAPI { // Make the request let parameters: JSON = [ - "pubKey": Features.useTestnet ? publicKey.removingIdPrefixIfNeeded() : publicKey, + "pubKey": publicKey, "messages": serverHashes, "timestamp": timestamp, "pubkey_ed25519": ed25519PublicKey, diff --git a/SessionUtilitiesKit/General/Features.swift b/SessionUtilitiesKit/General/Features.swift index d23dabef6..e4f8088a9 100644 --- a/SessionUtilitiesKit/General/Features.swift +++ b/SessionUtilitiesKit/General/Features.swift @@ -2,5 +2,5 @@ @objc(SNFeatures) public final class Features : NSObject { public static let useOnionRequests = true - public static let useTestnet = false + public static let useTestnet = true }