Batch updates, and fixing bug where daemon would crash when accessing IMCore stuff from different threads
This commit is contained in:
@@ -23,17 +23,9 @@
|
||||
|
||||
- (void)main
|
||||
{
|
||||
NSObject<HTTPResponse> *response = nil;
|
||||
__block NSObject<HTTPResponse> *response = nil;
|
||||
do {
|
||||
NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:self.requestURL resolvingAgainstBaseURL:NO];
|
||||
|
||||
NSString *guid = nil;
|
||||
for (NSURLQueryItem *queryItem in [urlComponents queryItems]) {
|
||||
if ([[queryItem name] isEqualToString:@"guid"]) {
|
||||
guid = [queryItem value];
|
||||
break;
|
||||
}
|
||||
}
|
||||
NSString *guid = [self valueForQueryItemWithName:@"guid"];
|
||||
|
||||
if (!guid) {
|
||||
NSLog(@"No query item provided");
|
||||
@@ -41,21 +33,22 @@
|
||||
break;
|
||||
}
|
||||
|
||||
IMChat *chat = [sChatRegistry existingChatWithGUID:guid];
|
||||
if (!chat) {
|
||||
NSLog(@"Chat with guid: %@ not found", guid);
|
||||
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
|
||||
break;
|
||||
}
|
||||
|
||||
// Load messages
|
||||
[chat loadMessagesBeforeDate:[NSDate date] limit:50 loadImmediately:YES];
|
||||
|
||||
NSMutableArray *messages = [NSMutableArray array];
|
||||
for (IMMessageItem *imMessage in [[chat chatItems] messages]) {
|
||||
NSDictionary *messageDict = [imMessage mbim_dictionaryRepresentation];
|
||||
[messages addObject:messageDict];
|
||||
}
|
||||
__block NSMutableArray *messages = [NSMutableArray array];
|
||||
dispatch_sync([[self class] sharedIMAccessQueue], ^{
|
||||
IMChat *chat = [sChatRegistry existingChatWithGUID:guid];
|
||||
if (!chat) {
|
||||
NSLog(@"Chat with guid: %@ not found", guid);
|
||||
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
|
||||
} else {
|
||||
// Load messages
|
||||
[chat loadMessagesBeforeDate:[NSDate date] limit:50 loadImmediately:YES];
|
||||
|
||||
for (IMMessageItem *imMessage in [[chat chatItems] messages]) {
|
||||
NSDictionary *messageDict = [imMessage mbim_dictionaryRepresentation];
|
||||
[messages addObject:messageDict];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
response = [MBIMJSONDataResponse responseWithJSONObject:messages];
|
||||
} while (0);
|
||||
|
||||
Reference in New Issue
Block a user