Skip to content
Snippets Groups Projects
Commit e7ada5c4 authored by EthanRDoesMC's avatar EthanRDoesMC
Browse files

attachment sending + newline handling

parent 7fed461b
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
-(void)forwardMessage:(IMMessage *)message fromChat:(IMChat *)chat;
-(void)getMessagesForCommand:(NSDictionary *)command;
-(void)sendReadReceiptWithCommand:(NSDictionary *)command;
-(BOOL)checkIfRunning:(NSString *)bundle_id;
@end
NS_ASSUME_NONNULL_END
......@@ -14,6 +14,10 @@
#import "CPDistributedMessagingCenter.h"
#import "rocketbootstrap.h"
#ifndef DEBUG
#define NSLog(...);
#endif
@interface UIApplication (BLSMSHelper)
-(BOOL)launchApplicationWithIdentifier:(NSString *)identifier suspended:(BOOL)launchSuspended;
@end
......@@ -111,7 +115,11 @@ NSInteger requestID = 0;
self.outputString = [[self outputString] stringByAppendingString:string];
// i'd like to replace this way of outputting the log by reading directly from the file, but i only just learned about file handles, so let's be real here: if I did it now (4/16) it would only make things slower
[[NSNotificationCenter defaultCenter] postNotificationName:@"BLMautrixLogUpdated" object:nil];
[self handleCommand:[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]];
NSArray * commands = [string componentsSeparatedByString:@"\n"];
for (NSString * command in commands) {
[self handleCommand:[NSJSONSerialization JSONObjectWithData:[command dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]];
}
});
}];
self.task.standardError = [NSPipe pipe];
......@@ -185,7 +193,9 @@ NSInteger requestID = 0;
[self sendDictionary:dictionary withID:[NSNumber numberWithInteger:requestID]];
}
-(void)sendDictionary:(NSDictionary *)dictionary withID:(NSNumber *)msgID {
NSLog(@"Got data:%@ and ID:%@", dictionary, msgID);
[dictionary setValue:msgID forKey: @"id"];
NSLog(@"made it past setValue");
// if (msgID > [NSNumber numberWithInteger:requestID]) {
// requestID = (NSInteger)msgID;
// }
......@@ -318,23 +328,56 @@ NSInteger requestID = 0;
-(void)sendAttachmentCommand:(NSDictionary *)command {
if ([[UIApplication sharedApplication] launchApplicationWithIdentifier:@"com.apple.MobileSMS" suspended:YES]) {
NSDictionary * message = @{ @"path_on_disk" : command[@"data"][@"path_on_disk"], @"file_name" : command[@"data"][@"file_name"], @"chat_guid" : command[@"data"][@"chat_guid"] };
NSDictionary *reply;
NSLog(@"aight we're here");
CPDistributedMessagingCenter * messagingCenter = [CPDistributedMessagingCenter centerNamed:@"com.beeper.brooklyn"];
NSLog(@"aight we're here");
[messagingCenter sendMessageName:@"sendAttachment" userInfo:nil];
NSLog(@"aight we're here");
//rocketbootstrap_distributedmessagingcenter_apply(messagingCenter);
//[messagingCenter sendMessageName:@"sendAttachment" userInfo:[NSDictionary dictionaryWithDictionary:message]];
if ((reply = [messagingCenter sendMessageAndReceiveReplyName:@"sendAttachment" userInfo:message])) {
[self.sessionSentGUIDs addObject:reply[@"sentGUID"]];
NSLog(@"Sent message; telling bridge...");
[self sendDictionary:[NSDictionary dictionaryWithDictionary:reply[@"request"]] withID:command[@"id"]];
}
NSLog(@"Launched successfully");
NSDictionary * message = @{ @"path_on_disk" : command[@"data"][@"path_on_disk"], @"file_name" : command[@"data"][@"file_name"], @"chat_guid" : command[@"data"][@"chat_guid"] };
NSLog(@"Outgoing user info: %@", message);
NSDictionary *reply;
while (![self checkIfRunning:@"MobileSMS"]) {
NSLog(@"sms isn't running!");
[self checkIfRunning:@"MobileSMS"];
}
NSLog(@"sms is running!");
CPDistributedMessagingCenter * messagingCenter = [CPDistributedMessagingCenter centerNamed:@"com.beeper.brooklyn"];
NSLog(@"Ping!");
//[messagingCenter sendMessageName:@"sendAttachment" userInfo:nil];
while (![messagingCenter sendMessageAndReceiveReplyName:@"ping" userInfo:nil]) {
NSLog(@"Pain");
[messagingCenter sendMessageAndReceiveReplyName:@"ping" userInfo:nil];
NSLog(@"Ping!");
}
NSLog(@"POG");
rocketbootstrap_distributedmessagingcenter_apply(messagingCenter);
//[messagingCenter sendMessageName:@"sendAttachment" userInfo:[NSDictionary dictionaryWithDictionary:message]];
if ((reply = [messagingCenter sendMessageAndReceiveReplyName:@"sendAttachment" userInfo:message])) {
NSLog(@"Reply: %@", reply);
[self.sessionSentGUIDs addObject:reply[@"sentGUID"]];
NSLog(@"Sent message; telling bridge...");
NSLog(@"Reply: %@", reply);
NSLog(@"Command's ID: %@", command[@"id"]);
[self sendDictionary:[NSMutableDictionary dictionaryWithDictionary:@{ @"command": @"response", @"data": @{ @"guid": reply[@"sentGUID"], @"timestamp": reply[@"request"][@"data"][@"timestamp"] } }] withID:command[@"id"]];
}
}
}
// source: https://github.com/iandwelker/libsmserver/blob/master/Tweak.xm
- (BOOL)checkIfRunning:(NSString *)bundle_id { /// Would return a _Bool but you can only send `id`s through MRYIPC funcs
/// Just checks if a certain app with the bundle id `bundle_id` is running at all, background or foreground.
NSTask* task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/sh"];
[task setArguments:@[@"-c", [NSString stringWithFormat:@"ps aux | grep %@ | grep -v grep", bundle_id]]];
NSPipe* pipe = [NSPipe pipe];
[task setStandardOutput:pipe];
NSFileHandle* file = [pipe fileHandleForReading];
[task launch];
NSData* data = [file readDataToEndOfFile];
NSString* out = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSNumber * temp = out.length > 0 ? @1 : @0;
return [temp boolValue];
}
-(void)respondWithChatInfoForCommand:(NSDictionary *)command {
IMChat * thisChat = [[IMChatRegistry sharedInstance] existingChatWithGUID:command[@"data"][@"chat_guid"]];
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1230"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4F70018325993B7000698E5C"
BuildableName = "brooklyn"
BlueprintName = "brooklyn"
ReferencedContainer = "container:brooklyn.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4F70018325993B7000698E5C"
BuildableName = "brooklyn"
BlueprintName = "brooklyn"
ReferencedContainer = "container:brooklyn.xcodeproj">
</BuildableReference>
</MacroExpansion>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4F70018325993B7000698E5C"
BuildableName = "brooklyn"
BlueprintName = "brooklyn"
ReferencedContainer = "container:brooklyn.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
......@@ -4,18 +4,18 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>brooklyn.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>xchighlight.xcscheme_^#shared#^_</key>
<key>Brooklyn + Xcode.xcscheme_^#shared#^_</key>
<dict>
<key>isShown</key>
<true/>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>Make.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
......
......@@ -7,6 +7,7 @@
@interface BLSMSHelper : NSObject
+(id)sharedInstance;
-(id)init;
-(NSDictionary *)ping;
-(NSDictionary *)handleCommand:(NSString *)command withDictionary:(NSDictionary *)dictionary;
@property (strong,nonatomic) CPDistributedMessagingCenter * messagingCenter;
@end
......@@ -24,15 +25,22 @@
}
-(id)init {
NSLog(@"aight we're here");
NSLog(@"init blsmshelper");
self.messagingCenter = [CPDistributedMessagingCenter centerNamed:@"com.beeper.brooklyn"];
//rocketbootstrap_distributedmessagingcenter_apply(self.messagingCenter);
rocketbootstrap_distributedmessagingcenter_apply(self.messagingCenter);
[self.messagingCenter runServerOnCurrentThread];
[self.messagingCenter registerForMessageName:@"sendAttachment" target:self selector:@selector(handleCommand:withDictionary:)];
[self.messagingCenter registerForMessageName:@"ping" target:self selector:@selector(ping)];
return [super init];
}
-(NSDictionary *)ping {
NSLog(@"Pong!");
return @{ @"ping" : @YES };
}
-(NSDictionary *)handleCommand:(NSString *)command withDictionary:(NSDictionary *)dictionary {
NSLog(@"command: %@, dictionary: %@", command, dictionary);
CKConversation * conversation = [CKConversationList.sharedConversationList conversationForExistingChatWithGUID:dictionary[@"chat_guid"]];
CKMediaObject * mediaObject = [CKMediaObjectManager.sharedInstance mediaObjectWithFileURL:[NSURL URLWithString:[NSString stringWithFormat:@"file:///private/var%@", dictionary[@"path_on_disk"]]] filename:dictionary[@"file_name"] transcoderUserInfo:@{}];
CKComposition* composition = [CKComposition compositionWithMediaObject:mediaObject subject:nil];
......@@ -42,10 +50,12 @@
NSMutableDictionary * datadict = [NSMutableDictionary new];
NSMutableDictionary * request = [NSMutableDictionary new];
[datadict setValue:[message guid] forKey:@"guid"];
NSLog(@"sent message guid %@", [message guid]);
[datadict setValue:[NSNumber numberWithDouble:[[message time] timeIntervalSince1970]] forKey:@"timestamp"];
[request setValue:@"response" forKey:@"command"];
[request setObject:[NSDictionary dictionaryWithDictionary:datadict] forKey:@"data"];
NSDictionary * reply = @{ @"request" : [NSDictionary dictionaryWithDictionary:request], @"sentGUID" : [message guid] };
NSLog(@"Reply from SMS: %@", reply);
return reply;
}
@end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment