|
|
|
@ -43,20 +43,36 @@ dispatch_queue_t attachmentsQueue() {
|
|
|
|
|
NSArray *attachmentsToRetrieve = (content.group != nil && (content.group.type == PushMessageContentGroupContextTypeUpdate)) ? [NSArray arrayWithObject:content.group.avatar] : content.attachments;
|
|
|
|
|
|
|
|
|
|
NSMutableArray *retrievedAttachments = [NSMutableArray array];
|
|
|
|
|
__block BOOL shouldProcessMessage = YES;
|
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
for (PushMessageContentAttachmentPointer *pointer in attachmentsToRetrieve) {
|
|
|
|
|
TSAttachmentPointer *attachmentPointer = (content.group != nil && (content.group.type == PushMessageContentGroupContextTypeUpdate)) ? [[TSAttachmentPointer alloc] initWithIdentifier:pointer.id key:pointer.key contentType:pointer.contentType relay:message.relay avatarOfGroupId:content.group.id] : [[TSAttachmentPointer alloc] initWithIdentifier:pointer.id key:pointer.key contentType:pointer.contentType relay:message.relay];
|
|
|
|
|
|
|
|
|
|
if ([attachmentPointer.contentType hasPrefix:@"image/"]) {
|
|
|
|
|
[attachmentPointer saveWithTransaction:transaction];
|
|
|
|
|
|
|
|
|
|
dispatch_async(attachmentsQueue(), ^{
|
|
|
|
|
[self retrieveAttachment:attachmentPointer];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
[retrievedAttachments addObject:attachmentPointer.uniqueId];
|
|
|
|
|
shouldProcessMessage = YES;
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
TSThread *thread = [TSContactThread getOrCreateThreadWithContactId:message.source transaction:transaction];
|
|
|
|
|
TSInfoMessage *infoMessage = [[TSInfoMessage alloc] initWithTimestamp:message.timestamp
|
|
|
|
|
inThread:thread
|
|
|
|
|
messageType:TSInfoMessageTypeUnsupportedMessage];
|
|
|
|
|
[infoMessage saveWithTransaction:transaction];
|
|
|
|
|
shouldProcessMessage = NO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
if (shouldProcessMessage) {
|
|
|
|
|
[self handleReceivedMessage:message withContent:content attachments:retrievedAttachments];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)sendAttachment:(NSData*)attachmentData contentType:(NSString*)contentType inMessage:(TSOutgoingMessage*)outgoingMessage thread:(TSThread*)thread {
|
|
|
|
|
TSRequest *allocateAttachment = [[TSAllocAttachmentRequest alloc] init];
|
|
|
|
@ -76,8 +92,10 @@ dispatch_queue_t attachmentsQueue() {
|
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
[result.pointer saveWithTransaction:transaction];
|
|
|
|
|
}];
|
|
|
|
|
[outgoingMessage.attachments addObject:attachementId];
|
|
|
|
|
[self sendMessage:outgoingMessage inThread:thread];
|
|
|
|
|
|
|
|
|
|
TSOutgoingMessage *messageToSend = [[TSOutgoingMessage alloc] initWithTimestamp:outgoingMessage.timeStamp inThread:thread messageBody:@"" attachments:[@[attachementId] mutableCopy]];
|
|
|
|
|
|
|
|
|
|
[self sendMessage:messageToSend inThread:thread];
|
|
|
|
|
} else{
|
|
|
|
|
DDLogWarn(@"Failed to upload attachment");
|
|
|
|
|
}
|
|
|
|
|