This commit is contained in:
Niels Andriesse 2019-10-04 14:52:59 +10:00
parent 8e539dad83
commit 391ed03913
8 changed files with 21 additions and 13 deletions

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -24,8 +24,6 @@
return contentBuilder;
}
- (uint)ttl {
return 4 * kDayInMs;
}
- (uint)ttl { return 4 * kDayInMs; }
@end

View File

@ -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);

View File

@ -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;

View File

@ -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.

View File

@ -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;
}
}