Adding completion blocks to media message sends.

pull/1/head
Frederic Jacobs 9 years ago
parent 8d6ce0b57c
commit f6f6133498

@ -15,7 +15,6 @@ PODS:
- AFNetworking/Serialization (3.0.4) - AFNetworking/Serialization (3.0.4)
- AFNetworking/UIKit (3.0.4): - AFNetworking/UIKit (3.0.4):
- AFNetworking/NSURLSession - AFNetworking/NSURLSession
- Alamofire (3.1.4)
- AxolotlKit (0.8): - AxolotlKit (0.8):
- 25519 (~> 2.0.1) - 25519 (~> 2.0.1)
- HKDFKit (~> 0.0.3) - HKDFKit (~> 0.0.3)
@ -34,15 +33,16 @@ PODS:
- Mantle/extobjc (= 2.0.6) - Mantle/extobjc (= 2.0.6)
- Mantle/extobjc (2.0.6) - Mantle/extobjc (2.0.6)
- ProtocolBuffers (1.9.9.2) - ProtocolBuffers (1.9.9.2)
- SocketRocket-PinningPolicy (0.4.2) - SocketRocket-PinningPolicy (0.4.3)
- SQLCipher/common (3.3.1) - SQLCipher/common (3.3.1)
- SQLCipher/fts (3.3.1): - SQLCipher/fts (3.3.1):
- SQLCipher/common - SQLCipher/common
- SSKeychain (1.3.1) - SSKeychain (1.3.1)
- TextSecureKit (0.0.1): - TextSecureKit (0.0.4):
- '25519'
- AFNetworking - AFNetworking
- Alamofire
- AxolotlKit - AxolotlKit
- CocoaLumberjack
- libPhoneNumber-iOS - libPhoneNumber-iOS
- Mantle - Mantle
- SocketRocket-PinningPolicy - SocketRocket-PinningPolicy
@ -66,17 +66,16 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
'25519': dc4bad7e2dbcbf1efa121068a705a44cd98c80fc '25519': dc4bad7e2dbcbf1efa121068a705a44cd98c80fc
AFNetworking: a0075feb321559dc78d9d85b55d11caa19eabb93 AFNetworking: a0075feb321559dc78d9d85b55d11caa19eabb93
Alamofire: fbc829692f351fa1d8a31dd75fd7f7f56fea31fb
AxolotlKit: a33962f26943990e5d69d05b30470cea18caeed0 AxolotlKit: a33962f26943990e5d69d05b30470cea18caeed0
CocoaLumberjack: 17fe8581f84914d5d7e6360f7c70022b173c3ae0 CocoaLumberjack: 17fe8581f84914d5d7e6360f7c70022b173c3ae0
HKDFKit: c058305d6f64b84f28c50bd7aa89574625bcb62a HKDFKit: c058305d6f64b84f28c50bd7aa89574625bcb62a
libPhoneNumber-iOS: 7bfd00f843fdcd82b5182b463e8eb3b27579f41d libPhoneNumber-iOS: 7bfd00f843fdcd82b5182b463e8eb3b27579f41d
Mantle: 299966b00759634931699f69cb6a30b9239b944d Mantle: 299966b00759634931699f69cb6a30b9239b944d
ProtocolBuffers: 7111461618460961e6b7469177ec45ee551b4f0e ProtocolBuffers: 7111461618460961e6b7469177ec45ee551b4f0e
SocketRocket-PinningPolicy: 28f8b3e9584feef9a1c7018deca4b08224784e97 SocketRocket-PinningPolicy: f2ef00c3927bac05cd04d9d5171f82d922b40d3d
SQLCipher: d490d2effe735895d2204d25a154b1e722278421 SQLCipher: d490d2effe735895d2204d25a154b1e722278421
SSKeychain: 04c4ec40f4c3deda524e269bc76e5f30e638a174 SSKeychain: 04c4ec40f4c3deda524e269bc76e5f30e638a174
TextSecureKit: 869dd7d9399ee00134d35db0763b82d24d3df888 TextSecureKit: b7419cbc792e5be4cbfd93a4da340f7a51d7bc41
TwistedOakCollapsingFutures: f359b90f203e9ab13dfb92c9ff41842a7fe1cd0c TwistedOakCollapsingFutures: f359b90f203e9ab13dfb92c9ff41842a7fe1cd0c
UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d
YapDatabase: a7a1ae3e0f89c319e3b22615c2351987fbbdbded YapDatabase: a7a1ae3e0f89c319e3b22615c2351987fbbdbded

@ -6,6 +6,7 @@
// Copyright (c) 2014 Open Whisper Systems. All rights reserved. // Copyright (c) 2014 Open Whisper Systems. All rights reserved.
// //
#import "TSMessagesManager+sendMessages.h"
#import "TSMessagesManager.h" #import "TSMessagesManager.h"
@class TSAttachment; @class TSAttachment;
@ -18,7 +19,9 @@
- (void)sendAttachment:(NSData *)attachmentData - (void)sendAttachment:(NSData *)attachmentData
contentType:(NSString *)contentType contentType:(NSString *)contentType
inMessage:(TSOutgoingMessage *)outgoingMessage inMessage:(TSOutgoingMessage *)outgoingMessage
thread:(TSThread *)thread; thread:(TSThread *)thread
success:(successSendingCompletionBlock)successCompletionBlock
failure:(failedSendingCompletionBlock)failedCompletionBlock;
- (void)retrieveAttachment:(TSAttachmentPointer *)attachment messageId:(NSString *)messageId; - (void)retrieveAttachment:(TSAttachmentPointer *)attachment messageId:(NSString *)messageId;

@ -13,7 +13,6 @@
#import "TSAttachmentPointer.h" #import "TSAttachmentPointer.h"
#import "TSInfoMessage.h" #import "TSInfoMessage.h"
#import "TSMessagesManager+attachments.h" #import "TSMessagesManager+attachments.h"
#import "TSMessagesManager+sendMessages.h"
#import "TSNetworkManager.h" #import "TSNetworkManager.h"
@interface TSMessagesManager () @interface TSMessagesManager ()
@ -95,7 +94,9 @@ dispatch_queue_t attachmentsQueue() {
- (void)sendAttachment:(NSData *)attachmentData - (void)sendAttachment:(NSData *)attachmentData
contentType:(NSString *)contentType contentType:(NSString *)contentType
inMessage:(TSOutgoingMessage *)outgoingMessage inMessage:(TSOutgoingMessage *)outgoingMessage
thread:(TSThread *)thread { thread:(TSThread *)thread
success:(successSendingCompletionBlock)successCompletionBlock
failure:(failedSendingCompletionBlock)failedCompletionBlock {
TSRequest *allocateAttachment = [[TSAllocAttachmentRequest alloc] init]; TSRequest *allocateAttachment = [[TSAllocAttachmentRequest alloc] init];
[[TSNetworkManager sharedManager] makeRequest:allocateAttachment [[TSNetworkManager sharedManager] makeRequest:allocateAttachment
success:^(NSURLSessionDataTask *task, id responseObject) { success:^(NSURLSessionDataTask *task, id responseObject) {
@ -126,26 +127,55 @@ dispatch_queue_t attachmentsQueue() {
result.pointer.isDownloaded = YES; result.pointer.isDownloaded = YES;
[result.pointer saveWithTransaction:transaction]; [result.pointer saveWithTransaction:transaction];
}]; }];
[self sendMessage:outgoingMessage inThread:thread success:nil failure:nil]; [self sendMessage:outgoingMessage
inThread:thread
success:^{
if (successCompletionBlock) {
successCompletionBlock();
}
}
failure:^{
if (failedCompletionBlock) {
failedCompletionBlock();
}
}];
} else { } else {
if (failedCompletionBlock) {
failedCompletionBlock();
}
DDLogWarn(@"Failed to upload attachment"); DDLogWarn(@"Failed to upload attachment");
} }
} else { } else {
if (failedCompletionBlock) {
failedCompletionBlock();
}
DDLogError(@"The server didn't returned an empty responseObject"); DDLogError(@"The server didn't returned an empty responseObject");
} }
}); });
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failedCompletionBlock) {
failedCompletionBlock();
}
DDLogError(@"Failed to get attachment allocated: %@", error); DDLogError(@"Failed to get attachment allocated: %@", error);
}]; }];
} }
- (void)sendAttachment:(NSData *)attachmentData contentType:(NSString *)contentType thread:(TSThread *)thread { - (void)sendAttachment:(NSData *)attachmentData
contentType:(NSString *)contentType
thread:(TSThread *)thread
success:(successSendingCompletionBlock)successCompletionBlock
failure:(failedSendingCompletionBlock)failedCompletionBlock {
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:thread inThread:thread
messageBody:nil messageBody:nil
attachments:[[NSMutableArray alloc] init]]; attachments:[[NSMutableArray alloc] init]];
[self sendAttachment:attachmentData contentType:contentType inMessage:message thread:thread]; [self sendAttachment:attachmentData
contentType:contentType
inMessage:message
thread:thread
success:successCompletionBlock
failure:failedCompletionBlock];
} }
- (void)retrieveAttachment:(TSAttachmentPointer *)attachment messageId:(NSString *)messageId { - (void)retrieveAttachment:(TSAttachmentPointer *)attachment messageId:(NSString *)messageId {

Loading…
Cancel
Save