Merge remote-tracking branch 'origin/release/2.31.0'

pull/1/head
Matthew Chen 6 years ago
commit b90fee08bd

@ -49,7 +49,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2.31.0.25</string>
<string>2.31.0.26</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LOGS_EMAIL</key>

@ -229,6 +229,14 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
void (^failureBlock)(void) = ^{
OWSLogError(@"Updating service with profile failed.");
// We use a "self-only" contact sync to indicate to desktop
// that we've changed our profile and that it should do a
// profile fetch for "self".
//
// NOTE: We also inform the desktop in the failure case,
// since that _may have_ affected service state.
[self.syncManager syncLocalContact];
dispatch_async(dispatch_get_main_queue(), ^{
failureBlockParameter();
});
@ -236,6 +244,11 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
void (^successBlock)(void) = ^{
OWSLogInfo(@"Successfully updated service with profile.");
// We use a "self-only" contact sync to indicate to desktop
// that we've changed our profile and that it should do a
// profile fetch for "self".
[self.syncManager syncLocalContact];
dispatch_async(dispatch_get_main_queue(), ^{
successBlockParameter();
});

@ -212,8 +212,9 @@ NS_ASSUME_NONNULL_BEGIN
__block NSMutableArray *result = [NSMutableArray array];
for (PhoneNumber *number in [self.parsedPhoneNumbers sortedArrayUsingSelector:@selector(compare:)]) {
SignalRecipient *_Nullable signalRecipient =
[SignalRecipient registeredRecipientForRecipientId:number.toE164 transaction:transaction];
SignalRecipient *_Nullable signalRecipient = [SignalRecipient registeredRecipientForRecipientId:number.toE164
mustHaveDevices:YES
transaction:transaction];
if (signalRecipient) {
[result addObject:signalRecipient];
}

@ -103,7 +103,7 @@ NS_ASSUME_NONNULL_BEGIN
[SignalRecipient markRecipientAsRegisteredAndGet:recipientId transaction:transaction];
[recipients addObject:recipient];
} else {
[SignalRecipient removeUnregisteredRecipient:recipientId transaction:transaction];
[SignalRecipient markRecipientAsUnregistered:recipientId transaction:transaction];
}
}
}];

@ -10,10 +10,11 @@ NS_ASSUME_NONNULL_BEGIN
//
// a) It serves as a cache of "known" Signal accounts. When the service indicates
// that an account exists, we make sure that an instance of SignalRecipient exists
// for that recipient id (using mark as registered).
// When the service indicates that an account does not exist, we remove any
// SignalRecipient.
// b) We hang the "known device list" for known signal accounts on this entity.
// for that recipient id (using mark as registered) and has at least one device.
// When the service indicates that an account does not exist, we remove any devices
// from that SignalRecipient - but do not remove it from the database.
// Note that SignalRecipients without any devices are not considered registered.
//// b) We hang the "known device list" for known signal accounts on this entity.
@interface SignalRecipient : TSYapDatabaseObject
@property (nonatomic, readonly) NSOrderedSet *devices;
@ -21,6 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_UNAVAILABLE;
+ (nullable instancetype)registeredRecipientForRecipientId:(NSString *)recipientId
mustHaveDevices:(BOOL)mustHaveDevices
transaction:(YapDatabaseReadTransaction *)transaction;
+ (instancetype)getOrBuildUnsavedRecipientForRecipientId:(NSString *)recipientId
transaction:(YapDatabaseReadTransaction *)transaction;
@ -40,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)markRecipientAsRegistered:(NSString *)recipientId
deviceId:(UInt32)deviceId
transaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (void)removeUnregisteredRecipient:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (void)markRecipientAsUnregistered:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction;
@end

@ -41,8 +41,9 @@ NS_ASSUME_NONNULL_BEGIN
{
OWSAssertDebug(transaction);
OWSAssertDebug(recipientId.length > 0);
SignalRecipient *_Nullable recipient = [self registeredRecipientForRecipientId:recipientId transaction:transaction];
SignalRecipient *_Nullable recipient =
[self registeredRecipientForRecipientId:recipientId mustHaveDevices:NO transaction:transaction];
if (!recipient) {
recipient = [[self alloc] initWithTextSecureIdentifier:recipientId];
}
@ -95,14 +96,18 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
+ (nullable instancetype)registeredRecipientForRecipientId:(NSString *)recipientId
mustHaveDevices:(BOOL)mustHaveDevices
transaction:(YapDatabaseReadTransaction *)transaction
{
OWSAssertDebug(transaction);
OWSAssertDebug(recipientId.length > 0);
return [self fetchObjectWithUniqueID:recipientId transaction:transaction];
SignalRecipient *_Nullable signalRecipient = [self fetchObjectWithUniqueID:recipientId transaction:transaction];
if (mustHaveDevices && signalRecipient.devices.count < 1) {
return nil;
}
return signalRecipient;
}
- (void)addDevices:(NSSet *)devices
@ -136,7 +141,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssertDebug(devicesToAdd.count > 0 || devicesToRemove.count > 0);
// Add before we remove, since removeDevicesFromRecipient:...
// can removeUnregisteredRecipient:... if the recipient has
// can markRecipientAsUnregistered:... if the recipient has
// no devices left.
if (devicesToAdd.count > 0) {
[self addDevicesToRegisteredRecipient:[NSSet setWithArray:devicesToAdd] transaction:transaction];
@ -172,12 +177,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSLogDebug(@"removing devices: %@, from registered recipient: %@", devices, self);
[self reloadWithTransaction:transaction];
[self removeDevices:devices];
if (self.devices.count > 0) {
[self saveWithTransaction_internal:transaction];
} else {
[SignalRecipient removeUnregisteredRecipient:self.recipientId transaction:transaction];
}
[self saveWithTransaction_internal:transaction];
}
- (NSString *)recipientId
@ -190,6 +190,19 @@ NS_ASSUME_NONNULL_BEGIN
return [self.recipientId compare:other.recipientId];
}
- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
// We need to distinguish between "users we know to be unregistered" and
// "users whose registration status is unknown". The former correspond to
// instances of SignalRecipient with no devices. The latter do not
// correspond to an instance of SignalRecipient in the database (although
// they may correspond to an "unsaved" instance of SignalRecipient built
// by getOrBuildUnsavedRecipientForRecipientId.
OWSFailDebug(@"Don't call removeWithTransaction.");
[super removeWithTransaction:transaction];
}
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
// We only want to mutate the persisted SignalRecipients in the database
@ -199,7 +212,7 @@ NS_ASSUME_NONNULL_BEGIN
// reflect "last known registration status". Forcing our codebase to
// use those methods helps ensure that we update the cache deliberately.
OWSFailDebug(@"Don't call saveWithTransaction from outside this class.");
[self saveWithTransaction_internal:transaction];
}
@ -207,13 +220,12 @@ NS_ASSUME_NONNULL_BEGIN
{
[super saveWithTransaction:transaction];
OWSLogVerbose(@"saved signal recipient: %@", self.recipientId);
OWSLogVerbose(@"saved signal recipient: %@ (%lu)", self.recipientId, (unsigned long) self.devices.count);
}
+ (BOOL)isRegisteredRecipient:(NSString *)recipientId transaction:(YapDatabaseReadTransaction *)transaction
{
SignalRecipient *_Nullable instance = [self registeredRecipientForRecipientId:recipientId transaction:transaction];
return instance != nil;
return nil != [self registeredRecipientForRecipientId:recipientId mustHaveDevices:YES transaction:transaction];
}
+ (SignalRecipient *)markRecipientAsRegisteredAndGet:(NSString *)recipientId
@ -222,7 +234,8 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssertDebug(transaction);
OWSAssertDebug(recipientId.length > 0);
SignalRecipient *_Nullable instance = [self registeredRecipientForRecipientId:recipientId transaction:transaction];
SignalRecipient *_Nullable instance =
[self registeredRecipientForRecipientId:recipientId mustHaveDevices:YES transaction:transaction];
if (!instance) {
OWSLogDebug(@"creating recipient: %@", recipientId);
@ -249,17 +262,18 @@ NS_ASSUME_NONNULL_BEGIN
}
}
+ (void)removeUnregisteredRecipient:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction
+ (void)markRecipientAsUnregistered:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction
{
OWSAssertDebug(transaction);
OWSAssertDebug(recipientId.length > 0);
SignalRecipient *_Nullable instance = [self registeredRecipientForRecipientId:recipientId transaction:transaction];
if (!instance) {
return;
SignalRecipient *instance = [self getOrBuildUnsavedRecipientForRecipientId:recipientId
transaction:transaction];
OWSLogDebug(@"Marking recipient as not registered: %@", recipientId);
if (instance.devices.count > 0) {
[instance removeDevices:instance.devices.set];
}
OWSLogDebug(@"removing recipient: %@", recipientId);
[instance removeWithTransaction:transaction];
[instance saveWithTransaction_internal:transaction];
}
@end

@ -1478,7 +1478,7 @@ NS_ASSUME_NONNULL_BEGIN
// Consult the device list cache we use for message sending
// whether or not we know about this linked device.
SignalRecipient *_Nullable recipient =
[SignalRecipient registeredRecipientForRecipientId:localNumber transaction:transaction];
[SignalRecipient registeredRecipientForRecipientId:localNumber mustHaveDevices:NO transaction:transaction];
if (!recipient) {
OWSFailDebug(@"No local SignalRecipient.");
} else {

@ -787,7 +787,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
return;
}
[SignalRecipient removeUnregisteredRecipient:recipient.recipientId transaction:transaction];
[SignalRecipient markRecipientAsUnregistered:recipient.recipientId transaction:transaction];
[[TSInfoMessage userNotRegisteredMessageInThread:thread recipientId:recipient.recipientId]
saveWithTransaction:transaction];
@ -1016,7 +1016,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
OWSFailDebug(@"sync message has device messages for unknown secondary devices.");
}
} else {
OWSAssertDebug(deviceMessages.count > 0);
// This can happen for users who have unregistered.
// We still want to try sending to them in case they have re-registered.
if (deviceMessages.count < 1) {
OWSLogWarn(@"Message send attempt with no device messages.");
}
}
if (deviceMessages.count == 0) {

@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>2.31.0</string>
<key>CFBundleVersion</key>
<string>2.31.0.25</string>
<string>2.31.0.26</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>NSAppTransportSecurity</key>

Loading…
Cancel
Save