From 391ed039137afb25dc5c37805d6734ffe58c9886 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 4 Oct 2019 14:52:59 +1000 Subject: [PATCH] Debug --- SignalServiceKit/src/Contacts/TSThread.h | 1 + .../src/Contacts/Threads/TSContactThread.h | 5 ++--- SignalServiceKit/src/Loki/API/LokiAPI.swift | 2 +- .../src/Loki/Messaging/LKFriendRequestMessage.m | 4 +--- SignalServiceKit/src/Messages/OWSMessageManager.m | 3 ++- SignalServiceKit/src/Messages/OWSMessageSender.m | 13 +++++++++++-- .../src/Storage/FullTextSearchFinder.swift | 2 +- SignalServiceKit/src/Storage/TSDatabaseView.m | 4 ++-- 8 files changed, 21 insertions(+), 13 deletions(-) diff --git a/SignalServiceKit/src/Contacts/TSThread.h b/SignalServiceKit/src/Contacts/TSThread.h index 8e5a8f50f..7aef9a0f4 100644 --- a/SignalServiceKit/src/Contacts/TSThread.h +++ b/SignalServiceKit/src/Contacts/TSThread.h @@ -64,6 +64,7 @@ typedef NS_ENUM(NSInteger, LKThreadFriendRequestStatus) { @property (nonatomic, readonly) BOOL hasCurrentUserSentFriendRequest; @property (nonatomic, readonly) BOOL hasCurrentUserReceivedFriendRequest; // ======== +@property (nonatomic) BOOL isForceHidden; /** * Whether the object is a group thread or not. diff --git a/SignalServiceKit/src/Contacts/Threads/TSContactThread.h b/SignalServiceKit/src/Contacts/Threads/TSContactThread.h index 19de31641..44839a34e 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSContactThread.h +++ b/SignalServiceKit/src/Contacts/Threads/TSContactThread.h @@ -25,6 +25,8 @@ extern NSString *const TSContactThreadPrefix; @property (nonatomic) BOOL hasDismissedOffers; +- (instancetype)initWithContactId:(NSString *)contactId; + + (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId NS_SWIFT_NAME(getOrCreateThread(contactId:)); + (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId @@ -37,10 +39,7 @@ extern NSString *const TSContactThreadPrefix; + (NSString *)contactIdFromThreadId:(NSString *)threadId; -// This is only exposed for tests. -#ifdef DEBUG + (NSString *)threadIdFromContactId:(NSString *)contactId; -#endif // This method can be used to get the conversation color for a given // recipient without using a read/write transaction to create a diff --git a/SignalServiceKit/src/Loki/API/LokiAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI.swift index 86044689a..d7fa2c77f 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI.swift @@ -15,7 +15,7 @@ public final class LokiAPI : NSObject { private static let longPollingTimeout: TimeInterval = 40 private static let deviceLinkUpdateInterval: TimeInterval = 8 * 60 public static let defaultMessageTTL: UInt64 = 24 * 60 * 60 * 1000 - internal static var powDifficulty: UInt = 40 + internal static var powDifficulty: UInt = 4 // MARK: Types public typealias RawResponse = Any diff --git a/SignalServiceKit/src/Loki/Messaging/LKFriendRequestMessage.m b/SignalServiceKit/src/Loki/Messaging/LKFriendRequestMessage.m index 100c9ec65..eccd41ce8 100644 --- a/SignalServiceKit/src/Loki/Messaging/LKFriendRequestMessage.m +++ b/SignalServiceKit/src/Loki/Messaging/LKFriendRequestMessage.m @@ -24,8 +24,6 @@ return contentBuilder; } -- (uint)ttl { - return 4 * kDayInMs; -} +- (uint)ttl { return 4 * kDayInMs; } @end diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 34ad2406a..7f84b2ab7 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1437,7 +1437,8 @@ NS_ASSUME_NONNULL_BEGIN } } } else { - // PMKHang([LKAPI getDestinationsFor:envelope.source]); // This should always be called from OWSBatchMessageProcessor.serialQueue, which is a background thread + + // TODO: Do we need to fetch the device mapping here? NSString *hexEncodedPublicKey = ([LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in:transaction] ?: envelope.source); diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index cd48e4eb7..239ef269d 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -43,6 +43,7 @@ #import "TSRequest.h" #import "TSSocketManager.h" #import "TSThread.h" +#import "TSContactThread.h" #import "LKFriendRequestMessage.h" #import "LKDeviceLinkMessage.h" #import "LKAddressMessage.h" @@ -903,8 +904,16 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; - (OWSMessageSend *)getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:(NSString *)hexEncodedPublicKey { - TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:hexEncodedPublicKey]; - LKFriendRequestMessage *message = [[LKFriendRequestMessage alloc] initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp inThread:thread messageBody:@"Please accept this friend request to enable multi device messaging" attachmentIds:[NSMutableArray new] + __block TSContactThread *thread; + [OWSPrimaryStorage.sharedManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + thread = [TSContactThread fetchObjectWithUniqueID:[TSContactThread threadIdFromContactId:hexEncodedPublicKey] transaction:transaction]; + if (thread == nil) { + thread = [[TSContactThread alloc] initWithContactId:hexEncodedPublicKey]; + } + thread.isForceHidden = YES; + [thread saveWithTransaction:transaction]; + }]; + LKFriendRequestMessage *message = [[LKFriendRequestMessage alloc] initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp inThread:thread messageBody:@"Accept this friend request to enable messages to be synced across devices" attachmentIds:[NSMutableArray new] expiresInSeconds:0 expireStartedAt:0 isVoiceMessage:NO groupMetaMessage:TSGroupMetaMessageUnspecified quotedMessage:nil contactShare:nil linkPreview:nil]; SignalRecipient *recipient = [[SignalRecipient alloc] initWithUniqueId:hexEncodedPublicKey]; NSString *userHexEncodedPublicKey = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey; diff --git a/SignalServiceKit/src/Storage/FullTextSearchFinder.swift b/SignalServiceKit/src/Storage/FullTextSearchFinder.swift index 90d680ab8..fe6b49b83 100644 --- a/SignalServiceKit/src/Storage/FullTextSearchFinder.swift +++ b/SignalServiceKit/src/Storage/FullTextSearchFinder.swift @@ -215,7 +215,7 @@ public class FullTextSearchFinder: NSObject { if let groupThread = object as? TSGroupThread { return self.groupThreadIndexer.index(groupThread, transaction: transaction) } else if let contactThread = object as? TSContactThread { - guard contactThread.shouldThreadBeVisible else { + guard contactThread.shouldThreadBeVisible && !contactThread.isForceHidden else { // If we've never sent/received a message in a TSContactThread, // then we want it to appear in the "Other Contacts" section rather // than in the "Conversations" section. diff --git a/SignalServiceKit/src/Storage/TSDatabaseView.m b/SignalServiceKit/src/Storage/TSDatabaseView.m index a565ceae3..04507c32b 100644 --- a/SignalServiceKit/src/Storage/TSDatabaseView.m +++ b/SignalServiceKit/src/Storage/TSDatabaseView.m @@ -282,13 +282,13 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup" } TSThread *thread = (TSThread *)object; - if (thread.shouldThreadBeVisible) { + if (thread.shouldThreadBeVisible && !thread.isForceHidden) { // Do nothing; we never hide threads that have ever had a message. } else { YapDatabaseViewTransaction *viewTransaction = [transaction ext:TSMessageDatabaseViewExtensionName]; OWSAssertDebug(viewTransaction); NSUInteger threadMessageCount = [viewTransaction numberOfItemsInGroup:thread.uniqueId]; - if (threadMessageCount < 1) { + if (threadMessageCount < 1 || thread.isForceHidden) { return nil; } }