Streamline SignalRecipient.

pull/1/head
Matthew Chen 7 years ago
parent d14f764b50
commit ebe87348a2

@ -5,6 +5,7 @@
#import "DebugUIContacts.h"
#import "OWSTableViewController.h"
#import "Signal-Swift.h"
#import "SignalApp.h"
#import <Contacts/Contacts.h>
NS_ASSUME_NONNULL_BEGIN
@ -50,6 +51,18 @@ NS_ASSUME_NONNULL_BEGIN
actionBlock:^{
[DebugUIContacts clearSignalAccountCache];
}],
[OWSTableItem itemWithTitle:@"Clear SignalRecipient Cache"
actionBlock:^{
[DebugUIContacts clearSignalRecipientCache];
}],
[OWSTableItem itemWithTitle:@"New Invalid Contact Thread"
actionBlock:^{
[DebugUIContacts createInvalidContactThread];
}],
[OWSTableItem itemWithTitle:@"New Invalid Group Thread"
actionBlock:^{
[DebugUIContacts createInvalidGroupThread];
}],
]];
}
@ -1290,6 +1303,12 @@ NS_ASSUME_NONNULL_BEGIN
[SignalAccount removeAllObjectsInCollection];
}
+ (void)clearSignalRecipientCache
{
DDLogWarn(@"%@ Deleting all signal recipients.", self.logTag);
[SignalRecipient removeAllObjectsInCollection];
}
+ (void)deleteAllContacts
{
[self deleteContactsWithFilter:^(CNContact *contact) {
@ -1304,6 +1323,41 @@ NS_ASSUME_NONNULL_BEGIN
}];
}
+ (NSString *)invalidRecipientId
{
// We ensure that the phone number is invalid by appending too many digits.
NSMutableString *recipientId = [@"+1" mutableCopy];
for (int i = 0; i < 11; i++) {
[recipientId appendFormat:@"%d", (int)(arc4random() % 10)];
}
return [recipientId copy];
}
+ (void)createInvalidContactThread
{
NSString *recipientId = [self invalidRecipientId];
TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:recipientId];
[SignalApp.sharedApp presentConversationForThread:thread];
}
+ (void)createInvalidGroupThread
{
NSString *invalidRecipientId = [self invalidRecipientId];
NSString *validRecipientId = @"+19174054216";
NSString *groupName = @"Partially invalid group";
NSMutableArray<NSString *> *recipientIds = [@[
invalidRecipientId,
validRecipientId,
[TSAccountManager localNumber],
] mutableCopy];
NSData *groupId = [SecurityUtils generateRandomBytes:16];
TSGroupModel *model =
[[TSGroupModel alloc] initWithTitle:groupName memberIds:recipientIds image:nil groupId:groupId];
TSGroupThread *thread = [TSGroupThread getOrCreateThreadWithGroupModel:model];
[SignalApp.sharedApp presentConversationForThread:thread];
}
@end
NS_ASSUME_NONNULL_END

@ -904,8 +904,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
} else if (!mayHaveLinkedDevices && hasDeviceMessages) {
OWSFail(@"%@ sync message has device messages for unknown secondary devices.", self.logTag);
}
} else {
OWSAssert(deviceMessages.count > 0);
}
if (deviceMessages.count == 0) {
@ -914,6 +912,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// * The first (after upgrading?) time we send a sync message to our linked devices.
// * After unlinking all linked devices.
// * After trying and failing to link a device.
// * The first time we send a message to a user, if they don't have their
// default device (device id = 0). For example, if they have unregistered
// their primary but still have a linked device. Or later, when they re-register.
//
// When we're not sure if we have linked devices, we need to try
// to send self-sync messages even if they have no device messages

Loading…
Cancel
Save