Fix edge cases around registration.

pull/1/head
Matthew Chen 7 years ago
parent 6cdef57e2a
commit 544bdbd7f5

@ -19,8 +19,7 @@ public class AccountManager: NSObject {
} }
@objc @objc
public override init() public override init() {
{
super.init() super.init()
SwiftSingletons.register(self) SwiftSingletons.register(self)
@ -72,7 +71,9 @@ public class AccountManager: NSObject {
default: default:
throw error throw error
} }
}.done { }.then { (_) in
self.tsAccountManager.performUpdateAccountAttributes()
}.done { (_) in
self.completeRegistration() self.completeRegistration()
} }

@ -226,6 +226,10 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag
- (void)sendConfigurationSyncMessage_AppReady { - (void)sendConfigurationSyncMessage_AppReady {
DDLogInfo(@""); DDLogInfo(@"");
if (![TSAccountManager sharedInstance].isRegistered) {
return;
}
BOOL areReadReceiptsEnabled = SSKEnvironment.shared.readReceiptManager.areReadReceiptsEnabled; BOOL areReadReceiptsEnabled = SSKEnvironment.shared.readReceiptManager.areReadReceiptsEnabled;
BOOL showUnidentifiedDeliveryIndicators = Environment.shared.preferences.shouldShowUnidentifiedDeliveryIndicators; BOOL showUnidentifiedDeliveryIndicators = Environment.shared.preferences.shouldShowUnidentifiedDeliveryIndicators;
BOOL showTypingIndicators = self.typingIndicators.areTypingIndicatorsEnabled; BOOL showTypingIndicators = self.typingIndicators.areTypingIndicatorsEnabled;

@ -144,6 +144,9 @@ extern NSString *const kNSNotificationName_LocalNumberDidChange;
- (AnyPromise *)updateAccountAttributes; - (AnyPromise *)updateAccountAttributes;
// This should only be used during the registration process.
- (AnyPromise *)performUpdateAccountAttributes;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -659,8 +659,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
if (!updateRequestDate) { if (!updateRequestDate) {
return [AnyPromise promiseWithValue:@(1)]; return [AnyPromise promiseWithValue:@(1)];
} }
AnyPromise *promise = [self performUpdateAccountAttributes];
AnyPromise *promise = [[SignalServiceRestClient new] updateAccountAttributesObjC];
promise = promise.then(^(id value) { promise = promise.then(^(id value) {
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
// Clear the update request unless a new update has been requested // Clear the update request unless a new update has been requested
@ -673,7 +672,14 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
inCollection:TSAccountManager_UserAccountCollection]; inCollection:TSAccountManager_UserAccountCollection];
} }
}]; }];
});
return promise;
}
- (AnyPromise *)performUpdateAccountAttributes
{
AnyPromise *promise = [[SignalServiceRestClient new] updateAccountAttributesObjC];
promise = promise.then(^(id value) {
// Fetch the local profile, as we may have changed its // Fetch the local profile, as we may have changed its
// account attributes. Specifically, we need to determine // account attributes. Specifically, we need to determine
// if all devices for our account now support UD for sync // if all devices for our account now support UD for sync

@ -686,7 +686,19 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
failureHandlerParam(error); failureHandlerParam(error);
}; };
TSThread *_Nullable thread = message.thread; __block TSThread *_Nullable thread = message.thread;
BOOL isSyncMessage = [message isKindOfClass:[OWSOutgoingSyncMessage class]];
if (!thread && !isSyncMessage) {
OWSFailDebug(@"Missing thread for non-sync message.");
// This thread has been deleted since the message was enqueued.
NSError *error = OWSErrorWithCodeDescription(OWSErrorCodeMessageSendNoValidRecipients,
NSLocalizedString(@"ERROR_DESCRIPTION_NO_VALID_RECIPIENTS",
@"Error indicating that an outgoing message had no valid recipients."));
[error setIsRetryable:NO];
return failureHandler(error);
}
// In the "self-send" special case, we ony need to send a sync message with a delivery receipt. // In the "self-send" special case, we ony need to send a sync message with a delivery receipt.
if ([thread isKindOfClass:[TSContactThread class]] && if ([thread isKindOfClass:[TSContactThread class]] &&

Loading…
Cancel
Save