Fixes lingering interactions after removing thread (#1297)

Most of the work was done in SignalServiceKit 0.0.7, this adapts to
those changes.

Migration to clean any orphaned interactions/attachments.

- don't set new migration version until migration was successful.
- remove dead code from migrations

- rename message.attachments->message.attachmentIds
- Remove unused parameter from GroupModel
- formatting touched method/'s signatures

//FREEBIE
pull/1/head
Michael Kirk 9 years ago committed by GitHub
parent f09af989b7
commit 9f2bb5d2cc

@ -33,7 +33,7 @@ PODS:
- JSQMessagesViewController (7.3.4): - JSQMessagesViewController (7.3.4):
- JSQSystemSoundPlayer (~> 2.0.1) - JSQSystemSoundPlayer (~> 2.0.1)
- JSQSystemSoundPlayer (2.0.1) - JSQSystemSoundPlayer (2.0.1)
- libPhoneNumber-iOS (0.8.14) - libPhoneNumber-iOS (0.8.15)
- Mantle (2.0.7): - Mantle (2.0.7):
- Mantle/extobjc (= 2.0.7) - Mantle/extobjc (= 2.0.7)
- Mantle/extobjc (2.0.7) - Mantle/extobjc (2.0.7)
@ -43,7 +43,7 @@ PODS:
- ProtocolBuffers (1.9.10) - ProtocolBuffers (1.9.10)
- Reachability (3.2) - Reachability (3.2)
- SCWaveformView (1.0.0) - SCWaveformView (1.0.0)
- SignalServiceKit (0.0.6): - SignalServiceKit (0.0.7):
- '25519' - '25519'
- AFNetworking - AFNetworking
- AxolotlKit - AxolotlKit
@ -130,7 +130,7 @@ EXTERNAL SOURCES:
CHECKOUT OPTIONS: CHECKOUT OPTIONS:
SignalServiceKit: SignalServiceKit:
:commit: 36cab4691cce4962220f2bfbcc19413c5a7964a1 :commit: c14e4bb7b372a8277860f27ebd7eed7637828395
:git: https://github.com/WhisperSystems/SignalServiceKit.git :git: https://github.com/WhisperSystems/SignalServiceKit.git
SocketRocket: SocketRocket:
:commit: 8096fef47d582bff8ae3758c9ae7af1d55ea53d6 :commit: 8096fef47d582bff8ae3758c9ae7af1d55ea53d6
@ -146,14 +146,14 @@ SPEC CHECKSUMS:
HKDFKit: c058305d6f64b84f28c50bd7aa89574625bcb62a HKDFKit: c058305d6f64b84f28c50bd7aa89574625bcb62a
JSQMessagesViewController: 39fed975e3c9f8eba7292071e29eeb541d105e66 JSQMessagesViewController: 39fed975e3c9f8eba7292071e29eeb541d105e66
JSQSystemSoundPlayer: c5850e77a4363ffd374cd851154b9af93264ed8d JSQSystemSoundPlayer: c5850e77a4363ffd374cd851154b9af93264ed8d
libPhoneNumber-iOS: fb165271ebe7fb32e55da97b83219382f2f9d409 libPhoneNumber-iOS: 62a740e1ea5741060f5cec0f788b52071115cf31
Mantle: bc40bb061d8c2c6fb48d5083e04d928c3b7f73d9 Mantle: bc40bb061d8c2c6fb48d5083e04d928c3b7f73d9
OpenSSL: b187269d386b07452f56af273764ea0636dd5da8 OpenSSL: b187269d386b07452f56af273764ea0636dd5da8
PastelogKit: 7b475be4cf577713506a943dd940bcc0499c8bca PastelogKit: 7b475be4cf577713506a943dd940bcc0499c8bca
ProtocolBuffers: d088180c10072b3d24a9939a6314b7b9bcc2340b ProtocolBuffers: d088180c10072b3d24a9939a6314b7b9bcc2340b
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96 Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
SCWaveformView: 52a96750255d817e300565a80c81fb643e233e07 SCWaveformView: 52a96750255d817e300565a80c81fb643e233e07
SignalServiceKit: 850620cd1535f8628474121e7ea142ff1fe236a6 SignalServiceKit: e0bc81d12cef07b621403ff49e1c9c6f64d96109
SocketRocket: 3f77ec2104cc113add553f817ad90a77114f5d43 SocketRocket: 3f77ec2104cc113add553f817ad90a77114f5d43
SQLCipher: 4c768761421736a247ed6cf412d9045615d53dff SQLCipher: 4c768761421736a247ed6cf412d9045615d53dff
SSKeychain: c71293fa57216a40ab06c23f4085387583293de4 SSKeychain: c71293fa57216a40ab06c23f4085387583293de4

@ -21,7 +21,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>2.4.0</string> <string>2.4.1</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleURLTypes</key> <key>CFBundleURLTypes</key>
@ -38,7 +38,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>2.4.0.4</string> <string>2.4.1.0</string>
<key>ITSAppUsesNonExemptEncryption</key> <key>ITSAppUsesNonExemptEncryption</key>
<false/> <false/>
<key>LOGS_EMAIL</key> <key>LOGS_EMAIL</key>

@ -10,8 +10,10 @@
#import "TSAttachmentPointer.h" #import "TSAttachmentPointer.h"
#import "TSAttachmentStream.h" #import "TSAttachmentStream.h"
#import "TSCall.h" #import "TSCall.h"
#import "TSContactThread.h"
#import "TSContentAdapters.h" #import "TSContentAdapters.h"
#import "TSErrorMessage.h" #import "TSErrorMessage.h"
#import "TSGroupThread.h"
#import "TSIncomingMessage.h" #import "TSIncomingMessage.h"
#import "TSInfoMessage.h" #import "TSInfoMessage.h"
#import "TSOutgoingMessage.h" #import "TSOutgoingMessage.h"
@ -57,7 +59,8 @@
@implementation TSMessageAdapter @implementation TSMessageAdapter
+ (id<JSQMessageData>)messageViewDataWithInteraction:(TSInteraction *)interaction inThread:(TSThread *)thread { + (id<JSQMessageData>)messageViewDataWithInteraction:(TSInteraction *)interaction inThread:(TSThread *)thread
{
TSMessageAdapter *adapter = [[TSMessageAdapter alloc] init]; TSMessageAdapter *adapter = [[TSMessageAdapter alloc] init];
adapter.interaction = interaction; adapter.interaction = interaction;
adapter.messageDate = interaction.date; adapter.messageDate = interaction.date;
@ -94,8 +97,8 @@
TSMessage *message = (TSMessage *)interaction; TSMessage *message = (TSMessage *)interaction;
adapter.messageBody = message.body; adapter.messageBody = message.body;
if ([message.attachments count] > 0) { if ([message hasAttachments]) {
for (NSString *attachmentID in message.attachments) { for (NSString *attachmentID in message.attachmentIds) {
TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentID]; TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentID];
if ([attachment isKindOfClass:[TSAttachmentStream class]]) { if ([attachment isKindOfClass:[TSAttachmentStream class]]) {

@ -1,9 +1,10 @@
#import <SignalServiceKit/TextSecureKitEnv.h>
#import "NotificationsManager.h"
#import "RecentCallManager.h" #import "RecentCallManager.h"
#import "NotificationsManager.h"
#import "TSCall.h" #import "TSCall.h"
#import "TSContactThread.h"
#import "TSMessagesManager.h" #import "TSMessagesManager.h"
#import "TSStorageManager.h" #import "TSStorageManager.h"
#import <SignalServiceKit/TextSecureKitEnv.h>
@interface RecentCallManager () @interface RecentCallManager ()
@property YapDatabaseConnection *dbConnection; @property YapDatabaseConnection *dbConnection;

@ -16,6 +16,7 @@
#import "SignalKeyingStorage.h" #import "SignalKeyingStorage.h"
#import "TSAccountManager.h" #import "TSAccountManager.h"
#import "TSNetworkManager.h" #import "TSNetworkManager.h"
#import <SignalServiceKit/OWSOrphanedDataCleaner.h>
#define NEEDS_TO_REGISTER_PUSH_KEY @"Register For Push" #define NEEDS_TO_REGISTER_PUSH_KEY @"Register For Push"
#define NEEDS_TO_REGISTER_ATTRIBUTES @"Register Attributes" #define NEEDS_TO_REGISTER_ATTRIBUTES @"Register Attributes"
@ -30,24 +31,24 @@
#pragma mark Utility methods #pragma mark Utility methods
+ (void)performUpdateCheck { + (void)performUpdateCheck
{
NSString *previousVersion = Environment.preferences.lastRanVersion; NSString *previousVersion = Environment.preferences.lastRanVersion;
[Environment.preferences setAndGetCurrentVersion];
BOOL VOIPRegistration =
[[PushManager sharedManager] supportsVOIPPush] && ![Environment.preferences hasRegisteredVOIPPush];
if (!previousVersion) { if (!previousVersion) {
DDLogError(@"No previous version found. Possibly first launch since install."); DDLogInfo(@"No previous version found. Probably first launch since install - nothing to migrate.");
return; return;
} }
if (([self isVersion:previousVersion atLeast:@"1.0.2" andLessThan:@"2.0"])) { if (([self isVersion:previousVersion atLeast:@"1.0.2" andLessThan:@"2.0"])) {
// We don't migrate from RedPhone anymore, too painful to maintain. // We don't migrate from RedPhone anymore, too painful to maintain.
// Resetting the app data and quitting. DDLogError(@"Migrating from RedPhone no longer supported. Resetting app data and quitting.");
[Environment resetAppData]; [Environment resetAppData];
exit(0); exit(0);
} }
BOOL VOIPRegistration =
[[PushManager sharedManager] supportsVOIPPush] && ![Environment.preferences hasRegisteredVOIPPush];
// VOIP Push might need to be enabled because 1) user ran old version 2) Update to compatible iOS version // VOIP Push might need to be enabled because 1) user ran old version 2) Update to compatible iOS version
if (VOIPRegistration && [TSAccountManager isRegistered]) { if (VOIPRegistration && [TSAccountManager isRegistered]) {
[self nonBlockingPushRegistration]; [self nonBlockingPushRegistration];
@ -61,6 +62,13 @@
if ([self isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.3.0"] && [TSAccountManager isRegistered]) { if ([self isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.3.0"] && [TSAccountManager isRegistered]) {
[self clearBloomFilterCache]; [self clearBloomFilterCache];
} }
if ([self isVersion:previousVersion atLeast:@"2.0.0" andLessThan:@"2.4.1"] && [TSAccountManager isRegistered]) {
DDLogInfo(@"Running migration: removing orphaned data.");
[[OWSOrphanedDataCleaner new] removeOrphanedData];
}
[Environment.preferences setAndGetCurrentVersion];
} }
+ (BOOL)isVersion:(NSString *)thisVersionString + (BOOL)isVersion:(NSString *)thisVersionString
@ -95,50 +103,6 @@
failure:failedBlock]; failure:failedBlock];
} }
+ (void)blockingPushRegistration {
LIControllerBlockingOperation blockingOperation = ^BOOL(void) {
[[NSUserDefaults standardUserDefaults] setObject:@YES forKey:NEEDS_TO_REGISTER_PUSH_KEY];
__block dispatch_semaphore_t sema = dispatch_semaphore_create(0);
__block BOOL success;
__block failedBlock failedBlock = ^(NSError *error) {
success = NO;
dispatch_semaphore_signal(sema);
};
[[PushManager sharedManager] requestPushTokenWithSuccess:^(NSString *pushToken, NSString *voipToken) {
[TSAccountManager registerForPushNotifications:pushToken
voipToken:voipToken
success:^{
success = YES;
dispatch_semaphore_signal(sema);
}
failure:failedBlock];
}
failure:failedBlock];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
return success;
};
LIControllerRetryBlock retryBlock = [LockInteractionController defaultNetworkRetry];
[LockInteractionController performBlock:blockingOperation
completionBlock:^{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:NEEDS_TO_REGISTER_PUSH_KEY];
DDLogWarn(@"Successfully migrated to 2.1");
}
retryBlock:retryBlock
usesNetwork:YES];
}
+ (BOOL)needsRegisterPush {
return [self userDefaultsBoolForKey:NEEDS_TO_REGISTER_PUSH_KEY];
}
+ (void)clearVideoCache { + (void)clearVideoCache {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
@ -157,10 +121,6 @@
#pragma mark Upgrading to 2.1.3 - Adding VOIP flag on TS Server #pragma mark Upgrading to 2.1.3 - Adding VOIP flag on TS Server
+ (BOOL)needsRegisterAttributes {
return [self userDefaultsBoolForKey:NEEDS_TO_REGISTER_ATTRIBUTES] && [TSAccountManager isRegistered];
}
+ (void)blockingAttributesUpdate { + (void)blockingAttributesUpdate {
LIControllerBlockingOperation blockingOperation = ^BOOL(void) { LIControllerBlockingOperation blockingOperation = ^BOOL(void) {
[[NSUserDefaults standardUserDefaults] setObject:@YES forKey:NEEDS_TO_REGISTER_ATTRIBUTES]; [[NSUserDefaults standardUserDefaults] setObject:@YES forKey:NEEDS_TO_REGISTER_ATTRIBUTES];
@ -223,16 +183,4 @@
} }
} }
#pragma mark Util
+ (BOOL)userDefaultsBoolForKey:(NSString *)key {
NSNumber *num = [[NSUserDefaults standardUserDefaults] objectForKey:key];
if (!num) {
return NO;
} else {
return [num boolValue];
}
}
@end @end

@ -174,7 +174,8 @@
handleActionWithIdentifier:(NSString *)identifier handleActionWithIdentifier:(NSString *)identifier
forLocalNotification:(UILocalNotification *)notification forLocalNotification:(UILocalNotification *)notification
withResponseInfo:(NSDictionary *)responseInfo withResponseInfo:(NSDictionary *)responseInfo
completionHandler:(void (^)())completionHandler { completionHandler:(void (^)())completionHandler
{
if ([identifier isEqualToString:Signal_Message_Reply_Identifier]) { if ([identifier isEqualToString:Signal_Message_Reply_Identifier]) {
NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key]; NSString *threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
@ -184,7 +185,7 @@
[[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:thread inThread:thread
messageBody:responseInfo[UIUserNotificationActionResponseTypedTextKey] messageBody:responseInfo[UIUserNotificationActionResponseTypedTextKey]
attachments:nil]; attachmentIds:nil];
[[TSMessagesManager sharedManager] sendMessage:message [[TSMessagesManager sharedManager] sendMessage:message
inThread:thread inThread:thread
success:^{ success:^{

@ -710,14 +710,15 @@ typedef enum : NSUInteger {
withMessageText:(NSString *)text withMessageText:(NSString *)text
senderId:(NSString *)senderId senderId:(NSString *)senderId
senderDisplayName:(NSString *)senderDisplayName senderDisplayName:(NSString *)senderDisplayName
date:(NSDate *)date { date:(NSDate *)date
{
if (text.length > 0) { if (text.length > 0) {
[JSQSystemSoundPlayer jsq_playMessageSentSound]; [JSQSystemSoundPlayer jsq_playMessageSentSound];
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:self.thread inThread:self.thread
messageBody:text messageBody:text
attachments:nil]; attachmentIds:nil];
[[TSMessagesManager sharedManager] sendMessage:message inThread:self.thread success:nil failure:nil]; [[TSMessagesManager sharedManager] sendMessage:message inThread:self.thread success:nil failure:nil];
[self finishSendingMessage]; [self finishSendingMessage];
@ -1257,7 +1258,7 @@ typedef enum : NSUInteger {
if ([interaction isKindOfClass:[TSIncomingMessage class]]) { if ([interaction isKindOfClass:[TSIncomingMessage class]]) {
TSIncomingMessage *message = (TSIncomingMessage *)interaction; TSIncomingMessage *message = (TSIncomingMessage *)interaction;
for (NSString *attachmentId in message.attachments) { for (NSString *attachmentId in message.attachmentIds) {
__block TSAttachment *attachment; __block TSAttachment *attachment;
[self.editingDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.editingDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
@ -1587,11 +1588,12 @@ typedef enum : NSUInteger {
} }
} }
- (void)sendMessageAttachment:(NSData *)attachmentData ofType:(NSString *)attachmentType { - (void)sendMessageAttachment:(NSData *)attachmentData ofType:(NSString *)attachmentType
{
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:self.thread inThread:self.thread
messageBody:nil messageBody:nil
attachments:[NSMutableArray array]]; attachmentIds:[NSMutableArray new]];
[self dismissViewControllerAnimated:YES [self dismissViewControllerAnimated:YES
completion:^{ completion:^{
@ -1980,14 +1982,15 @@ typedef enum : NSUInteger {
[self performSegueWithIdentifier:kUpdateGroupSegueIdentifier sender:self]; [self performSegueWithIdentifier:kUpdateGroupSegueIdentifier sender:self];
} }
- (void)leaveGroup { - (void)leaveGroup
{
[self.navController hideDropDown:self]; [self.navController hideDropDown:self];
TSGroupThread *gThread = (TSGroupThread *)_thread; TSGroupThread *gThread = (TSGroupThread *)_thread;
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:gThread inThread:gThread
messageBody:@"" messageBody:@""
attachments:[[NSMutableArray alloc] init]]; attachmentIds:[NSMutableArray new]];
message.groupMetaMessage = TSGroupMessageQuit; message.groupMetaMessage = TSGroupMessageQuit;
[[TSMessagesManager sharedManager] sendMessage:message inThread:gThread success:nil failure:nil]; [[TSMessagesManager sharedManager] sendMessage:message inThread:gThread success:nil failure:nil];
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
@ -1999,11 +2002,11 @@ typedef enum : NSUInteger {
[self hideInputIfNeeded]; [self hideInputIfNeeded];
} }
- (void)updateGroupModelTo:(TSGroupModel *)newGroupModel { - (void)updateGroupModelTo:(TSGroupModel *)newGroupModel
{
__block TSGroupThread *groupThread; __block TSGroupThread *groupThread;
__block TSOutgoingMessage *message; __block TSOutgoingMessage *message;
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
groupThread = [TSGroupThread getOrCreateThreadWithGroupModel:newGroupModel transaction:transaction]; groupThread = [TSGroupThread getOrCreateThreadWithGroupModel:newGroupModel transaction:transaction];
groupThread.groupModel = newGroupModel; groupThread.groupModel = newGroupModel;
@ -2011,7 +2014,7 @@ typedef enum : NSUInteger {
message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:groupThread inThread:groupThread
messageBody:@"" messageBody:@""
attachments:[[NSMutableArray alloc] init]]; attachmentIds:[NSMutableArray new]];
message.groupMetaMessage = TSGroupMessageUpdate; message.groupMetaMessage = TSGroupMessageUpdate;
}]; }];

@ -114,7 +114,8 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
#pragma mark - Actions #pragma mark - Actions
- (void)createGroup { - (void)createGroup
{
TSGroupModel *model = [self makeGroup]; TSGroupModel *model = [self makeGroup];
[[TSStorageManager sharedManager] [[TSStorageManager sharedManager]
@ -130,29 +131,30 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
presentViewController:alertController presentViewController:alertController
animated:YES animated:YES
completion:^{ completion:^{
TSOutgoingMessage *message = TSOutgoingMessage *message =
[[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:self.thread inThread:self.thread
messageBody:@"" messageBody:@""
attachments:[[NSMutableArray alloc] init]]; attachmentIds:[NSMutableArray new]];
message.groupMetaMessage = TSGroupMessageNew; message.groupMetaMessage = TSGroupMessageNew;
if (model.groupImage != nil) { if (model.groupImage != nil) {
[[TSMessagesManager sharedManager] sendAttachment:UIImagePNGRepresentation(model.groupImage) [[TSMessagesManager sharedManager] sendAttachment:UIImagePNGRepresentation(model.groupImage)
contentType:@"image/png" contentType:@"image/png"
inMessage:message inMessage:message
thread:self.thread thread:self.thread
success:^{ success:^{
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES [self dismissViewControllerAnimated:YES
completion:^{ completion:^{
[Environment messageGroup:self.thread]; [Environment messageGroup:self.thread];
}]; }];
}); });
} }
failure:^{ failure:^{
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES [self
dismissViewControllerAnimated:YES
completion:^{ completion:^{
[TSStorageManager.sharedManager.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction){ [TSStorageManager.sharedManager.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction){
[self.thread removeWithTransaction:transaction]; [self.thread removeWithTransaction:transaction];
@ -160,44 +162,41 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
SignalAlertView(NSLocalizedString(@"GROUP_CREATING_FAILED", nil), SignalAlertView(NSLocalizedString(@"GROUP_CREATING_FAILED", nil),
NSLocalizedString(@"NETWORK_ERROR_RECOVERY", nil)); NSLocalizedString(@"NETWORK_ERROR_RECOVERY", nil));
} }];
]; });
}); }];
} } else {
]; [[TSMessagesManager sharedManager] sendMessage:message
} else { inThread:self.thread
[[TSMessagesManager sharedManager] sendMessage:message success:^{
inThread:self.thread dispatch_async(dispatch_get_main_queue(), ^{
success:^{ [self dismissViewControllerAnimated:YES
dispatch_async(dispatch_get_main_queue(), ^{ completion:^{
[self dismissViewControllerAnimated:YES [Environment messageGroup:self.thread];
completion:^{ }];
[Environment messageGroup:self.thread]; });
} }
]; failure:^{
}); dispatch_async(dispatch_get_main_queue(), ^{
} [self
failure:^{ dismissViewControllerAnimated:YES
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES
completion:^{ completion:^{
[TSStorageManager.sharedManager.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction){ [TSStorageManager.sharedManager.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction){
[self.thread removeWithTransaction:transaction]; [self.thread removeWithTransaction:transaction];
}]; }];
SignalAlertView(NSLocalizedString(@"GROUP_CREATING_FAILED", nil), SignalAlertView(NSLocalizedString(@"GROUP_CREATING_FAILED", nil),
NSLocalizedString(@"NETWORK_ERROR_RECOVERY", nil)); NSLocalizedString(@"NETWORK_ERROR_RECOVERY", nil));
} }];
]; });
});
} }];
]; }
}
}]; }];
} }
- (void)updateGroup { - (void)updateGroup
{
NSMutableArray *mut = [[NSMutableArray alloc] init]; NSMutableArray *mut = [[NSMutableArray alloc] init];
for (NSIndexPath *idx in _tableView.indexPathsForSelectedRows) { for (NSIndexPath *idx in _tableView.indexPathsForSelectedRows) {
[mut addObjectsFromArray:[[contacts objectAtIndex:(NSUInteger)idx.row] textSecureIdentifiers]]; [mut addObjectsFromArray:[[contacts objectAtIndex:(NSUInteger)idx.row] textSecureIdentifiers]];
@ -207,8 +206,7 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
_groupModel = [[TSGroupModel alloc] initWithTitle:_nameGroupTextField.text _groupModel = [[TSGroupModel alloc] initWithTitle:_nameGroupTextField.text
memberIds:[[[NSSet setWithArray:mut] allObjects] mutableCopy] memberIds:[[[NSSet setWithArray:mut] allObjects] mutableCopy]
image:_thread.groupModel.groupImage image:_thread.groupModel.groupImage
groupId:_thread.groupModel.groupId groupId:_thread.groupModel.groupId];
associatedAttachmentId:nil];
[self.nameGroupTextField resignFirstResponder]; [self.nameGroupTextField resignFirstResponder];
@ -216,7 +214,8 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
} }
- (TSGroupModel *)makeGroup { - (TSGroupModel *)makeGroup
{
NSString *title = _nameGroupTextField.text; NSString *title = _nameGroupTextField.text;
NSMutableArray *mut = [[NSMutableArray alloc] init]; NSMutableArray *mut = [[NSMutableArray alloc] init];
@ -226,11 +225,7 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
[mut addObject:[TSAccountManager localNumber]]; [mut addObject:[TSAccountManager localNumber]];
NSData *groupId = [SecurityUtils generateRandomBytes:16]; NSData *groupId = [SecurityUtils generateRandomBytes:16];
return [[TSGroupModel alloc] initWithTitle:title return [[TSGroupModel alloc] initWithTitle:title memberIds:mut image:_groupImage groupId:groupId];
memberIds:mut
image:_groupImage
groupId:groupId
associatedAttachmentId:nil];
} }
- (IBAction)addGroupPhoto:(id)sender { - (IBAction)addGroupPhoto:(id)sender {

@ -9,14 +9,15 @@
#import "InboxTableViewCell.h" #import "InboxTableViewCell.h"
#import "UIUtil.h" #import "UIUtil.h"
#import "OWSContactsManager.h"
#import "InCallViewController.h" #import "InCallViewController.h"
#import "MessagesViewController.h" #import "MessagesViewController.h"
#import "NSDate+millisecondTimeStamp.h" #import "NSDate+millisecondTimeStamp.h"
#import "OWSContactsManager.h"
#import "PreferencesUtil.h" #import "PreferencesUtil.h"
#import "SignalsViewController.h" #import "SignalsViewController.h"
#import "TSAccountManager.h" #import "TSAccountManager.h"
#import "TSDatabaseView.h" #import "TSDatabaseView.h"
#import "TSGroupThread.h"
#import "TSMessagesManager+sendMessages.h" #import "TSMessagesManager+sendMessages.h"
#import "TSStorageManager.h" #import "TSStorageManager.h"
#import "VersionMigrations.h" #import "VersionMigrations.h"
@ -254,7 +255,7 @@ static NSString *const kShowSignupFlowSegue = @"showSignupFlow";
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:thread inThread:thread
messageBody:@"" messageBody:@""
attachments:[[NSMutableArray alloc] init]]; attachmentIds:[NSMutableArray new]];
message.groupMetaMessage = TSGroupMessageQuit; message.groupMetaMessage = TSGroupMessageQuit;
[[TSMessagesManager sharedManager] sendMessage:message [[TSMessagesManager sharedManager] sendMessage:message
inThread:thread inThread:thread

Loading…
Cancel
Save