Re-order files
This commit is contained in:
parent
1a8175472a
commit
1c73cf5114
|
@ -19,5 +19,5 @@
|
|||
#import <SignalCoreKit/OWSAsserts.h>
|
||||
#import <SignalServiceKit/SSKAsserts.h>
|
||||
#import <SignalServiceKit/OWSAnalytics.h>
|
||||
#import <SignalServiceKit/NSObject.h>
|
||||
#import <SignalServiceKit/NSObject+Casting.h>
|
||||
#endif
|
||||
|
|
|
@ -158,7 +158,7 @@ static NSTimeInterval launchStartedAt;
|
|||
return AppEnvironment.shared.legacyNotificationActionHandler;
|
||||
}
|
||||
|
||||
- (OWSLokiFriendRequestExpireJob *)lokiFriendRequestExpireJob
|
||||
- (LKFriendRequestExpirationJob *)lokiFriendRequestExpireJob
|
||||
{
|
||||
return SSKEnvironment.shared.lokiFriendRequestExpireJob;
|
||||
}
|
||||
|
|
|
@ -147,7 +147,7 @@ public class SessionResetOperation: OWSOperation, DurableOperation {
|
|||
message.save(with: transaction)
|
||||
|
||||
// Loki: We have initiated a session reset
|
||||
Logger.debug("[Loki] Session reset has been initiated.")
|
||||
Logger.debug("[Loki] Session reset initiated.")
|
||||
self.contactThread.sessionResetState = .initiated
|
||||
self.contactThread.save(with: transaction)
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
#import <SignalServiceKit/Contact.h>
|
||||
#import <SignalServiceKit/ContactsUpdater.h>
|
||||
#import <SignalServiceKit/DataSource.h>
|
||||
#import <SignalServiceKit/ECKeyPair.h>
|
||||
#import <SignalServiceKit/ECKeyPair+Loki.h>
|
||||
#import <SignalServiceKit/MIMETypeUtil.h>
|
||||
#import <SignalServiceKit/NSData+Image.h>
|
||||
#import <SignalServiceKit/NSNotificationCenter+OWS.h>
|
||||
|
@ -90,10 +90,10 @@
|
|||
#import <SignalServiceKit/OWSContactsOutputStream.h>
|
||||
#import <SignalServiceKit/OWSDispatch.h>
|
||||
#import <SignalServiceKit/OWSEndSessionMessage.h>
|
||||
#import <SignalServiceKit/OWSEphemeralMessage.h>
|
||||
#import <SignalServiceKit/LKEphemeralMessage.h>
|
||||
#import <SignalServiceKit/OWSError.h>
|
||||
#import <SignalServiceKit/OWSFileSystem.h>
|
||||
#import <SignalServiceKit/OWSFriendRequestMessage.h>
|
||||
#import <SignalServiceKit/LKFriendRequestMessage.h>
|
||||
#import <SignalServiceKit/OWSIdentityManager.h>
|
||||
#import <SignalServiceKit/OWSMediaGalleryFinder.h>
|
||||
#import <SignalServiceKit/OWSMessageManager.h>
|
||||
|
|
|
@ -127,7 +127,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
attachmentDownloads:attachmentDownloads]];
|
||||
|
||||
// Loki
|
||||
OWSLokiFriendRequestExpireJob *lokiFriendRequestExpireJob = [[OWSLokiFriendRequestExpireJob alloc] initWithPrimaryStorage:primaryStorage];
|
||||
LKFriendRequestExpirationJob *lokiFriendRequestExpireJob = [[LKFriendRequestExpirationJob alloc] initWithPrimaryStorage:primaryStorage];
|
||||
SSKEnvironment.shared.lokiFriendRequestExpireJob = lokiFriendRequestExpireJob;
|
||||
|
||||
appSpecificSingletonBlock();
|
||||
|
|
|
@ -85,9 +85,9 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess
|
|||
|
||||
#pragma mark - Durable Message Enqueue
|
||||
|
||||
+ (OWSEphemeralMessage *)enqueueAcceptFriendRequestMessageInThread:(TSThread *)thread
|
||||
+ (LKEphemeralMessage *)enqueueAcceptFriendRequestMessageInThread:(TSThread *)thread
|
||||
{
|
||||
OWSEphemeralMessage *emptyMessage = [OWSEphemeralMessage createEmptyOutgoingMessageInThread:thread];
|
||||
LKEphemeralMessage *emptyMessage = [LKEphemeralMessage createEmptyOutgoingMessageInThread:thread];
|
||||
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self.messageSenderJobQueue addMessage:emptyMessage transaction:transaction];
|
||||
}];
|
||||
|
@ -185,7 +185,7 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess
|
|||
|
||||
// Loki: If we're not friends then always set the message to a friend request message
|
||||
// If we're friends then the assumption is that we have the other user's prekey bundle
|
||||
NSString *messageClassAsString = thread.isContactFriend ? @"TSOutgoingMessage" : @"OWSFriendRequestMessage";
|
||||
NSString *messageClassAsString = thread.isContactFriend ? @"TSOutgoingMessage" : @"LKFriendRequestMessage";
|
||||
Class messageClass = NSClassFromString(messageClassAsString);
|
||||
|
||||
TSOutgoingMessage *message =
|
||||
|
|
|
@ -37,7 +37,7 @@ public extension LokiAPI {
|
|||
let destination = signalMessage["destination"] as! String
|
||||
let ttl = LokiAPI.defaultMessageTTL
|
||||
if isPoWRequired {
|
||||
// Storage server takes a time interval in milliseconds
|
||||
// The storage server takes a time interval in milliseconds
|
||||
let now = NSDate.ows_millisecondTimeStamp()
|
||||
if let nonce = ProofOfWork.calculate(data: data, pubKey: destination, timestamp: now, ttl: ttl) {
|
||||
let result = Message(destination: destination, data: data, ttl: ttl, timestamp: now, nonce: nonce)
|
||||
|
|
|
@ -46,7 +46,7 @@ extension LokiAPI {
|
|||
let envelope = webSocketMessage.request!.body!
|
||||
return try SSKProtoEnvelope.parseData(envelope)
|
||||
} catch let error {
|
||||
owsFailDebug("[Loki API] Failed to unwrap data: \(error).")
|
||||
owsFailDebug("[Loki] Failed to unwrap data: \(error).")
|
||||
throw WrappingError.failedToUnwrapData
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ extension LokiAPI {
|
|||
messageBuilder.setRequest(try requestBuilder.build())
|
||||
return try messageBuilder.build()
|
||||
} catch let error {
|
||||
owsFailDebug("[Loki API] - Failed to wrap envelope in web socket message: \(error).")
|
||||
owsFailDebug("[Loki] Failed to wrap envelope in web socket message: \(error).")
|
||||
throw WrappingError.failedToWrapEnvelopeInWebSocketMessage
|
||||
}
|
||||
}
|
||||
|
@ -68,14 +68,14 @@ extension LokiAPI {
|
|||
/// Wrap a `SignalMessage` in an `SSKProtoEnvelope`.
|
||||
private static func createEnvelope(around signalMessage: SignalMessage, timestamp: UInt64) throws -> SSKProtoEnvelope {
|
||||
guard let keyPair = SSKEnvironment.shared.identityManager.identityKeyPair() else {
|
||||
owsFailDebug("[Loki API] - Failed to wrap message in envelope: identityManager.identityKeyPair() is invalid.")
|
||||
owsFailDebug("[Loki] Failed to wrap message in envelope: identityManager.identityKeyPair() is invalid.")
|
||||
throw WrappingError.failedToWrapMessageInEnvelope
|
||||
}
|
||||
do {
|
||||
let hexEncodedPublicKey = keyPair.hexEncodedPublicKey
|
||||
let parameters = ParamParser(dictionary: signalMessage)
|
||||
let rawType: Int32 = try parameters.required(key: "type")
|
||||
guard let type: SSKProtoEnvelope.SSKProtoEnvelopeType = SSKProtoEnvelope.SSKProtoEnvelopeType(rawValue: rawType) else {
|
||||
guard let type = SSKProtoEnvelope.SSKProtoEnvelopeType(rawValue: rawType) else {
|
||||
Logger.error("Invalid envelope type: \(rawType).")
|
||||
throw ParamParser.ParseError.invalidFormat("type")
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ extension LokiAPI {
|
|||
}
|
||||
return try builder.build()
|
||||
} catch let error {
|
||||
owsFailDebug("[Loki API] Failed to wrap message in envelope: \(error).")
|
||||
owsFailDebug("[Loki] Failed to wrap message in envelope: \(error).")
|
||||
throw WrappingError.failedToWrapMessageInEnvelope
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,11 +54,11 @@ import PromiseKit
|
|||
guard let json = rawResponse as? JSON, let messages = json["messages"] as? [JSON] else { return [] }
|
||||
return messages.compactMap { message in
|
||||
guard let base64EncodedData = message["data"] as? String, let data = Data(base64Encoded: base64EncodedData) else {
|
||||
Logger.warn("[Loki API] Failed to decode data for message: \(message).")
|
||||
Logger.warn("[Loki] Failed to decode data for message: \(message).")
|
||||
return nil
|
||||
}
|
||||
guard let envelope = try? unwrap(data: data) else {
|
||||
Logger.warn("[Loki API] Failed to unwrap data for message: \(message).")
|
||||
Logger.warn("[Loki] Failed to unwrap data for message: \(message).")
|
||||
return nil
|
||||
}
|
||||
return envelope
|
||||
|
@ -82,7 +82,7 @@ import PromiseKit
|
|||
@objc public static func objc_sendSignalMessage(_ signalMessage: SignalMessage, to destination: String, timestamp: UInt64, requiringPoW isPoWRequired: Bool) -> AnyPromise {
|
||||
let promise = Message.from(signalMessage: signalMessage, timestamp: timestamp, requiringPoW: isPoWRequired)
|
||||
.then(sendMessage)
|
||||
.recoverNetworkError(on: DispatchQueue.global())
|
||||
.recoverNetworkErrorIfNeeded(on: DispatchQueue.global())
|
||||
let anyPromise = AnyPromise(promise)
|
||||
anyPromise.retainUntilComplete()
|
||||
return anyPromise
|
||||
|
@ -93,13 +93,11 @@ import PromiseKit
|
|||
|
||||
private extension Promise {
|
||||
|
||||
func recoverNetworkError(on queue: DispatchQueue) -> Promise<T> {
|
||||
func recoverNetworkErrorIfNeeded(on queue: DispatchQueue) -> Promise<T> {
|
||||
return self.recover(on: queue) { error -> Promise<T> in
|
||||
switch error {
|
||||
case NetworkManagerError.taskError(_, let underlyingError):
|
||||
throw underlyingError
|
||||
default:
|
||||
throw error
|
||||
case NetworkManagerError.taskError(_, let underlyingError): throw underlyingError
|
||||
default: throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#import "ECKeyPair.h"
|
||||
#import "ECKeyPair+Loki.h"
|
||||
|
||||
extern void curve25519_donna(unsigned char *output, const unsigned char *a, const unsigned char *b);
|
||||
|
|
@ -57,7 +57,7 @@
|
|||
@try {
|
||||
return [self throws_loadPreKey:preKeyId];
|
||||
} @catch (NSException *exception) {
|
||||
OWSLogWarn(@"[Loki] New prekey had to be generated for %@.", pubKey);
|
||||
OWSLogWarn(@"[Loki] New prekey generated for %@.", pubKey);
|
||||
return [self generateAndStorePreKeyForContact:pubKey];
|
||||
}
|
||||
}
|
|
@ -43,7 +43,7 @@ private extension MutableCollection where Element == UInt8, Index == Int {
|
|||
* This was copied from the desktop messenger.
|
||||
* Ref: libloki/proof-of-work.js
|
||||
*/
|
||||
@objc public final class ProofOfWork : NSObject {
|
||||
public enum ProofOfWork {
|
||||
|
||||
// If this changes then we also have to use something other than UInt64 to support the new length
|
||||
private static let nonceLength = 8
|
||||
|
@ -54,8 +54,6 @@ private extension MutableCollection where Element == UInt8, Index == Int {
|
|||
case .production: return 100
|
||||
}
|
||||
}()
|
||||
|
||||
private override init() { }
|
||||
|
||||
/// Calculate a proof of work with the given configuration
|
||||
///
|
||||
|
@ -67,7 +65,7 @@ private extension MutableCollection where Element == UInt8, Index == Int {
|
|||
/// - timestamp: The timestamp
|
||||
/// - ttl: The message time to live
|
||||
/// - Returns: A nonce string or `nil` if it failed
|
||||
@objc public static func calculate(data: String, pubKey: String, timestamp: UInt64, ttl: UInt64) -> String? {
|
||||
public static func calculate(data: String, pubKey: String, timestamp: UInt64, ttl: UInt64) -> String? {
|
||||
let payload = createPayload(pubKey: pubKey, data: data, timestamp: timestamp, ttl: ttl)
|
||||
let target = calcTarget(ttl: ttl, payloadLength: payload.count, nonceTrials: nonceTrialCount)
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
|
||||
/*
|
||||
This class is used for settings friend requests to expired
|
||||
This is modelled after `OWSDisappearingMessagesJob`.
|
||||
Modeled after `OWSDisappearingMessagesJob`.
|
||||
*/
|
||||
@objc(OWSLokiFriendRequestExpireJob)
|
||||
public final class FriendRequestExpireJob : NSObject {
|
||||
@objc(LKFriendRequestExpirationJob)
|
||||
public final class FriendRequestExpirationJob : NSObject {
|
||||
private let databaseConnection: YapDatabaseConnection
|
||||
private let messageFinder = FriendRequestExpireMessageFinder()
|
||||
private let messageFinder = FriendRequestExpirationMessageFinder()
|
||||
|
||||
// These properties should only be accessed on the main thread.
|
||||
private var hasStarted = false
|
||||
|
@ -18,26 +17,21 @@ public final class FriendRequestExpireJob : NSObject {
|
|||
fileprivate static let serialQueue = DispatchQueue(label: "network.loki.friendrequest.expire")
|
||||
|
||||
/// Create a `FriendRequestExpireJob`.
|
||||
/// This will create a auto-running job which will set friend requests to expired.
|
||||
///
|
||||
/// - Parameter primaryStorage: The primary storage.
|
||||
/// This will create an auto-running job which will set friend requests to expired.
|
||||
@objc public init(withPrimaryStorage primaryStorage: OWSPrimaryStorage) {
|
||||
databaseConnection = primaryStorage.newDatabaseConnection()
|
||||
super.init()
|
||||
|
||||
// This makes sure we only ever have one instance of this class
|
||||
// This ensures we only ever have one instance of this class
|
||||
SwiftSingletons.register(self)
|
||||
|
||||
// Setup a timer that runs periodically to check for new friend request messages that will soon expire
|
||||
// Set up a timer that runs periodically to check for new friend request messages that will soon expire
|
||||
AppReadiness.runNowOrWhenAppDidBecomeReady {
|
||||
if CurrentAppContext().isMainApp {
|
||||
let fallbackInterval = 5 * kMinuteInterval
|
||||
self.fallbackTimer = WeakTimer.scheduledTimer(timeInterval: fallbackInterval, target: self, userInfo: nil, repeats: true) { [weak self] _ in
|
||||
AssertIsOnMainThread()
|
||||
|
||||
guard let strongSelf = self else { return }
|
||||
|
||||
strongSelf.timerDidFire(mainTimer: false)
|
||||
self?.timerDidFire(isMainTimer: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,19 +44,19 @@ public final class FriendRequestExpireJob : NSObject {
|
|||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
/// Start the job if we haven't done it yet
|
||||
/// Start the job if we haven't done so yet.
|
||||
@objc public func startIfNecessary() {
|
||||
DispatchQueue.main.async {
|
||||
guard !self.hasStarted else { return }
|
||||
|
||||
self.hasStarted = true;
|
||||
FriendRequestExpireJob.serialQueue.async {
|
||||
FriendRequestExpirationJob.serialQueue.async {
|
||||
self.runLoop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The main loop
|
||||
/// The main loop.
|
||||
private func runLoop() {
|
||||
AssertIsOnFriendRequestExpireQueue();
|
||||
|
||||
|
@ -83,27 +77,19 @@ public final class FriendRequestExpireJob : NSObject {
|
|||
// Schedule the next timer to run
|
||||
private func scheduleRun(by date: Date) {
|
||||
DispatchQueue.main.async {
|
||||
guard CurrentAppContext().isMainAppAndActive else {
|
||||
// Don't schedule run when inactive or not in main app.
|
||||
return
|
||||
}
|
||||
guard CurrentAppContext().isMainAppAndActive else { return } // Don't schedule run when inactive or not in main app
|
||||
|
||||
let minDelaySeconds: TimeInterval = 1
|
||||
let delaySeconds = max(minDelaySeconds, date.timeIntervalSinceNow)
|
||||
let newTimerScheduleDate = Date(timeIntervalSinceNow: delaySeconds)
|
||||
|
||||
// check that we only set the date if needed
|
||||
if let previousDate = self.nextExpireDate, previousDate < date {
|
||||
// If the date is later than the one we have stored then just ignore
|
||||
return
|
||||
}
|
||||
// Check that we only set the date if needed
|
||||
if let previousDate = self.nextExpireDate, previousDate < date { return } // If the date is later than the one we have stored then just ignore
|
||||
|
||||
self.resetNextExpireTimer()
|
||||
self.nextExpireDate = newTimerScheduleDate
|
||||
self.nextExpireTimer = WeakTimer.scheduledTimer(timeInterval: delaySeconds, target: self, userInfo: nil, repeats: false) { [weak self] _ in
|
||||
guard let strongSelf = self else { return }
|
||||
|
||||
strongSelf.timerDidFire(mainTimer: true)
|
||||
self?.timerDidFire(isMainTimer: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,15 +111,15 @@ public final class FriendRequestExpireJob : NSObject {
|
|||
|
||||
// Sanity check
|
||||
guard message.friendRequestExpiresAt <= now else {
|
||||
owsFailDebug("Refusing to expire friend request which doesn't expire until: \(message.friendRequestExpiresAt)")
|
||||
return;
|
||||
owsFailDebug("Refusing to expire friend request which doesn't expire until: \(message.friendRequestExpiresAt).")
|
||||
return
|
||||
}
|
||||
|
||||
// Check that we only expire sent friend requests
|
||||
guard message is TSOutgoingMessage && message.friendRequestStatus == .pending else {
|
||||
// Set message to not expire, so our other logic works correctly
|
||||
message.saveFriendRequestExpires(at: 0, with: transaction)
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
// Loki: Expire the friend request message
|
||||
|
@ -151,16 +137,16 @@ public final class FriendRequestExpireJob : NSObject {
|
|||
nextExpireDate = nil
|
||||
}
|
||||
|
||||
private func timerDidFire(mainTimer: Bool) {
|
||||
private func timerDidFire(isMainTimer: Bool) {
|
||||
guard CurrentAppContext().isMainAppAndActive else {
|
||||
let infoString = mainTimer ? "Main timer fired while main app is inactive" : "Ignoring fallbacktimer for app which is not main and active."
|
||||
Logger.info("[Loki Friend Request Expire Job] \(infoString)")
|
||||
let infoString = isMainTimer ? "Main timer fired while main app is inactive." : "Ignoring fallback timer for app which is not main and active."
|
||||
Logger.info("[Loki] Friend request expiration job: \(infoString)")
|
||||
return
|
||||
}
|
||||
|
||||
if (mainTimer) { self.resetNextExpireTimer() }
|
||||
if (isMainTimer) { self.resetNextExpireTimer() }
|
||||
|
||||
FriendRequestExpireJob.serialQueue.async {
|
||||
FriendRequestExpirationJob.serialQueue.async {
|
||||
self.runLoop()
|
||||
}
|
||||
}
|
||||
|
@ -168,12 +154,12 @@ public final class FriendRequestExpireJob : NSObject {
|
|||
}
|
||||
|
||||
// MARK: Events
|
||||
private extension FriendRequestExpireJob {
|
||||
private extension FriendRequestExpirationJob {
|
||||
|
||||
@objc func didBecomeActive() {
|
||||
AssertIsOnMainThread()
|
||||
AppReadiness.runNowOrWhenAppDidBecomeReady {
|
||||
FriendRequestExpireJob.serialQueue.async {
|
||||
FriendRequestExpirationJob.serialQueue.async {
|
||||
self.runLoop()
|
||||
}
|
||||
}
|
||||
|
@ -187,12 +173,12 @@ private extension FriendRequestExpireJob {
|
|||
}
|
||||
|
||||
// MARK: Asserts
|
||||
private extension FriendRequestExpireJob {
|
||||
private extension FriendRequestExpirationJob {
|
||||
|
||||
func AssertIsOnFriendRequestExpireQueue() {
|
||||
#if DEBUG
|
||||
guard #available(iOS 10.0, *) else { return }
|
||||
dispatchPrecondition(condition: .onQueue(FriendRequestExpireJob.serialQueue))
|
||||
dispatchPrecondition(condition: .onQueue(FriendRequestExpirationJob.serialQueue))
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -1,18 +1,19 @@
|
|||
|
||||
/*
|
||||
This class is used for finding friend request messages which are expired.
|
||||
This is modelled after `OWSDisappearingMessagesFinder`.
|
||||
This class is used for finding friend request messages which are pending expiration.
|
||||
Modeled after `OWSDisappearingMessagesFinder`.
|
||||
*/
|
||||
@objc(OWSLokiFriendRequestExpireMessageFinder)
|
||||
public class FriendRequestExpireMessageFinder : NSObject {
|
||||
public static let friendRequestExpireColumn = "friend_request_expires_at"
|
||||
public static let friendRequestExpireIndex = "loki_index_friend_request_expires_at"
|
||||
@objc(LKFriendRequestExpirationMessageFinder)
|
||||
public final class FriendRequestExpirationMessageFinder : NSObject {
|
||||
|
||||
private static let friendRequestExpireColumn = "friend_request_expires_at"
|
||||
private static let friendRequestExpireIndex = "loki_index_friend_request_expires_at"
|
||||
|
||||
public func nextExpirationTimestamp(with transaction: YapDatabaseReadTransaction) -> UInt64? {
|
||||
let query = "WHERE \(FriendRequestExpireMessageFinder.friendRequestExpireColumn) > 0 ORDER BY \(FriendRequestExpireMessageFinder.friendRequestExpireColumn) ASC"
|
||||
let query = "WHERE \(FriendRequestExpirationMessageFinder.friendRequestExpireColumn) > 0 ORDER BY \(FriendRequestExpirationMessageFinder.friendRequestExpireColumn) ASC"
|
||||
|
||||
let dbQuery = YapDatabaseQuery(string: query, parameters: [])
|
||||
let ext = transaction.ext(FriendRequestExpireMessageFinder.friendRequestExpireIndex) as? YapDatabaseSecondaryIndexTransaction
|
||||
let ext = transaction.ext(FriendRequestExpirationMessageFinder.friendRequestExpireIndex) as? YapDatabaseSecondaryIndexTransaction
|
||||
var firstMessage: TSMessage? = nil
|
||||
ext?.enumerateKeysAndObjects(matching: dbQuery) { (collection, key, object, stop) in
|
||||
firstMessage = object as? TSMessage
|
||||
|
@ -35,10 +36,10 @@ public class FriendRequestExpireMessageFinder : NSObject {
|
|||
var messageIds = [String]()
|
||||
let now = NSDate.ows_millisecondTimeStamp()
|
||||
|
||||
let query = "WHERE \(FriendRequestExpireMessageFinder.friendRequestExpireColumn) > 0 AND \(FriendRequestExpireMessageFinder.friendRequestExpireColumn) <= \(now)"
|
||||
let query = "WHERE \(FriendRequestExpirationMessageFinder.friendRequestExpireColumn) > 0 AND \(FriendRequestExpirationMessageFinder.friendRequestExpireColumn) <= \(now)"
|
||||
// When (friendRequestExpiresAt == 0) then the friend request SHOULD NOT be set to expired
|
||||
let dbQuery = YapDatabaseQuery(string: query, parameters: [])
|
||||
if let ext = transaction.ext(FriendRequestExpireMessageFinder.friendRequestExpireIndex) as? YapDatabaseSecondaryIndexTransaction {
|
||||
if let ext = transaction.ext(FriendRequestExpirationMessageFinder.friendRequestExpireIndex) as? YapDatabaseSecondaryIndexTransaction {
|
||||
ext.enumerateKeys(matching: dbQuery) { (_, key, _) in
|
||||
messageIds.append(key)
|
||||
}
|
||||
|
@ -49,9 +50,9 @@ public class FriendRequestExpireMessageFinder : NSObject {
|
|||
|
||||
}
|
||||
|
||||
// MARK: YapDatabaseExtension
|
||||
// MARK: Database Extension
|
||||
|
||||
public extension FriendRequestExpireMessageFinder {
|
||||
public extension FriendRequestExpirationMessageFinder {
|
||||
|
||||
@objc public static var indexDatabaseExtension: YapDatabaseSecondaryIndex {
|
||||
let setup = YapDatabaseSecondaryIndexSetup()
|
|
@ -3,10 +3,10 @@
|
|||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
NS_SWIFT_NAME(EphemeralMessage)
|
||||
@interface OWSEphemeralMessage : TSOutgoingMessage
|
||||
@interface LKEphemeralMessage : TSOutgoingMessage
|
||||
|
||||
/// Used to establish sessions.
|
||||
+ (OWSEphemeralMessage *)createEmptyOutgoingMessageInThread:(TSThread *)thread;
|
||||
+ (LKEphemeralMessage *)createEmptyOutgoingMessageInThread:(TSThread *)thread;
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#import "LKEphemeralMessage.h"
|
||||
#import <SignalCoreKit/NSDate+OWS.h>
|
||||
|
||||
@implementation LKEphemeralMessage
|
||||
|
||||
+ (LKEphemeralMessage *)createEmptyOutgoingMessageInThread:(TSThread *)thread {
|
||||
return [[LKEphemeralMessage alloc] initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp inThread:thread messageBody:@"" attachmentIds:[NSMutableArray<NSString *> new]
|
||||
expiresInSeconds:0 expireStartedAt:0 isVoiceMessage:NO groupMetaMessage:TSGroupMetaMessageUnspecified quotedMessage:nil contactShare:nil linkPreview:nil];
|
||||
}
|
||||
|
||||
- (BOOL)shouldBeSaved { return NO; }
|
||||
|
||||
@end
|
|
@ -3,7 +3,7 @@
|
|||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
NS_SWIFT_NAME(FriendRequestMessage)
|
||||
@interface OWSFriendRequestMessage : TSOutgoingMessage
|
||||
@interface LKFriendRequestMessage : TSOutgoingMessage
|
||||
|
||||
@end
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
#import "OWSFriendRequestMessage.h"
|
||||
#import "LKFriendRequestMessage.h"
|
||||
#import "OWSPrimaryStorage+Loki.h"
|
||||
#import "SignalRecipient.h"
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
|
||||
@implementation OWSFriendRequestMessage
|
||||
@implementation LKFriendRequestMessage
|
||||
|
||||
-(BOOL)isFriendRequest { return YES; }
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
#import "OWSEphemeralMessage.h"
|
||||
#import <SignalCoreKit/NSDate+OWS.h>
|
||||
|
||||
@implementation OWSEphemeralMessage
|
||||
|
||||
+ (OWSEphemeralMessage *)createEmptyOutgoingMessageInThread:(TSThread *)thread {
|
||||
return [[OWSEphemeralMessage alloc] initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp inThread:thread messageBody:@"" attachmentIds:[NSMutableArray<NSString *> new]
|
||||
expiresInSeconds:0 expireStartedAt:0 isVoiceMessage:NO groupMetaMessage:TSGroupMetaMessageUnspecified quotedMessage:nil contactShare:nil linkPreview:nil];
|
||||
}
|
||||
|
||||
- (BOOL)shouldBeSaved { return NO; }
|
||||
|
||||
@end
|
|
@ -1,4 +1,4 @@
|
|||
#import "NSObject.h"
|
||||
#import "NSObject+Casting.h"
|
||||
|
||||
@implementation NSObject (Casting)
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
#import "OWSDisappearingConfigurationUpdateInfoMessage.h"
|
||||
#import "OWSDisappearingMessagesConfiguration.h"
|
||||
#import "OWSDisappearingMessagesJob.h"
|
||||
#import "OWSEphemeralMessage.h"
|
||||
#import "LKEphemeralMessage.h"
|
||||
#import "OWSIdentityManager.h"
|
||||
#import "OWSIncomingMessageFinder.h"
|
||||
#import "OWSIncomingSentMessageTranscript.h"
|
||||
|
@ -51,7 +51,7 @@
|
|||
#import "TSQuotedMessage.h"
|
||||
#import <SignalCoreKit/Cryptography.h>
|
||||
#import <SignalCoreKit/NSDate+OWS.h>
|
||||
#import <SignalServiceKit/NSObject.h>
|
||||
#import <SignalServiceKit/NSObject+Casting.h>
|
||||
#import <SignalServiceKit/SignalRecipient.h>
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
#import <YapDatabase/YapDatabase.h>
|
||||
|
@ -1022,10 +1022,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[thread saveWithTransaction:transaction];
|
||||
|
||||
/// Loki: Send an empty message to trigger the session reset code for both parties
|
||||
OWSEphemeralMessage *emptyMessage = [OWSEphemeralMessage createEmptyOutgoingMessageInThread:thread];
|
||||
LKEphemeralMessage *emptyMessage = [LKEphemeralMessage createEmptyOutgoingMessageInThread:thread];
|
||||
[self.messageSenderJobQueue addMessage:emptyMessage transaction:transaction];
|
||||
|
||||
OWSLogDebug(@"[Loki] Session reset has been received from %@.", envelope.source);
|
||||
OWSLogDebug(@"[Loki] Session reset received from %@.", envelope.source);
|
||||
|
||||
/* Loki: Original code
|
||||
* ================
|
||||
|
@ -1481,7 +1481,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[existingFriendRequestMessage saveFriendRequestStatus:TSMessageFriendRequestStatusAccepted withTransaction:transaction];
|
||||
}
|
||||
// The two lines below are equivalent to calling [ThreadUtil enqueueAcceptFriendRequestMessageInThread:thread]
|
||||
OWSEphemeralMessage *emptyMessage = [OWSEphemeralMessage createEmptyOutgoingMessageInThread:thread];
|
||||
LKEphemeralMessage *emptyMessage = [LKEphemeralMessage createEmptyOutgoingMessageInThread:thread];
|
||||
[self.messageSenderJobQueue addMessage:emptyMessage transaction:transaction];
|
||||
} else if (!thread.isContactFriend) {
|
||||
// Checking that the sender of the message isn't already a friend is necessary because otherwise
|
||||
|
@ -1707,13 +1707,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
TSContactThread *_Nullable thread = [TSContactThread getThreadWithContactId:pubKey transaction:transaction];
|
||||
if (!thread) {
|
||||
OWSLogDebug(@"[Loki] New session was adopted but we failed to get the thread for %@.", pubKey);
|
||||
OWSLogDebug(@"[Loki] A new session was adopted but we failed to get the thread for %@.", pubKey);
|
||||
return;
|
||||
}
|
||||
|
||||
// If we were the ones to initiate the reset then we need to send back an empty message
|
||||
if (thread.sessionResetState == TSContactThreadSessionResetStateInitiated) {
|
||||
OWSEphemeralMessage *emptyMessage = [OWSEphemeralMessage createEmptyOutgoingMessageInThread:thread];
|
||||
LKEphemeralMessage *emptyMessage = [LKEphemeralMessage createEmptyOutgoingMessageInThread:thread];
|
||||
[self.messageSenderJobQueue addMessage:emptyMessage transaction:transaction];
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#import "TSRequest.h"
|
||||
#import "TSSocketManager.h"
|
||||
#import "TSThread.h"
|
||||
#import "OWSFriendRequestMessage.h"
|
||||
#import "LKFriendRequestMessage.h"
|
||||
#import <AxolotlKit/AxolotlExceptions.h>
|
||||
#import <AxolotlKit/CipherMessage.h>
|
||||
#import <AxolotlKit/PreKeyBundle.h>
|
||||
|
@ -1573,7 +1573,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
|
||||
// A friend request means we don't have a session with the person
|
||||
// There's no point to check for it
|
||||
Boolean isFriendRequest = [messageSend.message isKindOfClass:OWSFriendRequestMessage.class];
|
||||
Boolean isFriendRequest = [messageSend.message isKindOfClass:LKFriendRequestMessage.class];
|
||||
if (!isFriendRequest) {
|
||||
[self throws_ensureRecipientHasSessionForMessageSend:messageSend deviceId:deviceId];
|
||||
}
|
||||
|
@ -1818,7 +1818,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
OWSAssertDebug(recipientId.length > 0);
|
||||
|
||||
// Loki: Handle friend requests differently
|
||||
Boolean isFriendRequest = [messageSend.message isKindOfClass:OWSFriendRequestMessage.class];
|
||||
Boolean isFriendRequest = [messageSend.message isKindOfClass:LKFriendRequestMessage.class];
|
||||
if (isFriendRequest) {
|
||||
return [self throws_encryptedFriendMessageForMessageSend:messageSend deviceId:deviceId plainText:plainText];
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@class YapDatabaseConnection;
|
||||
|
||||
// Loki
|
||||
@class OWSLokiFriendRequestExpireJob;
|
||||
@class LKFriendRequestExpirationJob;
|
||||
|
||||
@protocol ContactsManagerProtocol;
|
||||
@protocol NotificationsProtocol;
|
||||
|
@ -115,8 +115,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@property (atomic, readonly) YapDatabaseConnection *analyticsDBConnection;
|
||||
|
||||
// Loki
|
||||
@property (nonatomic, readonly) OWSLokiFriendRequestExpireJob *lokiFriendRequestExpireJob;
|
||||
- (void)setLokiFriendRequestExpireJob:(OWSLokiFriendRequestExpireJob *)lokiFriendRequestExpireJob;
|
||||
@property (nonatomic, readonly) LKFriendRequestExpirationJob *lokiFriendRequestExpireJob;
|
||||
- (void)setLokiFriendRequestExpireJob:(LKFriendRequestExpirationJob *)lokiFriendRequestExpireJob;
|
||||
|
||||
- (BOOL)isComplete;
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ static SSKEnvironment *sharedSSKEnvironment;
|
|||
@property (nonatomic) OWSAttachmentDownloads *attachmentDownloads;
|
||||
|
||||
// Loki
|
||||
@property (nonatomic) OWSLokiFriendRequestExpireJob *lokiFriendRequestExpireJob;
|
||||
@property (nonatomic) LKFriendRequestExpirationJob *lokiFriendRequestExpireJob;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -199,7 +199,7 @@ static SSKEnvironment *sharedSSKEnvironment;
|
|||
}
|
||||
}
|
||||
|
||||
- (void)setLokiFriendRequestExpireJob:(OWSLokiFriendRequestExpireJob *)lokiFriendRequestExpireJob {
|
||||
- (void)setLokiFriendRequestExpireJob:(LKFriendRequestExpirationJob *)lokiFriendRequestExpireJob {
|
||||
@synchronized(self) {
|
||||
OWSAssertDebug(lokiFriendRequestExpireJob);
|
||||
OWSAssertDebug(!_lokiFriendRequestExpireJob);
|
||||
|
|
|
@ -215,7 +215,7 @@ void VerifyRegistrationsForPrimaryStorage(OWSStorage *storage)
|
|||
[TSDatabaseView asyncRegisterLazyRestoreAttachmentsDatabaseView:self];
|
||||
[SSKJobRecordFinder asyncRegisterDatabaseExtensionObjCWithStorage:self];
|
||||
|
||||
[OWSLokiFriendRequestExpireMessageFinder asyncRegisterDatabaseExtensions:self];
|
||||
[LKFriendRequestExpirationMessageFinder asyncRegisterDatabaseExtensions:self];
|
||||
|
||||
[self.database
|
||||
flushExtensionRequestsWithCompletionQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
|
||||
|
|
|
@ -12,7 +12,7 @@ static const NSUInteger ddLogLevel = DDLogLevelAll;
|
|||
static const NSUInteger ddLogLevel = DDLogLevelInfo;
|
||||
#endif
|
||||
#import "OWSAnalytics.h"
|
||||
#import "NSObject.h"
|
||||
#import "NSObject+Casting.h"
|
||||
#import "SSKAsserts.h"
|
||||
#import "TSConstants.h"
|
||||
#import <SignalCoreKit/NSObject+OWS.h>
|
||||
|
|
Loading…
Reference in New Issue