Supports polling for updates
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#import "MBIMMessagesListOperation.h"
|
||||
#import "MBIMHTTPUtilities.h"
|
||||
#import "IMMessageItem+Encoded.h"
|
||||
|
||||
#import <IMCore/IMCore.h>
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user