Only send "sent message transcript" sync messages using UD.

pull/1/head
Matthew Chen 7 years ago
parent 991cf51480
commit 94c7b72361

@ -46,6 +46,8 @@ NS_ASSUME_NONNULL_BEGIN
= NSLocalizedString(@"LINK_NEW_DEVICE_TITLE", "Navigation title when scanning QR code to add new device."); = NSLocalizedString(@"LINK_NEW_DEVICE_TITLE", "Navigation title when scanning QR code to add new device.");
} }
#pragma mark - Dependencies
- (OWSProfileManager *)profileManager - (OWSProfileManager *)profileManager
{ {
return [OWSProfileManager sharedManager]; return [OWSProfileManager sharedManager];
@ -56,6 +58,23 @@ NS_ASSUME_NONNULL_BEGIN
return [OWSReadReceiptManager sharedManager]; return [OWSReadReceiptManager sharedManager];
} }
- (id<OWSUDManager>)udManager
{
return SSKEnvironment.shared.udManager;
}
- (TSAccountManager *)tsAccountManager
{
return TSAccountManager.sharedInstance;
}
- (TSSocketManager *)socketManager
{
return SSKEnvironment.shared.socketManager;
}
#pragma mark -
- (void)viewWillAppear:(BOOL)animated - (void)viewWillAppear:(BOOL)animated
{ {
[super viewWillAppear:animated]; [super viewWillAppear:animated];
@ -173,6 +192,13 @@ NS_ASSUME_NONNULL_BEGIN
// The service implementation of the socket connection caches the linked device state, // The service implementation of the socket connection caches the linked device state,
// so all sync message sends will fail on the socket until it is cycled. // so all sync message sends will fail on the socket until it is cycled.
[TSSocketManager.shared cycleSocket]; [TSSocketManager.shared cycleSocket];
[self.udManager setUnidentifiedAccessMode:UnidentifiedAccessModeUnknown
recipientId:self.tsAccountManager.localNumber];
// Fetch the local profile to determine if all
// linked devices support UD.
[self.profileManager fetchLocalUsersProfile];
}); });
} }
failure:^(NSError *error) { failure:^(NSError *error) {

@ -5,6 +5,8 @@
#import "OWSDevice.h" #import "OWSDevice.h"
#import "OWSError.h" #import "OWSError.h"
#import "OWSPrimaryStorage.h" #import "OWSPrimaryStorage.h"
#import "ProfileManagerProtocol.h"
#import "SSKEnvironment.h"
#import "YapDatabaseConnection+OWS.h" #import "YapDatabaseConnection+OWS.h"
#import "YapDatabaseConnection.h" #import "YapDatabaseConnection.h"
#import "YapDatabaseTransaction.h" #import "YapDatabaseTransaction.h"
@ -112,6 +114,11 @@ NSString *const kOWSPrimaryStorage_MayHaveLinkedDevices = @"kTSStorageManager_Ma
@implementation OWSDevice @implementation OWSDevice
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
[super saveWithTransaction:transaction];
}
+ (nullable instancetype)deviceFromJSONDictionary:(NSDictionary *)deviceAttributes error:(NSError **)error + (nullable instancetype)deviceFromJSONDictionary:(NSDictionary *)deviceAttributes error:(NSError **)error
{ {
OWSDevice *device = [MTLJSONAdapter modelOfClass:[self class] fromJSONDictionary:deviceAttributes error:error]; OWSDevice *device = [MTLJSONAdapter modelOfClass:[self class] fromJSONDictionary:deviceAttributes error:error];
@ -145,16 +152,19 @@ NSString *const kOWSPrimaryStorage_MayHaveLinkedDevices = @"kTSStorageManager_Ma
+ (void)replaceAll:(NSArray<OWSDevice *> *)currentDevices + (void)replaceAll:(NSArray<OWSDevice *> *)currentDevices
{ {
BOOL didChange = NO;
NSMutableArray<OWSDevice *> *existingDevices = [[self allObjectsInCollection] mutableCopy]; NSMutableArray<OWSDevice *> *existingDevices = [[self allObjectsInCollection] mutableCopy];
for (OWSDevice *currentDevice in currentDevices) { for (OWSDevice *currentDevice in currentDevices) {
NSUInteger existingDeviceIndex = [existingDevices indexOfObject:currentDevice]; NSUInteger existingDeviceIndex = [existingDevices indexOfObject:currentDevice];
if (existingDeviceIndex == NSNotFound) { if (existingDeviceIndex == NSNotFound) {
// New Device // New Device
[currentDevice save]; [currentDevice save];
didChange = YES;
} else { } else {
OWSDevice *existingDevice = existingDevices[existingDeviceIndex]; OWSDevice *existingDevice = existingDevices[existingDeviceIndex];
if ([existingDevice updateAttributesWithDevice:currentDevice]) { if ([existingDevice updateAttributesWithDevice:currentDevice]) {
[existingDevice save]; [existingDevice save];
didChange = YES;
} }
[existingDevices removeObjectAtIndex:existingDeviceIndex]; [existingDevices removeObjectAtIndex:existingDeviceIndex];
} }
@ -163,6 +173,11 @@ NSString *const kOWSPrimaryStorage_MayHaveLinkedDevices = @"kTSStorageManager_Ma
// Since we removed existing devices as we went, only stale devices remain // Since we removed existing devices as we went, only stale devices remain
for (OWSDevice *staleDevice in existingDevices) { for (OWSDevice *staleDevice in existingDevices) {
[staleDevice remove]; [staleDevice remove];
didChange = YES;
}
if (didChange) {
[SSKEnvironment.shared.profileManager fetchLocalUsersProfile];
} }
} }

@ -79,9 +79,13 @@ public class OWSMessageSend: NSObject {
} }
@objc @objc
public func setHasUDAuthFailed() { public func disableUD() {
// We "fail over" to non-UD sends after auth errors sending via UD.
unidentifiedAccess = nil unidentifiedAccess = nil
} }
@objc
public func setHasUDAuthFailed() {
// We "fail over" to non-UD sends after auth errors sending via UD.
disableUD()
}
} }

@ -1016,6 +1016,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
OWSLogWarn(@"Sending a message with no device messages."); OWSLogWarn(@"Sending a message with no device messages.");
} }
OWSLogVerbose(@"sending to recipient.recipientId: %@", recipient.recipientId);
if ([message isKindOfClass:[OWSOutgoingSyncMessage class]]
&& ![message isKindOfClass:[OWSOutgoingSentMessageTranscript class]]) {
[messageSend disableUD];
}
OWSRequestMaker *requestMaker = [[OWSRequestMaker alloc] OWSRequestMaker *requestMaker = [[OWSRequestMaker alloc]
initWithRequestFactoryBlock:^(SSKUnidentifiedAccess *_Nullable unidentifiedAccess) { initWithRequestFactoryBlock:^(SSKUnidentifiedAccess *_Nullable unidentifiedAccess) {
return [OWSRequestFactory submitMessageRequestWithRecipient:recipient.recipientId return [OWSRequestFactory submitMessageRequestWithRecipient:recipient.recipientId

Loading…
Cancel
Save