Attachment uploading support
This commit is contained in:
@@ -63,6 +63,7 @@
|
|||||||
1ACFCFDA219EB2AC00E2C237 /* GCDAsyncSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 1ACFCF1B219EB2AC00E2C237 /* GCDAsyncSocket.m */; };
|
1ACFCFDA219EB2AC00E2C237 /* GCDAsyncSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 1ACFCF1B219EB2AC00E2C237 /* GCDAsyncSocket.m */; };
|
||||||
1ACFCFDC219EB2AC00E2C237 /* GCDAsyncSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ACFCF1D219EB2AC00E2C237 /* GCDAsyncSocket.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
1ACFCFDC219EB2AC00E2C237 /* GCDAsyncSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ACFCF1D219EB2AC00E2C237 /* GCDAsyncSocket.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
1ACFCFDF219EB31400E2C237 /* CocoaHTTPServer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1ACFCDE2219EB28A00E2C237 /* CocoaHTTPServer.framework */; };
|
1ACFCFDF219EB31400E2C237 /* CocoaHTTPServer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1ACFCDE2219EB28A00E2C237 /* CocoaHTTPServer.framework */; };
|
||||||
|
1AD8936E21EFD986009B599A /* MBIMUploadAttachmentOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 1AD8936D21EFD986009B599A /* MBIMUploadAttachmentOperation.m */; };
|
||||||
CD14F18E219E2DB400E7DD22 /* CryptoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CD14F18D219E2DB400E7DD22 /* CryptoTests.m */; };
|
CD14F18E219E2DB400E7DD22 /* CryptoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CD14F18D219E2DB400E7DD22 /* CryptoTests.m */; };
|
||||||
CD14F1A1219FE7D600E7DD22 /* MBIMUpdatePollOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CD14F1A0219FE7D600E7DD22 /* MBIMUpdatePollOperation.m */; };
|
CD14F1A1219FE7D600E7DD22 /* MBIMUpdatePollOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CD14F1A0219FE7D600E7DD22 /* MBIMUpdatePollOperation.m */; };
|
||||||
CD14F1A4219FF22700E7DD22 /* IMMessageItem+Encoded.m in Sources */ = {isa = PBXBuildFile; fileRef = CD14F1A3219FF22700E7DD22 /* IMMessageItem+Encoded.m */; };
|
CD14F1A4219FF22700E7DD22 /* IMMessageItem+Encoded.m in Sources */ = {isa = PBXBuildFile; fileRef = CD14F1A3219FF22700E7DD22 /* IMMessageItem+Encoded.m */; };
|
||||||
@@ -194,6 +195,8 @@
|
|||||||
1ACFCF1D219EB2AC00E2C237 /* GCDAsyncSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDAsyncSocket.h; sourceTree = "<group>"; };
|
1ACFCF1D219EB2AC00E2C237 /* GCDAsyncSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDAsyncSocket.h; sourceTree = "<group>"; };
|
||||||
1ACFCFE2219EB45300E2C237 /* MBIMHTTPConnection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMHTTPConnection.h; sourceTree = "<group>"; };
|
1ACFCFE2219EB45300E2C237 /* MBIMHTTPConnection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMHTTPConnection.h; sourceTree = "<group>"; };
|
||||||
1ACFCFE3219EB45300E2C237 /* MBIMHTTPConnection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMHTTPConnection.m; sourceTree = "<group>"; };
|
1ACFCFE3219EB45300E2C237 /* MBIMHTTPConnection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMHTTPConnection.m; sourceTree = "<group>"; };
|
||||||
|
1AD8936C21EFD986009B599A /* MBIMUploadAttachmentOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMUploadAttachmentOperation.h; sourceTree = "<group>"; };
|
||||||
|
1AD8936D21EFD986009B599A /* MBIMUploadAttachmentOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMUploadAttachmentOperation.m; sourceTree = "<group>"; };
|
||||||
CD14F18B219E2DB400E7DD22 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
CD14F18B219E2DB400E7DD22 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
CD14F18D219E2DB400E7DD22 /* CryptoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CryptoTests.m; sourceTree = "<group>"; };
|
CD14F18D219E2DB400E7DD22 /* CryptoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CryptoTests.m; sourceTree = "<group>"; };
|
||||||
CD14F18F219E2DB400E7DD22 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
CD14F18F219E2DB400E7DD22 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
@@ -525,6 +528,8 @@
|
|||||||
CD602061219B68950024D9C5 /* MBIMSendMessageOperation.m */,
|
CD602061219B68950024D9C5 /* MBIMSendMessageOperation.m */,
|
||||||
CD14F19F219FE7D600E7DD22 /* MBIMUpdatePollOperation.h */,
|
CD14F19F219FE7D600E7DD22 /* MBIMUpdatePollOperation.h */,
|
||||||
CD14F1A0219FE7D600E7DD22 /* MBIMUpdatePollOperation.m */,
|
CD14F1A0219FE7D600E7DD22 /* MBIMUpdatePollOperation.m */,
|
||||||
|
1AD8936C21EFD986009B599A /* MBIMUploadAttachmentOperation.h */,
|
||||||
|
1AD8936D21EFD986009B599A /* MBIMUploadAttachmentOperation.m */,
|
||||||
);
|
);
|
||||||
path = Operations;
|
path = Operations;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -797,6 +802,7 @@
|
|||||||
1AA43E95219EC38E00EDF1A7 /* MBIMHTTPUtilities.m in Sources */,
|
1AA43E95219EC38E00EDF1A7 /* MBIMHTTPUtilities.m in Sources */,
|
||||||
CDE455A421A5308D0041F5DD /* MBIMFetchAttachmentOperation.m in Sources */,
|
CDE455A421A5308D0041F5DD /* MBIMFetchAttachmentOperation.m in Sources */,
|
||||||
CD83E156219BE10A00F4CCEA /* hooking.m in Sources */,
|
CD83E156219BE10A00F4CCEA /* hooking.m in Sources */,
|
||||||
|
1AD8936E21EFD986009B599A /* MBIMUploadAttachmentOperation.m in Sources */,
|
||||||
CDF6233A219A8A5600690038 /* MBIMBridge.m in Sources */,
|
CDF6233A219A8A5600690038 /* MBIMBridge.m in Sources */,
|
||||||
CDF62335219A895D00690038 /* main.m in Sources */,
|
CDF62335219A895D00690038 /* main.m in Sources */,
|
||||||
CD60205C219B623F0024D9C5 /* MBIMMessagesListOperation.m in Sources */,
|
CD60205C219B623F0024D9C5 /* MBIMMessagesListOperation.m in Sources */,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
return @"sendMessage";
|
return @"sendMessage";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)_sendMessage:(NSString *)messageBody toChatWithGUID:(NSString *)chatGUID
|
- (BOOL)_sendMessage:(NSString *)messageBody toChatWithGUID:(NSString *)chatGUID attachmentGUIDs:(NSArray<NSString *> *)guids
|
||||||
{
|
{
|
||||||
__block BOOL result = YES;
|
__block BOOL result = YES;
|
||||||
|
|
||||||
@@ -32,7 +32,16 @@
|
|||||||
IMHandle *senderHandle = [iMessageAccount loginIMHandle];
|
IMHandle *senderHandle = [iMessageAccount loginIMHandle];
|
||||||
|
|
||||||
NSAttributedString *replyAttrString = [[NSAttributedString alloc] initWithString:messageBody];
|
NSAttributedString *replyAttrString = [[NSAttributedString alloc] initWithString:messageBody];
|
||||||
IMMessage *reply = [IMMessage fromMeIMHandle:senderHandle withText:replyAttrString fileTransferGUIDs:@[] flags:kIMMessageFinished];
|
NSAttributedString *attrStringWithFileTransfers = IMCreateSuperFormatStringWithAppendedFileTransfers(replyAttrString, guids);
|
||||||
|
|
||||||
|
IMMessage *reply = [IMMessage fromMeIMHandle:senderHandle
|
||||||
|
withText:attrStringWithFileTransfers
|
||||||
|
fileTransferGUIDs:guids
|
||||||
|
flags:(kIMMessageFinished | kIMMessageIsFromMe)];
|
||||||
|
|
||||||
|
for (NSString *guid in [reply fileTransferGUIDs]) {
|
||||||
|
[[IMFileTransferCenter sharedInstance] assignTransfer:guid toHandle:chat.recipient];
|
||||||
|
}
|
||||||
|
|
||||||
if (!chat) {
|
if (!chat) {
|
||||||
NSLog(@"Chat does not exist: %@", chatGUID);
|
NSLog(@"Chat does not exist: %@", chatGUID);
|
||||||
@@ -63,7 +72,12 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL result = [self _sendMessage:messageBody toChatWithGUID:guid];
|
NSArray *transferGUIDs = [args objectForKey:@"fileTransferGUIDs"];
|
||||||
|
if (!transferGUIDs) {
|
||||||
|
transferGUIDs = @[];
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL result = [self _sendMessage:messageBody toChatWithGUID:guid attachmentGUIDs:transferGUIDs];
|
||||||
if (result) {
|
if (result) {
|
||||||
response = [[HTTPErrorResponse alloc] initWithErrorCode:200];
|
response = [[HTTPErrorResponse alloc] initWithErrorCode:200];
|
||||||
}
|
}
|
||||||
|
|||||||
17
kordophone/Bridge/Operations/MBIMUploadAttachmentOperation.h
Normal file
17
kordophone/Bridge/Operations/MBIMUploadAttachmentOperation.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// MBIMUploadAttachmentOperation.h
|
||||||
|
// kordophoned
|
||||||
|
//
|
||||||
|
// Created by James Magahern on 1/16/19.
|
||||||
|
// Copyright © 2019 James Magahern. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "MBIMBridgeOperation.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface MBIMUploadAttachmentOperation : MBIMBridgeOperation
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
66
kordophone/Bridge/Operations/MBIMUploadAttachmentOperation.m
Normal file
66
kordophone/Bridge/Operations/MBIMUploadAttachmentOperation.m
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
//
|
||||||
|
// MBIMUploadAttachmentOperation.m
|
||||||
|
// kordophoned
|
||||||
|
//
|
||||||
|
// Created by James Magahern on 1/16/19.
|
||||||
|
// Copyright © 2019 James Magahern. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "MBIMUploadAttachmentOperation.h"
|
||||||
|
#import "MBIMDataResponse.h"
|
||||||
|
|
||||||
|
#import <IMCore/IMCore.h>
|
||||||
|
|
||||||
|
@implementation MBIMUploadAttachmentOperation
|
||||||
|
|
||||||
|
+ (void)load { [super load]; }
|
||||||
|
|
||||||
|
+ (NSString *)endpointName
|
||||||
|
{
|
||||||
|
return @"uploadAttachment";
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)main
|
||||||
|
{
|
||||||
|
NSObject<HTTPResponse> *response = nil;
|
||||||
|
do {
|
||||||
|
NSString *filename = [self valueForQueryItemWithName:@"filename"];
|
||||||
|
if ([filename length] == 0) {
|
||||||
|
NSLog(@"No filename provided");
|
||||||
|
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSData *attachmentData = self.requestBodyData;
|
||||||
|
if ([attachmentData length] == 0) {
|
||||||
|
NSLog(@"No attachment data in request");
|
||||||
|
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *localPath = [NSTemporaryDirectory() stringByAppendingPathComponent:filename];
|
||||||
|
NSURL *localURL = [NSURL fileURLWithPath:localPath];
|
||||||
|
BOOL success = [attachmentData writeToURL:localURL atomically:NO];
|
||||||
|
if (!success) {
|
||||||
|
NSLog(@"Error writing attachment to temporary directory");
|
||||||
|
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *guid = [[IMFileTransferCenter sharedInstance] guidForNewOutgoingTransferWithLocalURL:localURL];
|
||||||
|
if (!guid) {
|
||||||
|
NSLog(@"There was some problem shuttling the file to IMCore");
|
||||||
|
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSDictionary *responseDict = @{
|
||||||
|
@"fileTransferGUID" : guid
|
||||||
|
};
|
||||||
|
response = [MBIMJSONDataResponse responseWithJSONObject:responseDict];
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
self.serverCompletionBlock(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
Reference in New Issue
Block a user