From 7ef47968e3077037606c6c2757fed4ee489d46d7 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 23 Aug 2019 16:25:12 +1000 Subject: [PATCH] Handle group chat token expiration --- SignalServiceKit/src/Loki/API/LokiGroupChatAPI.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SignalServiceKit/src/Loki/API/LokiGroupChatAPI.swift b/SignalServiceKit/src/Loki/API/LokiGroupChatAPI.swift index 92a7e4cd8..b3a7a8d6d 100644 --- a/SignalServiceKit/src/Loki/API/LokiGroupChatAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiGroupChatAPI.swift @@ -8,6 +8,7 @@ public final class LokiGroupChatAPI : NSObject { private static let batchCount = 8 @objc public static let publicChatMessageType = "network.loki.messenger.publicChat" @objc public static let publicChatID = 1 + private static let maxRetryCount: UInt = 4 private static let tokenCollection = "LokiGroupChatTokenCollection" internal static var userDisplayName: String { return SSKEnvironment.shared.contactsManager.displayName(forPhoneIdentifier: userHexEncodedPublicKey) ?? "Anonymous" } @@ -103,7 +104,13 @@ public final class LokiGroupChatAPI : NSObject { let timestamp = UInt64(date.timeIntervalSince1970) * 1000 return LokiGroupMessage(serverID: serverID, hexEncodedPublicKey: userHexEncodedPublicKey, displayName: displayName, body: body, type: publicChatMessageType, timestamp: timestamp) } - } + }.recover { error -> Promise in + if let error = error as? NetworkManagerError, error.statusCode == 401 { + print("[Loki] Group chat token expired; dropping it.") + storage.dbReadWriteConnection.removeObject(forKey: serverURL, inCollection: tokenCollection) + } + throw error + }.retryingIfNeeded(maxRetryCount: maxRetryCount) } @objc(getMessagesForGroup:)