From ddec4be8d603ccff143b0ed45f8925e56b90938d Mon Sep 17 00:00:00 2001 From: James Magahern Date: Sat, 17 Nov 2018 01:07:55 -0800 Subject: [PATCH] Supports polling for updates --- MessagesBridge.xcodeproj/project.pbxproj | 36 +++++++++++ kordophone/Bridge/MBIMBridge.m | 21 ++++++- kordophone/Bridge/MBIMConcurrentHTTPServer.h | 17 ++++++ kordophone/Bridge/MBIMConcurrentHTTPServer.m | 23 +++++++ kordophone/Bridge/MBIMHTTPConnection.m | 15 +++-- kordophone/Bridge/MBIMUpdateQueue.h | 30 +++++++++ kordophone/Bridge/MBIMUpdateQueue.m | 61 +++++++++++++++++++ .../Operations/MBIMMessagesListOperation.m | 6 +- .../Operations/MBIMUpdatePollOperation.h | 17 ++++++ .../Operations/MBIMUpdatePollOperation.m | 39 ++++++++++++ kordophone/Categories/IMMessageItem+Encoded.h | 24 ++++++++ kordophone/Categories/IMMessageItem+Encoded.m | 38 ++++++++++++ 12 files changed, 316 insertions(+), 11 deletions(-) create mode 100644 kordophone/Bridge/MBIMConcurrentHTTPServer.h create mode 100644 kordophone/Bridge/MBIMConcurrentHTTPServer.m create mode 100644 kordophone/Bridge/MBIMUpdateQueue.h create mode 100644 kordophone/Bridge/MBIMUpdateQueue.m create mode 100644 kordophone/Bridge/Operations/MBIMUpdatePollOperation.h create mode 100644 kordophone/Bridge/Operations/MBIMUpdatePollOperation.m create mode 100644 kordophone/Categories/IMMessageItem+Encoded.h create mode 100644 kordophone/Categories/IMMessageItem+Encoded.m diff --git a/MessagesBridge.xcodeproj/project.pbxproj b/MessagesBridge.xcodeproj/project.pbxproj index be3113e..45d0d86 100644 --- a/MessagesBridge.xcodeproj/project.pbxproj +++ b/MessagesBridge.xcodeproj/project.pbxproj @@ -64,6 +64,11 @@ 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 */; }; CD14F18E219E2DB400E7DD22 /* CryptoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CD14F18D219E2DB400E7DD22 /* CryptoTests.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 */; }; + CD14F1A7219FF2F400E7DD22 /* IMSharedUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD14F1A6219FF2F400E7DD22 /* IMSharedUtilities.framework */; }; + CD14F1AA219FF3B800E7DD22 /* MBIMUpdateQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = CD14F1A9219FF3B800E7DD22 /* MBIMUpdateQueue.m */; }; + CD14F1AD219FFAE100E7DD22 /* MBIMConcurrentHTTPServer.m in Sources */ = {isa = PBXBuildFile; fileRef = CD14F1AC219FFAE100E7DD22 /* MBIMConcurrentHTTPServer.m */; }; CD602056219B5DFD0024D9C5 /* MBIMBridgeOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CD602055219B5DFD0024D9C5 /* MBIMBridgeOperation.m */; }; CD60205C219B623F0024D9C5 /* MBIMMessagesListOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CD60205B219B623F0024D9C5 /* MBIMMessagesListOperation.m */; }; CD60205F219B674B0024D9C5 /* MBIMConversationListOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CD60205E219B674B0024D9C5 /* MBIMConversationListOperation.m */; }; @@ -188,6 +193,15 @@ 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 = ""; }; CD14F18F219E2DB400E7DD22 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + CD14F19F219FE7D600E7DD22 /* MBIMUpdatePollOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMUpdatePollOperation.h; sourceTree = ""; }; + CD14F1A0219FE7D600E7DD22 /* MBIMUpdatePollOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMUpdatePollOperation.m; sourceTree = ""; }; + CD14F1A2219FF22700E7DD22 /* IMMessageItem+Encoded.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "IMMessageItem+Encoded.h"; sourceTree = ""; }; + CD14F1A3219FF22700E7DD22 /* IMMessageItem+Encoded.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "IMMessageItem+Encoded.m"; sourceTree = ""; }; + CD14F1A6219FF2F400E7DD22 /* IMSharedUtilities.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IMSharedUtilities.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/System/Library/PrivateFrameworks/IMSharedUtilities.framework; sourceTree = DEVELOPER_DIR; }; + CD14F1A8219FF3B800E7DD22 /* MBIMUpdateQueue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMUpdateQueue.h; sourceTree = ""; }; + CD14F1A9219FF3B800E7DD22 /* MBIMUpdateQueue.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMUpdateQueue.m; sourceTree = ""; }; + CD14F1AB219FFAE100E7DD22 /* MBIMConcurrentHTTPServer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMConcurrentHTTPServer.h; sourceTree = ""; }; + CD14F1AC219FFAE100E7DD22 /* MBIMConcurrentHTTPServer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMConcurrentHTTPServer.m; sourceTree = ""; }; CD602054219B5DFD0024D9C5 /* MBIMBridgeOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMBridgeOperation.h; sourceTree = ""; }; CD602055219B5DFD0024D9C5 /* MBIMBridgeOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMBridgeOperation.m; sourceTree = ""; }; CD60205A219B623F0024D9C5 /* MBIMMessagesListOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMMessagesListOperation.h; sourceTree = ""; }; @@ -233,6 +247,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + CD14F1A7219FF2F400E7DD22 /* IMSharedUtilities.framework in Frameworks */, 1ACFCFDF219EB31400E2C237 /* CocoaHTTPServer.framework in Frameworks */, CDF62343219A9BE200690038 /* ContactsFoundation.framework in Frameworks */, CDF6233E219A8AFC00690038 /* IMCore.framework in Frameworks */, @@ -280,6 +295,7 @@ 1A0C445E219A45B400F2AC00 /* Frameworks */ = { isa = PBXGroup; children = ( + CD14F1A6219FF2F400E7DD22 /* IMSharedUtilities.framework */, CDF62342219A9BE200690038 /* ContactsFoundation.framework */, CDF62340219A9AAA00690038 /* EmailFoundation.framework */, 1A0C4467219A45D500F2AC00 /* IMCore.framework */, @@ -297,6 +313,10 @@ CD60204C219B5D710024D9C5 /* Operations */, 1A0C4469219A4BC300F2AC00 /* MBIMBridge.h */, 1A0C446A219A4BC300F2AC00 /* MBIMBridge.m */, + CD14F1A8219FF3B800E7DD22 /* MBIMUpdateQueue.h */, + CD14F1A9219FF3B800E7DD22 /* MBIMUpdateQueue.m */, + CD14F1AB219FFAE100E7DD22 /* MBIMConcurrentHTTPServer.h */, + CD14F1AC219FFAE100E7DD22 /* MBIMConcurrentHTTPServer.m */, 1ACFCFE2219EB45300E2C237 /* MBIMHTTPConnection.h */, 1ACFCFE3219EB45300E2C237 /* MBIMHTTPConnection.m */, ); @@ -462,6 +482,15 @@ path = Tests; sourceTree = ""; }; + CD14F1A5219FF22B00E7DD22 /* Categories */ = { + isa = PBXGroup; + children = ( + CD14F1A2219FF22700E7DD22 /* IMMessageItem+Encoded.h */, + CD14F1A3219FF22700E7DD22 /* IMMessageItem+Encoded.m */, + ); + path = Categories; + sourceTree = ""; + }; CD60204C219B5D710024D9C5 /* Operations */ = { isa = PBXGroup; children = ( @@ -474,6 +503,8 @@ CD60205E219B674B0024D9C5 /* MBIMConversationListOperation.m */, CD602060219B68950024D9C5 /* MBIMSendMessageOperation.h */, CD602061219B68950024D9C5 /* MBIMSendMessageOperation.m */, + CD14F19F219FE7D600E7DD22 /* MBIMUpdatePollOperation.h */, + CD14F1A0219FE7D600E7DD22 /* MBIMUpdatePollOperation.m */, ); path = Operations; sourceTree = ""; @@ -499,6 +530,7 @@ CDF62333219A895D00690038 /* kordophone */ = { isa = PBXGroup; children = ( + CD14F1A5219FF22B00E7DD22 /* Categories */, CD83E150219BDB4F00F4CCEA /* Hooking */, 1A0C446D219A4BCD00F2AC00 /* Bridge */, CDF62334219A895D00690038 /* main.m */, @@ -739,6 +771,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + CD14F1AD219FFAE100E7DD22 /* MBIMConcurrentHTTPServer.m in Sources */, 1AA43E91219EBC2C00EDF1A7 /* MBIMHTTPConnection.m in Sources */, CDF62339219A8A5600690038 /* MBIMBridge.h in Sources */, 1AA43E95219EC38E00EDF1A7 /* MBIMHTTPUtilities.m in Sources */, @@ -746,7 +779,10 @@ CDF6233A219A8A5600690038 /* MBIMBridge.m in Sources */, CDF62335219A895D00690038 /* main.m in Sources */, CD60205C219B623F0024D9C5 /* MBIMMessagesListOperation.m in Sources */, + CD14F1AA219FF3B800E7DD22 /* MBIMUpdateQueue.m in Sources */, + CD14F1A4219FF22700E7DD22 /* IMMessageItem+Encoded.m in Sources */, CD602062219B68950024D9C5 /* MBIMSendMessageOperation.m in Sources */, + CD14F1A1219FE7D600E7DD22 /* MBIMUpdatePollOperation.m in Sources */, CD602056219B5DFD0024D9C5 /* MBIMBridgeOperation.m in Sources */, CD60205F219B674B0024D9C5 /* MBIMConversationListOperation.m in Sources */, 1AA43E8F219EBB2D00EDF1A7 /* MBIMJSONDataResponse.m in Sources */, diff --git a/kordophone/Bridge/MBIMBridge.m b/kordophone/Bridge/MBIMBridge.m index 06c6a9a..cce8c65 100644 --- a/kordophone/Bridge/MBIMBridge.m +++ b/kordophone/Bridge/MBIMBridge.m @@ -8,7 +8,9 @@ #import "MBIMBridge.h" #import "MBIMBridgeOperation.h" +#import "MBIMConcurrentHTTPServer.h" #import "MBIMHTTPConnection.h" +#import "MBIMUpdateQueue.h" #import "hooking.h" #import @@ -22,7 +24,7 @@ static NSString *const MBIMBridgeToken = @"net.buzzert.kordophone"; @interface MBIMBridge (/* INTERNAL */) -@property (nonatomic, strong) HTTPServer *httpServer; +@property (nonatomic, strong) MBIMConcurrentHTTPServer *httpServer; @property (nonatomic, strong) NSOperationQueue *operationQueue; - (instancetype)_init; @@ -52,6 +54,7 @@ static NSString *const MBIMBridgeToken = @"net.buzzert.kordophone"; [sDaemonListener addHandler:self]; _operationQueue = [[NSOperationQueue alloc] init]; + _operationQueue.maxConcurrentOperationCount = 5; } return self; @@ -115,7 +118,19 @@ static NSString *const MBIMBridgeToken = @"net.buzzert.kordophone"; { NSLog(@"Received message from chat with GUID: %@", [[notification object] guid]); - // TODO: Notify observers or something + IMChat *chat = [notification object]; + IMMessage *message = [[notification userInfo] objectForKey:IMChatValueKey]; + if (chat && message) { + if (![message isFromMe]) { + MBIMUpdateItem *updateItem = [[MBIMUpdateItem alloc] init]; + updateItem.changedChat = chat; + updateItem.message = message; + + [[MBIMUpdateQueue sharedInstance] enqueueUpdateItem:updateItem]; + } else { + // TODO: care about messages from me? + } + } } - (void)_chatRegistryDidLoad:(NSNotification *)notification @@ -133,7 +148,7 @@ static NSString *const MBIMBridgeToken = @"net.buzzert.kordophone"; - (void)startWebServer { - self.httpServer = [[HTTPServer alloc] init]; + self.httpServer = [[MBIMConcurrentHTTPServer alloc] init]; [self.httpServer setConnectionClass:[MBIMHTTPConnection class]]; [self.httpServer setPort:8080]; diff --git a/kordophone/Bridge/MBIMConcurrentHTTPServer.h b/kordophone/Bridge/MBIMConcurrentHTTPServer.h new file mode 100644 index 0000000..e19cc43 --- /dev/null +++ b/kordophone/Bridge/MBIMConcurrentHTTPServer.h @@ -0,0 +1,17 @@ +// +// MBIMConcurrentHTTPServer.h +// kordophoned +// +// Created by James Magahern on 11/16/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface MBIMConcurrentHTTPServer : HTTPServer + +@end + +NS_ASSUME_NONNULL_END diff --git a/kordophone/Bridge/MBIMConcurrentHTTPServer.m b/kordophone/Bridge/MBIMConcurrentHTTPServer.m new file mode 100644 index 0000000..f05b537 --- /dev/null +++ b/kordophone/Bridge/MBIMConcurrentHTTPServer.m @@ -0,0 +1,23 @@ +// +// MBIMConcurrentHTTPServer.m +// kordophoned +// +// Created by James Magahern on 11/16/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import "MBIMConcurrentHTTPServer.h" + +@implementation MBIMConcurrentHTTPServer + +- (id)init +{ + self = [super init]; + if (self) { + connectionQueue = dispatch_queue_create("net.buzzert.MBIMConcurrentHTTPConnectionQueue", DISPATCH_QUEUE_CONCURRENT); + } + + return self; +} + +@end diff --git a/kordophone/Bridge/MBIMHTTPConnection.m b/kordophone/Bridge/MBIMHTTPConnection.m index 0479cd8..1aba86f 100644 --- a/kordophone/Bridge/MBIMHTTPConnection.m +++ b/kordophone/Bridge/MBIMHTTPConnection.m @@ -13,6 +13,7 @@ @implementation MBIMHTTPConnection { NSMutableData *_bodyData; + MBIMBridgeOperation *_currentOperation; } - (BOOL)supportsMethod:(NSString *)method atPath:(NSString *)path @@ -37,11 +38,11 @@ NSString *endpointName = [url lastPathComponent]; Class operationClass = [MBIMBridgeOperation operationClassForEndpointName:endpointName]; if (operationClass != nil) { - MBIMBridgeOperation *operation = [[operationClass alloc] initWithRequestURL:url completion:completion]; - operation.requestBodyData = _bodyData; + _currentOperation = [[operationClass alloc] initWithRequestURL:url completion:completion]; + _currentOperation.requestBodyData = _bodyData; - [[[MBIMBridge sharedInstance] operationQueue] addOperation:operation]; - dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10.0 * NSEC_PER_SEC))); + [[[MBIMBridge sharedInstance] operationQueue] addOperation:_currentOperation]; + dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(60.0 * NSEC_PER_SEC))); } else { response = [[HTTPErrorResponse alloc] initWithErrorCode:404]; } @@ -68,4 +69,10 @@ [_bodyData appendData:postDataChunk]; } +- (void)die +{ + [_currentOperation cancel]; + [super die]; +} + @end diff --git a/kordophone/Bridge/MBIMUpdateQueue.h b/kordophone/Bridge/MBIMUpdateQueue.h new file mode 100644 index 0000000..9eb15b1 --- /dev/null +++ b/kordophone/Bridge/MBIMUpdateQueue.h @@ -0,0 +1,30 @@ +// +// MBIMUpdateQueue.h +// kordophoned +// +// Created by James Magahern on 11/16/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface MBIMUpdateItem : NSObject +@property (nonatomic, strong) IMChat *changedChat; +@property (nonatomic, strong) IMMessage *message; +@end + +typedef void (^MBIMUpdateConsumer)(MBIMUpdateItem *item); + +@interface MBIMUpdateQueue : NSObject + ++ (instancetype)sharedInstance; + +- (void)addConsumer:(MBIMUpdateConsumer)consumer; +- (void)enqueueUpdateItem:(MBIMUpdateItem *)item; + +@end + +NS_ASSUME_NONNULL_END diff --git a/kordophone/Bridge/MBIMUpdateQueue.m b/kordophone/Bridge/MBIMUpdateQueue.m new file mode 100644 index 0000000..30e4091 --- /dev/null +++ b/kordophone/Bridge/MBIMUpdateQueue.m @@ -0,0 +1,61 @@ +// +// MBIMUpdateQueue.m +// kordophoned +// +// Created by James Magahern on 11/16/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import "MBIMUpdateQueue.h" + +@implementation MBIMUpdateQueue { + dispatch_queue_t _accessQueue; + NSMutableArray *_consumers; +} + ++ (instancetype)sharedInstance +{ + static MBIMUpdateQueue *sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [[self alloc] init]; + }); + + return sharedInstance; +} + +- (instancetype)init +{ + self = [super init]; + if (self) { + _accessQueue = dispatch_queue_create("net.buzzert.MBIMUpdateQueue", DISPATCH_QUEUE_SERIAL); + _consumers = [[NSMutableArray alloc] init]; + } + + return self; +} + +- (void)addConsumer:(MBIMUpdateConsumer)consumer +{ + __weak NSMutableArray *consumers = _consumers; + dispatch_async(_accessQueue, ^{ + [consumers addObject:consumer]; + }); +} + +- (void)enqueueUpdateItem:(MBIMUpdateItem *)item +{ + __weak NSMutableArray *consumers = _consumers; + dispatch_async(_accessQueue, ^{ + for (MBIMUpdateConsumer consumer in consumers) { + consumer(item); + } + + [consumers removeAllObjects]; + }); +} + +@end + +@implementation MBIMUpdateItem +@end diff --git a/kordophone/Bridge/Operations/MBIMMessagesListOperation.m b/kordophone/Bridge/Operations/MBIMMessagesListOperation.m index 9f34d62..a50c282 100644 --- a/kordophone/Bridge/Operations/MBIMMessagesListOperation.m +++ b/kordophone/Bridge/Operations/MBIMMessagesListOperation.m @@ -8,6 +8,7 @@ #import "MBIMMessagesListOperation.h" #import "MBIMHTTPUtilities.h" +#import "IMMessageItem+Encoded.h" #import @@ -52,10 +53,7 @@ NSMutableArray *messages = [NSMutableArray array]; for (IMMessageItem *imMessage in [[chat chatItems] messages]) { - NSMutableDictionary *messageDict = [NSMutableDictionary dictionary]; - messageDict[@"text"] = [[imMessage body] string]; - messageDict[@"date"] = MBIMWebServerFormatRFC822([imMessage time]); - messageDict[@"sender"] = [imMessage sender]; + NSDictionary *messageDict = [imMessage mbim_dictionaryRepresentation]; [messages addObject:messageDict]; } diff --git a/kordophone/Bridge/Operations/MBIMUpdatePollOperation.h b/kordophone/Bridge/Operations/MBIMUpdatePollOperation.h new file mode 100644 index 0000000..db2f740 --- /dev/null +++ b/kordophone/Bridge/Operations/MBIMUpdatePollOperation.h @@ -0,0 +1,17 @@ +// +// MBIMUpdatePollOperation.h +// kordophoned +// +// Created by James Magahern on 11/16/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import "MBIMBridgeOperation.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MBIMUpdatePollOperation : MBIMBridgeOperation + +@end + +NS_ASSUME_NONNULL_END diff --git a/kordophone/Bridge/Operations/MBIMUpdatePollOperation.m b/kordophone/Bridge/Operations/MBIMUpdatePollOperation.m new file mode 100644 index 0000000..d0db0c9 --- /dev/null +++ b/kordophone/Bridge/Operations/MBIMUpdatePollOperation.m @@ -0,0 +1,39 @@ +// +// MBIMUpdatePollOperation.m +// kordophoned +// +// Created by James Magahern on 11/16/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import "MBIMUpdatePollOperation.h" +#import "MBIMUpdateQueue.h" +#import "IMMessageItem+Encoded.h" + +@implementation MBIMUpdatePollOperation + ++ (void)load { [super load]; } + ++ (NSString *)endpointName +{ + return @"pollUpdates"; +} + +- (void)main +{ + MBIMUpdateConsumer consumer = ^(MBIMUpdateItem *nextUpdateItem) { + NSDictionary *updateDict = @{ + @"guid" : [[nextUpdateItem changedChat] guid], + @"message" : [[nextUpdateItem message] mbim_dictionaryRepresentation] + }; + + MBIMJSONDataResponse *response = [MBIMJSONDataResponse responseWithJSONObject:updateDict]; + self.serverCompletionBlock(response); + }; + + [[MBIMUpdateQueue sharedInstance] addConsumer:consumer]; +} + +// TODO: cancel needs to remove the consumer from the update queue + +@end diff --git a/kordophone/Categories/IMMessageItem+Encoded.h b/kordophone/Categories/IMMessageItem+Encoded.h new file mode 100644 index 0000000..222d704 --- /dev/null +++ b/kordophone/Categories/IMMessageItem+Encoded.h @@ -0,0 +1,24 @@ +// +// IMMessageItem+Encoded.h +// kordophoned +// +// Created by James Magahern on 11/16/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface IMMessage (Encoded) +- (NSDictionary *)mbim_dictionaryRepresentation; + +@end + +@interface IMMessageItem (Encoded) +- (NSDictionary *)mbim_dictionaryRepresentation; + +@end + +NS_ASSUME_NONNULL_END diff --git a/kordophone/Categories/IMMessageItem+Encoded.m b/kordophone/Categories/IMMessageItem+Encoded.m new file mode 100644 index 0000000..7305780 --- /dev/null +++ b/kordophone/Categories/IMMessageItem+Encoded.m @@ -0,0 +1,38 @@ +// +// IMMessageItem+Encoded.m +// kordophoned +// +// Created by James Magahern on 11/16/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import "IMMessageItem+Encoded.h" +#import "MBIMHTTPUtilities.h" + +@implementation IMMessage (Encoded) + +- (NSDictionary *)mbim_dictionaryRepresentation +{ + NSMutableDictionary *messageDict = [NSMutableDictionary dictionary]; + messageDict[@"text"] = [[self text] string]; + messageDict[@"date"] = MBIMWebServerFormatRFC822([self time]); + messageDict[@"sender"] = [[self sender] displayID]; + + return messageDict; +} + +@end + +@implementation IMMessageItem (Encoded) + +- (NSDictionary *)mbim_dictionaryRepresentation +{ + NSMutableDictionary *messageDict = [NSMutableDictionary dictionary]; + messageDict[@"text"] = [[self body] string]; + messageDict[@"date"] = MBIMWebServerFormatRFC822([self time]); + messageDict[@"sender"] = [self sender]; + + return messageDict; +} + +@end