Supports polling for updates
This commit is contained in:
@@ -64,6 +64,11 @@
|
|||||||
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 */; };
|
||||||
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 */; };
|
||||||
|
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 */; };
|
CD602056219B5DFD0024D9C5 /* MBIMBridgeOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CD602055219B5DFD0024D9C5 /* MBIMBridgeOperation.m */; };
|
||||||
CD60205C219B623F0024D9C5 /* MBIMMessagesListOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CD60205B219B623F0024D9C5 /* MBIMMessagesListOperation.m */; };
|
CD60205C219B623F0024D9C5 /* MBIMMessagesListOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CD60205B219B623F0024D9C5 /* MBIMMessagesListOperation.m */; };
|
||||||
CD60205F219B674B0024D9C5 /* MBIMConversationListOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CD60205E219B674B0024D9C5 /* MBIMConversationListOperation.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; };
|
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>"; };
|
||||||
|
CD14F19F219FE7D600E7DD22 /* MBIMUpdatePollOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMUpdatePollOperation.h; sourceTree = "<group>"; };
|
||||||
|
CD14F1A0219FE7D600E7DD22 /* MBIMUpdatePollOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMUpdatePollOperation.m; sourceTree = "<group>"; };
|
||||||
|
CD14F1A2219FF22700E7DD22 /* IMMessageItem+Encoded.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "IMMessageItem+Encoded.h"; sourceTree = "<group>"; };
|
||||||
|
CD14F1A3219FF22700E7DD22 /* IMMessageItem+Encoded.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "IMMessageItem+Encoded.m"; sourceTree = "<group>"; };
|
||||||
|
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 = "<group>"; };
|
||||||
|
CD14F1A9219FF3B800E7DD22 /* MBIMUpdateQueue.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMUpdateQueue.m; sourceTree = "<group>"; };
|
||||||
|
CD14F1AB219FFAE100E7DD22 /* MBIMConcurrentHTTPServer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMConcurrentHTTPServer.h; sourceTree = "<group>"; };
|
||||||
|
CD14F1AC219FFAE100E7DD22 /* MBIMConcurrentHTTPServer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMConcurrentHTTPServer.m; sourceTree = "<group>"; };
|
||||||
CD602054219B5DFD0024D9C5 /* MBIMBridgeOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMBridgeOperation.h; sourceTree = "<group>"; };
|
CD602054219B5DFD0024D9C5 /* MBIMBridgeOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMBridgeOperation.h; sourceTree = "<group>"; };
|
||||||
CD602055219B5DFD0024D9C5 /* MBIMBridgeOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMBridgeOperation.m; sourceTree = "<group>"; };
|
CD602055219B5DFD0024D9C5 /* MBIMBridgeOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMBridgeOperation.m; sourceTree = "<group>"; };
|
||||||
CD60205A219B623F0024D9C5 /* MBIMMessagesListOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMMessagesListOperation.h; sourceTree = "<group>"; };
|
CD60205A219B623F0024D9C5 /* MBIMMessagesListOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMMessagesListOperation.h; sourceTree = "<group>"; };
|
||||||
@@ -233,6 +247,7 @@
|
|||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
CD14F1A7219FF2F400E7DD22 /* IMSharedUtilities.framework in Frameworks */,
|
||||||
1ACFCFDF219EB31400E2C237 /* CocoaHTTPServer.framework in Frameworks */,
|
1ACFCFDF219EB31400E2C237 /* CocoaHTTPServer.framework in Frameworks */,
|
||||||
CDF62343219A9BE200690038 /* ContactsFoundation.framework in Frameworks */,
|
CDF62343219A9BE200690038 /* ContactsFoundation.framework in Frameworks */,
|
||||||
CDF6233E219A8AFC00690038 /* IMCore.framework in Frameworks */,
|
CDF6233E219A8AFC00690038 /* IMCore.framework in Frameworks */,
|
||||||
@@ -280,6 +295,7 @@
|
|||||||
1A0C445E219A45B400F2AC00 /* Frameworks */ = {
|
1A0C445E219A45B400F2AC00 /* Frameworks */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
CD14F1A6219FF2F400E7DD22 /* IMSharedUtilities.framework */,
|
||||||
CDF62342219A9BE200690038 /* ContactsFoundation.framework */,
|
CDF62342219A9BE200690038 /* ContactsFoundation.framework */,
|
||||||
CDF62340219A9AAA00690038 /* EmailFoundation.framework */,
|
CDF62340219A9AAA00690038 /* EmailFoundation.framework */,
|
||||||
1A0C4467219A45D500F2AC00 /* IMCore.framework */,
|
1A0C4467219A45D500F2AC00 /* IMCore.framework */,
|
||||||
@@ -297,6 +313,10 @@
|
|||||||
CD60204C219B5D710024D9C5 /* Operations */,
|
CD60204C219B5D710024D9C5 /* Operations */,
|
||||||
1A0C4469219A4BC300F2AC00 /* MBIMBridge.h */,
|
1A0C4469219A4BC300F2AC00 /* MBIMBridge.h */,
|
||||||
1A0C446A219A4BC300F2AC00 /* MBIMBridge.m */,
|
1A0C446A219A4BC300F2AC00 /* MBIMBridge.m */,
|
||||||
|
CD14F1A8219FF3B800E7DD22 /* MBIMUpdateQueue.h */,
|
||||||
|
CD14F1A9219FF3B800E7DD22 /* MBIMUpdateQueue.m */,
|
||||||
|
CD14F1AB219FFAE100E7DD22 /* MBIMConcurrentHTTPServer.h */,
|
||||||
|
CD14F1AC219FFAE100E7DD22 /* MBIMConcurrentHTTPServer.m */,
|
||||||
1ACFCFE2219EB45300E2C237 /* MBIMHTTPConnection.h */,
|
1ACFCFE2219EB45300E2C237 /* MBIMHTTPConnection.h */,
|
||||||
1ACFCFE3219EB45300E2C237 /* MBIMHTTPConnection.m */,
|
1ACFCFE3219EB45300E2C237 /* MBIMHTTPConnection.m */,
|
||||||
);
|
);
|
||||||
@@ -462,6 +482,15 @@
|
|||||||
path = Tests;
|
path = Tests;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
CD14F1A5219FF22B00E7DD22 /* Categories */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
CD14F1A2219FF22700E7DD22 /* IMMessageItem+Encoded.h */,
|
||||||
|
CD14F1A3219FF22700E7DD22 /* IMMessageItem+Encoded.m */,
|
||||||
|
);
|
||||||
|
path = Categories;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
CD60204C219B5D710024D9C5 /* Operations */ = {
|
CD60204C219B5D710024D9C5 /* Operations */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@@ -474,6 +503,8 @@
|
|||||||
CD60205E219B674B0024D9C5 /* MBIMConversationListOperation.m */,
|
CD60205E219B674B0024D9C5 /* MBIMConversationListOperation.m */,
|
||||||
CD602060219B68950024D9C5 /* MBIMSendMessageOperation.h */,
|
CD602060219B68950024D9C5 /* MBIMSendMessageOperation.h */,
|
||||||
CD602061219B68950024D9C5 /* MBIMSendMessageOperation.m */,
|
CD602061219B68950024D9C5 /* MBIMSendMessageOperation.m */,
|
||||||
|
CD14F19F219FE7D600E7DD22 /* MBIMUpdatePollOperation.h */,
|
||||||
|
CD14F1A0219FE7D600E7DD22 /* MBIMUpdatePollOperation.m */,
|
||||||
);
|
);
|
||||||
path = Operations;
|
path = Operations;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -499,6 +530,7 @@
|
|||||||
CDF62333219A895D00690038 /* kordophone */ = {
|
CDF62333219A895D00690038 /* kordophone */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
CD14F1A5219FF22B00E7DD22 /* Categories */,
|
||||||
CD83E150219BDB4F00F4CCEA /* Hooking */,
|
CD83E150219BDB4F00F4CCEA /* Hooking */,
|
||||||
1A0C446D219A4BCD00F2AC00 /* Bridge */,
|
1A0C446D219A4BCD00F2AC00 /* Bridge */,
|
||||||
CDF62334219A895D00690038 /* main.m */,
|
CDF62334219A895D00690038 /* main.m */,
|
||||||
@@ -739,6 +771,7 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
CD14F1AD219FFAE100E7DD22 /* MBIMConcurrentHTTPServer.m in Sources */,
|
||||||
1AA43E91219EBC2C00EDF1A7 /* MBIMHTTPConnection.m in Sources */,
|
1AA43E91219EBC2C00EDF1A7 /* MBIMHTTPConnection.m in Sources */,
|
||||||
CDF62339219A8A5600690038 /* MBIMBridge.h in Sources */,
|
CDF62339219A8A5600690038 /* MBIMBridge.h in Sources */,
|
||||||
1AA43E95219EC38E00EDF1A7 /* MBIMHTTPUtilities.m in Sources */,
|
1AA43E95219EC38E00EDF1A7 /* MBIMHTTPUtilities.m in Sources */,
|
||||||
@@ -746,7 +779,10 @@
|
|||||||
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 */,
|
||||||
|
CD14F1AA219FF3B800E7DD22 /* MBIMUpdateQueue.m in Sources */,
|
||||||
|
CD14F1A4219FF22700E7DD22 /* IMMessageItem+Encoded.m in Sources */,
|
||||||
CD602062219B68950024D9C5 /* MBIMSendMessageOperation.m in Sources */,
|
CD602062219B68950024D9C5 /* MBIMSendMessageOperation.m in Sources */,
|
||||||
|
CD14F1A1219FE7D600E7DD22 /* MBIMUpdatePollOperation.m in Sources */,
|
||||||
CD602056219B5DFD0024D9C5 /* MBIMBridgeOperation.m in Sources */,
|
CD602056219B5DFD0024D9C5 /* MBIMBridgeOperation.m in Sources */,
|
||||||
CD60205F219B674B0024D9C5 /* MBIMConversationListOperation.m in Sources */,
|
CD60205F219B674B0024D9C5 /* MBIMConversationListOperation.m in Sources */,
|
||||||
1AA43E8F219EBB2D00EDF1A7 /* MBIMJSONDataResponse.m in Sources */,
|
1AA43E8F219EBB2D00EDF1A7 /* MBIMJSONDataResponse.m in Sources */,
|
||||||
|
|||||||
@@ -8,7 +8,9 @@
|
|||||||
|
|
||||||
#import "MBIMBridge.h"
|
#import "MBIMBridge.h"
|
||||||
#import "MBIMBridgeOperation.h"
|
#import "MBIMBridgeOperation.h"
|
||||||
|
#import "MBIMConcurrentHTTPServer.h"
|
||||||
#import "MBIMHTTPConnection.h"
|
#import "MBIMHTTPConnection.h"
|
||||||
|
#import "MBIMUpdateQueue.h"
|
||||||
#import "hooking.h"
|
#import "hooking.h"
|
||||||
|
|
||||||
#import <CocoaHTTPServer/HTTPServer.h>
|
#import <CocoaHTTPServer/HTTPServer.h>
|
||||||
@@ -22,7 +24,7 @@
|
|||||||
static NSString *const MBIMBridgeToken = @"net.buzzert.kordophone";
|
static NSString *const MBIMBridgeToken = @"net.buzzert.kordophone";
|
||||||
|
|
||||||
@interface MBIMBridge (/* INTERNAL */)
|
@interface MBIMBridge (/* INTERNAL */)
|
||||||
@property (nonatomic, strong) HTTPServer *httpServer;
|
@property (nonatomic, strong) MBIMConcurrentHTTPServer *httpServer;
|
||||||
@property (nonatomic, strong) NSOperationQueue *operationQueue;
|
@property (nonatomic, strong) NSOperationQueue *operationQueue;
|
||||||
|
|
||||||
- (instancetype)_init;
|
- (instancetype)_init;
|
||||||
@@ -52,6 +54,7 @@ static NSString *const MBIMBridgeToken = @"net.buzzert.kordophone";
|
|||||||
[sDaemonListener addHandler:self];
|
[sDaemonListener addHandler:self];
|
||||||
|
|
||||||
_operationQueue = [[NSOperationQueue alloc] init];
|
_operationQueue = [[NSOperationQueue alloc] init];
|
||||||
|
_operationQueue.maxConcurrentOperationCount = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@@ -115,7 +118,19 @@ static NSString *const MBIMBridgeToken = @"net.buzzert.kordophone";
|
|||||||
{
|
{
|
||||||
NSLog(@"Received message from chat with GUID: %@", [[notification object] guid]);
|
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
|
- (void)_chatRegistryDidLoad:(NSNotification *)notification
|
||||||
@@ -133,7 +148,7 @@ static NSString *const MBIMBridgeToken = @"net.buzzert.kordophone";
|
|||||||
|
|
||||||
- (void)startWebServer
|
- (void)startWebServer
|
||||||
{
|
{
|
||||||
self.httpServer = [[HTTPServer alloc] init];
|
self.httpServer = [[MBIMConcurrentHTTPServer alloc] init];
|
||||||
[self.httpServer setConnectionClass:[MBIMHTTPConnection class]];
|
[self.httpServer setConnectionClass:[MBIMHTTPConnection class]];
|
||||||
[self.httpServer setPort:8080];
|
[self.httpServer setPort:8080];
|
||||||
|
|
||||||
|
|||||||
17
kordophone/Bridge/MBIMConcurrentHTTPServer.h
Normal file
17
kordophone/Bridge/MBIMConcurrentHTTPServer.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// MBIMConcurrentHTTPServer.h
|
||||||
|
// kordophoned
|
||||||
|
//
|
||||||
|
// Created by James Magahern on 11/16/18.
|
||||||
|
// Copyright © 2018 James Magahern. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <CocoaHTTPServer/HTTPServer.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface MBIMConcurrentHTTPServer : HTTPServer
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
23
kordophone/Bridge/MBIMConcurrentHTTPServer.m
Normal file
23
kordophone/Bridge/MBIMConcurrentHTTPServer.m
Normal file
@@ -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
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
@implementation MBIMHTTPConnection {
|
@implementation MBIMHTTPConnection {
|
||||||
NSMutableData *_bodyData;
|
NSMutableData *_bodyData;
|
||||||
|
MBIMBridgeOperation *_currentOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)supportsMethod:(NSString *)method atPath:(NSString *)path
|
- (BOOL)supportsMethod:(NSString *)method atPath:(NSString *)path
|
||||||
@@ -37,11 +38,11 @@
|
|||||||
NSString *endpointName = [url lastPathComponent];
|
NSString *endpointName = [url lastPathComponent];
|
||||||
Class operationClass = [MBIMBridgeOperation operationClassForEndpointName:endpointName];
|
Class operationClass = [MBIMBridgeOperation operationClassForEndpointName:endpointName];
|
||||||
if (operationClass != nil) {
|
if (operationClass != nil) {
|
||||||
MBIMBridgeOperation *operation = [[operationClass alloc] initWithRequestURL:url completion:completion];
|
_currentOperation = [[operationClass alloc] initWithRequestURL:url completion:completion];
|
||||||
operation.requestBodyData = _bodyData;
|
_currentOperation.requestBodyData = _bodyData;
|
||||||
|
|
||||||
[[[MBIMBridge sharedInstance] operationQueue] addOperation:operation];
|
[[[MBIMBridge sharedInstance] operationQueue] addOperation:_currentOperation];
|
||||||
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10.0 * NSEC_PER_SEC)));
|
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(60.0 * NSEC_PER_SEC)));
|
||||||
} else {
|
} else {
|
||||||
response = [[HTTPErrorResponse alloc] initWithErrorCode:404];
|
response = [[HTTPErrorResponse alloc] initWithErrorCode:404];
|
||||||
}
|
}
|
||||||
@@ -68,4 +69,10 @@
|
|||||||
[_bodyData appendData:postDataChunk];
|
[_bodyData appendData:postDataChunk];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)die
|
||||||
|
{
|
||||||
|
[_currentOperation cancel];
|
||||||
|
[super die];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
30
kordophone/Bridge/MBIMUpdateQueue.h
Normal file
30
kordophone/Bridge/MBIMUpdateQueue.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// MBIMUpdateQueue.h
|
||||||
|
// kordophoned
|
||||||
|
//
|
||||||
|
// Created by James Magahern on 11/16/18.
|
||||||
|
// Copyright © 2018 James Magahern. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <IMCore/IMCore.h>
|
||||||
|
#import <IMFoundation/IMFoundation.h>
|
||||||
|
|
||||||
|
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
|
||||||
61
kordophone/Bridge/MBIMUpdateQueue.m
Normal file
61
kordophone/Bridge/MBIMUpdateQueue.m
Normal file
@@ -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
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#import "MBIMMessagesListOperation.h"
|
#import "MBIMMessagesListOperation.h"
|
||||||
#import "MBIMHTTPUtilities.h"
|
#import "MBIMHTTPUtilities.h"
|
||||||
|
#import "IMMessageItem+Encoded.h"
|
||||||
|
|
||||||
#import <IMCore/IMCore.h>
|
#import <IMCore/IMCore.h>
|
||||||
|
|
||||||
@@ -52,10 +53,7 @@
|
|||||||
|
|
||||||
NSMutableArray *messages = [NSMutableArray array];
|
NSMutableArray *messages = [NSMutableArray array];
|
||||||
for (IMMessageItem *imMessage in [[chat chatItems] messages]) {
|
for (IMMessageItem *imMessage in [[chat chatItems] messages]) {
|
||||||
NSMutableDictionary *messageDict = [NSMutableDictionary dictionary];
|
NSDictionary *messageDict = [imMessage mbim_dictionaryRepresentation];
|
||||||
messageDict[@"text"] = [[imMessage body] string];
|
|
||||||
messageDict[@"date"] = MBIMWebServerFormatRFC822([imMessage time]);
|
|
||||||
messageDict[@"sender"] = [imMessage sender];
|
|
||||||
[messages addObject:messageDict];
|
[messages addObject:messageDict];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
17
kordophone/Bridge/Operations/MBIMUpdatePollOperation.h
Normal file
17
kordophone/Bridge/Operations/MBIMUpdatePollOperation.h
Normal file
@@ -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
|
||||||
39
kordophone/Bridge/Operations/MBIMUpdatePollOperation.m
Normal file
39
kordophone/Bridge/Operations/MBIMUpdatePollOperation.m
Normal file
@@ -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
|
||||||
24
kordophone/Categories/IMMessageItem+Encoded.h
Normal file
24
kordophone/Categories/IMMessageItem+Encoded.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
//
|
||||||
|
// IMMessageItem+Encoded.h
|
||||||
|
// kordophoned
|
||||||
|
//
|
||||||
|
// Created by James Magahern on 11/16/18.
|
||||||
|
// Copyright © 2018 James Magahern. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <IMCore/IMCore.h>
|
||||||
|
#import <IMSharedUtilities/IMSharedUtilities.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@interface IMMessage (Encoded)
|
||||||
|
- (NSDictionary *)mbim_dictionaryRepresentation;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface IMMessageItem (Encoded)
|
||||||
|
- (NSDictionary *)mbim_dictionaryRepresentation;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
38
kordophone/Categories/IMMessageItem+Encoded.m
Normal file
38
kordophone/Categories/IMMessageItem+Encoded.m
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user