Merge branch 'charlesmchen/recipientDevices'
This commit is contained in:
commit
e194959c13
@ -29,8 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)addDevicesToRegisteredRecipient:(NSSet *)devices
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
- (void)removeDevicesFromRegisteredRecipient:(NSSet *)devices
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
- (void)removeDevicesFromRecipient:(NSSet *)devices transaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
- (NSString *)recipientId;
|
||||
|
||||
|
||||
@ -149,20 +149,23 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
[latest saveWithTransaction_internal:transaction];
|
||||
}
|
||||
|
||||
- (void)removeDevicesFromRegisteredRecipient:(NSSet *)devices transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
- (void)removeDevicesFromRecipient:(NSSet *)devices transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
OWSAssert(transaction);
|
||||
OWSAssert(devices.count > 0);
|
||||
|
||||
[self removeDevices:devices];
|
||||
|
||||
SignalRecipient *latest =
|
||||
[SignalRecipient markRecipientAsRegisteredAndGet:self.recipientId transaction:transaction];
|
||||
SignalRecipient *_Nullable latest =
|
||||
[SignalRecipient registeredRecipientForRecipientId:self.recipientId transaction:transaction];
|
||||
|
||||
if (!latest) {
|
||||
return;
|
||||
}
|
||||
if (![devices intersectsSet:latest.devices.set]) {
|
||||
return;
|
||||
}
|
||||
DDLogDebug(@"%@ removing devices: %@, from recipient: %@", self.logTag, devices, latest.recipientId);
|
||||
DDLogDebug(@"%@ removing devices: %@, from registered recipient: %@", self.logTag, devices, latest.recipientId);
|
||||
|
||||
[latest removeDevices:devices];
|
||||
[latest saveWithTransaction_internal:transaction];
|
||||
|
||||
@ -71,7 +71,6 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
|
||||
contentType = OWSMimeTypeApplicationOctetStream;
|
||||
}
|
||||
OWSAssert(contentType.length > 0);
|
||||
OWSAssert(byteCount > 0);
|
||||
|
||||
self = [super init];
|
||||
if (!self) {
|
||||
|
||||
@ -1166,7 +1166,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
||||
}
|
||||
|
||||
[self.dbConnection
|
||||
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction * transaction) {
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
if (extraDevices.count < 1 && missingDevices.count < 1) {
|
||||
OWSProdFail([OWSAnalyticsEvents messageSenderErrorNoMissingOrExtraDevices]);
|
||||
}
|
||||
@ -1179,8 +1179,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
||||
protocolContext:transaction];
|
||||
}
|
||||
|
||||
[recipient removeDevicesFromRegisteredRecipient:[NSSet setWithArray:extraDevices]
|
||||
transaction:transaction];
|
||||
[recipient removeDevicesFromRecipient:[NSSet setWithArray:extraDevices] transaction:transaction];
|
||||
}
|
||||
|
||||
if (missingDevices && missingDevices.count > 0) {
|
||||
@ -1279,11 +1278,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
||||
}
|
||||
} @catch (NSException *exception) {
|
||||
if ([exception.name isEqualToString:OWSMessageSenderInvalidDeviceException]) {
|
||||
[self.dbConnection
|
||||
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction * transaction) {
|
||||
[recipient removeDevicesFromRegisteredRecipient:[NSSet setWithObject:deviceNumber]
|
||||
transaction:transaction];
|
||||
}];
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[recipient removeDevicesFromRecipient:[NSSet setWithObject:deviceNumber] transaction:transaction];
|
||||
}];
|
||||
} else {
|
||||
@throw exception;
|
||||
}
|
||||
@ -1332,9 +1329,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
||||
DDLogError(@"Server replied to PreKeyBundle request with error: %@", error);
|
||||
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
|
||||
if (response.statusCode == 404) {
|
||||
[recipient removeDevicesFromRegisteredRecipient:[NSSet setWithObject:deviceNumber]
|
||||
transaction:transaction];
|
||||
|
||||
// Can't throw exception from within callback as it's probabably a different thread.
|
||||
exception = [NSException exceptionWithName:OWSMessageSenderInvalidDeviceException
|
||||
reason:@"Device not registered"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user