From fa82d43e6cc8a29ce528644b5f3ea8784c6af7c1 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 12 Nov 2018 13:33:33 -0600 Subject: [PATCH 1/7] put custom image picker behind feature flag --- .../ConversationViewController.m | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index daa8f2ce5..5f29c6e77 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -90,6 +90,8 @@ @import Photos; +//#define FEATURE_FLAG_ALBUM_SEND_ENABLED; + NS_ASSUME_NONNULL_BEGIN static const CGFloat kLoadMoreHeaderHeight = 60.f; @@ -2638,10 +2640,17 @@ typedef enum : NSUInteger { return; } +#ifdef FEATURE_FLAG_ALBUM_SEND_ENABLED OWSImagePickerGridController *picker = [OWSImagePickerGridController new]; picker.delegate = self; OWSNavigationController *pickerModal = [[OWSNavigationController alloc] initWithRootViewController:picker]; +#else + UIImagePickerController *pickerModal = [UIImagePickerController new]; + pickerModal.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; + pickerModal.delegate = self; + pickerModal.mediaTypes = @[ (__bridge NSString *)kUTTypeImage, (__bridge NSString *)kUTTypeMovie ]; +#endif [self dismissKeyBoard]; [self presentViewController:pickerModal animated:YES completion:nil]; @@ -2711,7 +2720,7 @@ typedef enum : NSUInteger { NSString *mediaType = info[UIImagePickerControllerMediaType]; if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeMovie]) { - // Video captured with camera + // Video picked from library or captured with camera NSURL *videoURL = info[UIImagePickerControllerMediaURL]; [self dismissViewControllerAnimated:YES @@ -2749,8 +2758,60 @@ typedef enum : NSUInteger { } }]; } else { + // Non-Video image picked from library +#ifdef FEATURE_FLAG_ALBUM_SEND_ENABLED OWSFailDebug( @"Only use UIImagePicker for camera/video capture. Picking media from UIImagePicker is not supported. "); +#endif + + // To avoid re-encoding GIF and PNG's as JPEG we have to get the raw data of + // the selected item vs. using the UIImagePickerControllerOriginalImage + NSURL *assetURL = info[UIImagePickerControllerReferenceURL]; + PHAsset *asset = [[PHAsset fetchAssetsWithALAssetURLs:@[ assetURL ] options:nil] lastObject]; + if (!asset) { + return failedToPickAttachment(nil); + } + + // Images chosen from the "attach document" UI should be sent as originals; + // images chosen from the "attach media" UI should be resized to "medium" size; + TSImageQuality imageQuality = (self.isPickingMediaAsDocument ? TSImageQualityOriginal : TSImageQualityMedium); + + PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; + options.synchronous = YES; // We're only fetching one asset. + options.networkAccessAllowed = YES; // iCloud OK + options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; // Don't need quick/dirty version + [[PHImageManager defaultManager] + requestImageDataForAsset:asset + options:options + resultHandler:^(NSData *_Nullable imageData, + NSString *_Nullable dataUTI, + UIImageOrientation orientation, + NSDictionary *_Nullable assetInfo) { + NSError *assetFetchingError = assetInfo[PHImageErrorKey]; + if (assetFetchingError || !imageData) { + return failedToPickAttachment(assetFetchingError); + } + OWSAssertIsOnMainThread(); + + DataSource *_Nullable dataSource = + [DataSourceValue dataSourceWithData:imageData utiType:dataUTI]; + [dataSource setSourceFilename:filename]; + SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource + dataUTI:dataUTI + imageQuality:imageQuality]; + [self dismissViewControllerAnimated:YES + completion:^{ + OWSAssertIsOnMainThread(); + if (!attachment || [attachment hasError]) { + OWSLogWarn(@"Invalid attachment: %@.", + attachment ? [attachment errorName] : @"Missing data"); + [self showErrorAlertForAttachment:attachment]; + failedToPickAttachment(nil); + } else { + [self tryToSendAttachmentIfApproved:attachment]; + } + }]; + }]; } } From c6cead7bb3e9127f34f97dea2ca2eb896a04a932 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 13 Nov 2018 09:50:22 -0600 Subject: [PATCH 2/7] "Bump build to 2.32.0.6." --- Signal/Signal-Info.plist | 2 +- SignalShareExtension/Info.plist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist index a471fb279..120a55556 100644 --- a/Signal/Signal-Info.plist +++ b/Signal/Signal-Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 2.32.0.5 + 2.32.0.6 ITSAppUsesNonExemptEncryption LOGS_EMAIL diff --git a/SignalShareExtension/Info.plist b/SignalShareExtension/Info.plist index b11943ca0..e18cf6ff1 100644 --- a/SignalShareExtension/Info.plist +++ b/SignalShareExtension/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 2.32.0 CFBundleVersion - 2.32.0.5 + 2.32.0.6 ITSAppUsesNonExemptEncryption NSAppTransportSecurity From b19cfbc55e58e8e801b7ef1976961b4557059f9a Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 13 Nov 2018 10:36:29 -0600 Subject: [PATCH 3/7] Fixup AppReadiness vis a vis RI --- SignalMessaging/utils/ProximityMonitoringManager.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/SignalMessaging/utils/ProximityMonitoringManager.swift b/SignalMessaging/utils/ProximityMonitoringManager.swift index 945506354..b5dcd8148 100644 --- a/SignalMessaging/utils/ProximityMonitoringManager.swift +++ b/SignalMessaging/utils/ProximityMonitoringManager.swift @@ -15,9 +15,7 @@ public class OWSProximityMonitoringManagerImpl: NSObject, OWSProximityMonitoring public override init() { super.init() - // TODO: change to `runNowOrWhenAppWillBecomeReady` when - // reverse integrating - AppReadiness.runNowOrWhenAppIsReady { + AppReadiness.runNowOrWhenAppWillBecomeReady { self.setup() } } From 6749eccaac966a214f4bbeb00f4f9a4c15facd8e Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 13 Nov 2018 10:36:59 -0600 Subject: [PATCH 4/7] "Bump build to 2.32.0.7." --- Signal/Signal-Info.plist | 2 +- SignalShareExtension/Info.plist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist index 120a55556..4dd92cb7b 100644 --- a/Signal/Signal-Info.plist +++ b/Signal/Signal-Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 2.32.0.6 + 2.32.0.7 ITSAppUsesNonExemptEncryption LOGS_EMAIL diff --git a/SignalShareExtension/Info.plist b/SignalShareExtension/Info.plist index e18cf6ff1..545eea197 100644 --- a/SignalShareExtension/Info.plist +++ b/SignalShareExtension/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 2.32.0 CFBundleVersion - 2.32.0.6 + 2.32.0.7 ITSAppUsesNonExemptEncryption NSAppTransportSecurity From 7eaaab7be4923aa5db1be48ac627cb7cf678fc9b Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Sat, 10 Nov 2018 21:12:53 -0600 Subject: [PATCH 5/7] restrict self device id in message building, not in recipient data model --- .../src/Contacts/SignalRecipient.m | 30 ++----------------- .../src/Messages/OWSMessageSender.m | 17 +++++------ .../tests/Contacts/SignalRecipientTest.m | 14 ++++++++- 3 files changed, 22 insertions(+), 39 deletions(-) diff --git a/SignalServiceKit/src/Contacts/SignalRecipient.m b/SignalServiceKit/src/Contacts/SignalRecipient.m index 2e8853e3a..01d2225e0 100644 --- a/SignalServiceKit/src/Contacts/SignalRecipient.m +++ b/SignalServiceKit/src/Contacts/SignalRecipient.m @@ -71,23 +71,8 @@ NS_ASSUME_NONNULL_BEGIN if (!self) { return self; } - - OWSAssertDebug(self.tsAccountManager.localNumber.length > 0); - if ([self.tsAccountManager.localNumber isEqualToString:textSecureIdentifier]) { - // Default to no devices. - // - // This instance represents our own account and is used for sending - // sync message to linked devices. We shouldn't have any linked devices - // yet when we create the "self" SignalRecipient, and we don't need to - // send sync messages to the primary - we ARE the primary. - _devices = [NSOrderedSet new]; - } else { - // Default to sending to just primary device. - // - // OWSMessageSender will correct this if it is wrong the next time - // we send a message to this recipient. - _devices = [NSOrderedSet orderedSetWithObject:@(OWSDevicePrimaryDeviceId)]; - } + + _devices = [NSOrderedSet orderedSetWithObject:@(OWSDevicePrimaryDeviceId)]; return self; } @@ -103,11 +88,6 @@ NS_ASSUME_NONNULL_BEGIN _devices = [NSOrderedSet new]; } - if ([self.uniqueId isEqual:self.tsAccountManager.localNumber] && - [self.devices containsObject:@(OWSDevicePrimaryDeviceId)]) { - OWSFailDebug(@"self as recipient device"); - } - return self; } @@ -129,12 +109,6 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssertDebug(devices.count > 0); - if ([self.uniqueId isEqual:self.tsAccountManager.localNumber] && - [devices containsObject:@(OWSDevicePrimaryDeviceId)]) { - OWSFailDebug(@"adding self as recipient device"); - return; - } - NSMutableOrderedSet *updatedDevices = [self.devices mutableCopy]; [updatedDevices unionSet:devices]; self.devices = [updatedDevices copy]; diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 8d715fa47..36fc8e8ed 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -819,8 +819,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; }]; } -- (nullable NSArray *)deviceMessagesForMessageSendSafe:(OWSMessageSend *)messageSend - error:(NSError **)errorHandle +- (nullable NSArray *)deviceMessagesForMessageSend:(OWSMessageSend *)messageSend + error:(NSError **)errorHandle { OWSAssertDebug(messageSend); OWSAssertDebug(errorHandle); @@ -830,7 +830,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; NSArray *deviceMessages; @try { - deviceMessages = [self throws_deviceMessagesForMessageSendUnsafe:messageSend]; + deviceMessages = [self throws_deviceMessagesForMessageSend:messageSend]; } @catch (NSException *exception) { if ([exception.name isEqualToString:UntrustedIdentityKeyException]) { // This *can* happen under normal usage, but it should happen relatively rarely. @@ -964,7 +964,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; NSError *deviceMessagesError; NSArray *_Nullable deviceMessages = - [self deviceMessagesForMessageSendSafe:messageSend error:&deviceMessagesError]; + [self deviceMessagesForMessageSend:messageSend error:&deviceMessagesError]; if (deviceMessagesError || !deviceMessages) { OWSAssertDebug(deviceMessagesError); return messageSend.failure(deviceMessagesError); @@ -1398,7 +1398,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; [self sendMessageToRecipient:messageSend]; } -- (NSArray *)throws_deviceMessagesForMessageSendUnsafe:(OWSMessageSend *)messageSend +- (NSArray *)throws_deviceMessagesForMessageSend:(OWSMessageSend *)messageSend { OWSAssertDebug(messageSend.message); OWSAssertDebug(messageSend.recipient); @@ -1423,11 +1423,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; NSMutableArray *deviceIds = [recipient.devices mutableCopy]; OWSAssertDebug(deviceIds); - if (messageSend.isUDSend && messageSend.isLocalNumber) { - OWSLogVerbose(@"Adding device message for UD send to local device."); - OWSAssertDebug(![deviceIds containsObject:@(OWSDevicePrimaryDeviceId)]); - - [deviceIds addObject:@(OWSDevicePrimaryDeviceId)]; + if (messageSend.isLocalNumber) { + [deviceIds removeObject:@(OWSDevicePrimaryDeviceId)]; } for (NSNumber *deviceId in deviceIds) { diff --git a/SignalServiceKit/tests/Contacts/SignalRecipientTest.m b/SignalServiceKit/tests/Contacts/SignalRecipientTest.m index 630719613..ea92dab36 100644 --- a/SignalServiceKit/tests/Contacts/SignalRecipientTest.m +++ b/SignalServiceKit/tests/Contacts/SignalRecipientTest.m @@ -2,10 +2,10 @@ // Copyright (c) 2018 Open Whisper Systems. All rights reserved. // -#import "SignalRecipient.h" #import "MockSSKEnvironment.h" #import "OWSPrimaryStorage.h" #import "SSKBaseTestObjC.h" +#import "SignalRecipient.h" #import "TSAccountManager.h" #import "TestAppContext.h" #import @@ -49,4 +49,16 @@ }]; } +- (void)testRecipientWithExistingRecord +{ + // Sanity Check + XCTAssertNotNil(self.localNumber); + NSString *recipientId = @"+15551231234"; + [self readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + [SignalRecipient markRecipientAsRegisteredAndGet:recipientId transaction:transaction]; + + XCTAssertTrue([SignalRecipient isRegisteredRecipient:recipientId transaction:transaction]); + }]; +} + @end From b25a704039eda01ab990f4b12d2bc5c577d763b2 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 12 Nov 2018 10:42:37 -0600 Subject: [PATCH 6/7] Fix: Compose thread picker doesn't show self --- SignalServiceKit/src/Contacts/SignalRecipient.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/SignalServiceKit/src/Contacts/SignalRecipient.m b/SignalServiceKit/src/Contacts/SignalRecipient.m index 01d2225e0..6f2c576c0 100644 --- a/SignalServiceKit/src/Contacts/SignalRecipient.m +++ b/SignalServiceKit/src/Contacts/SignalRecipient.m @@ -88,6 +88,15 @@ NS_ASSUME_NONNULL_BEGIN _devices = [NSOrderedSet new]; } + // Since we use device count to determine whether a user is registered or not, + // ensure the local user always has at least *this* device. + if (![_devices containsObject:@(OWSDevicePrimaryDeviceId)]) { + if ([self.uniqueId isEqualToString:self.tsAccountManager.localNumber]) { + DDLogInfo(@"Adding primary device to self recipient."); + [self addDevices:[NSSet setWithObject:@(OWSDevicePrimaryDeviceId)]]; + } + } + return self; } From f9e2c8172c1cb077a2a47d7e4638b0bda186ec69 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 13 Nov 2018 10:38:47 -0600 Subject: [PATCH 7/7] "Bump build to 2.32.0.8." --- Signal/Signal-Info.plist | 2 +- SignalShareExtension/Info.plist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist index 4dd92cb7b..c2e69c0e7 100644 --- a/Signal/Signal-Info.plist +++ b/Signal/Signal-Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 2.32.0.7 + 2.32.0.8 ITSAppUsesNonExemptEncryption LOGS_EMAIL diff --git a/SignalShareExtension/Info.plist b/SignalShareExtension/Info.plist index 545eea197..bd48afbbd 100644 --- a/SignalShareExtension/Info.plist +++ b/SignalShareExtension/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 2.32.0 CFBundleVersion - 2.32.0.7 + 2.32.0.8 ITSAppUsesNonExemptEncryption NSAppTransportSecurity