Private
Public Access
1
0

Updates to sending and message sequences

This commit is contained in:
James Magahern
2018-11-20 19:57:35 -07:00
parent ddec4be8d6
commit 4f5cd058c5
17 changed files with 264 additions and 45 deletions

View File

@@ -8,9 +8,10 @@
#import "MBIMUpdatePollOperation.h"
#import "MBIMUpdateQueue.h"
#import "IMMessageItem+Encoded.h"
@implementation MBIMUpdatePollOperation
@implementation MBIMUpdatePollOperation {
__strong MBIMUpdateConsumer _updateConsumer;
}
+ (void)load { [super load]; }
@@ -21,19 +22,27 @@
- (void)main
{
MBIMUpdateConsumer consumer = ^(MBIMUpdateItem *nextUpdateItem) {
NSDictionary *updateDict = @{
@"guid" : [[nextUpdateItem changedChat] guid],
@"message" : [[nextUpdateItem message] mbim_dictionaryRepresentation]
};
__weak __auto_type weakSelf = self;
_updateConsumer = ^(MBIMUpdateItem *nextUpdateItem) {
NSDictionary *updateDict = [nextUpdateItem dictionaryRepresentation];
MBIMJSONDataResponse *response = [MBIMJSONDataResponse responseWithJSONObject:updateDict];
self.serverCompletionBlock(response);
weakSelf.serverCompletionBlock(response);
};
[[MBIMUpdateQueue sharedInstance] addConsumer:consumer];
[[MBIMUpdateQueue sharedInstance] addConsumer:_updateConsumer];
}
// TODO: cancel needs to remove the consumer from the update queue
- (void)cancel
{
[super cancel];
[[MBIMUpdateQueue sharedInstance] removeConsumer:_updateConsumer];
}
- (NSObject<HTTPResponse> *)cancelAndReturnTimeoutResponse
{
[self cancel];
return [[HTTPErrorResponse alloc] initWithErrorCode:205]; // 205 = nothing to report
}
@end