Private
Public Access
1
0
Files
Kordophone/kordophone/Bridge/Operations/MBIMMessagesListOperation.m
James Magahern 4f7a6d1b87 Move off of macosxinternal sdk
This moves kordophone off of using the internal SDK and switches to using class dumped headers instead.
2019-12-16 17:29:53 -08:00

60 lines
1.7 KiB
Objective-C

//
// MBIMMessagesListOperation.m
// kordophoned
//
// Created by James Magahern on 11/13/18.
// Copyright © 2018 James Magahern. All rights reserved.
//
#import "MBIMMessagesListOperation.h"
#import "MBIMHTTPUtilities.h"
#import "IMMessageItem+Encoded.h"
#import "IMCore_ClassDump.h"
@implementation MBIMMessagesListOperation
+ (void)load { [super load]; }
+ (NSString *)endpointName
{
return @"messages";
}
- (void)main
{
__block NSObject<HTTPResponse> *response = nil;
do {
NSString *guid = [self valueForQueryItemWithName:@"guid"];
if (!guid) {
MBIMLogInfo(@"No query item provided");
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
break;
}
__block NSMutableArray *messages = [NSMutableArray array];
dispatch_sync([[self class] sharedIMAccessQueue], ^{
IMChat *chat = [[IMChatRegistry sharedInstance] existingChatWithGUID:guid];
if (!chat) {
MBIMLogInfo(@"Chat with guid: %@ not found", guid);
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
} else {
// Load messages
[chat loadMessagesBeforeDate:[NSDate date] limit:50 loadImmediately:YES];
[[chat chatItems] enumerateMessagesWithOptions:0 usingBlock:^(IMMessage *message, BOOL *stop) {
NSDictionary *messageDict = [message mbim_dictionaryRepresentation];
[messages addObject:messageDict];
}];
}
});
response = [MBIMJSONDataResponse responseWithJSONObject:messages];
} while (0);
self.serverCompletionBlock(response);
}
@end