Batch updates, and fixing bug where daemon would crash when accessing IMCore stuff from different threads
This commit is contained in:
@@ -20,17 +20,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");
|
||||
@@ -38,18 +30,19 @@
|
||||
break;
|
||||
}
|
||||
|
||||
IMChat *chat = [sChatRegistry existingChatWithGUID:guid];
|
||||
if (!chat) {
|
||||
NSLog(@"Chat with guid: %@ not found", guid);
|
||||
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: be smarter about this and mark individual messages as read? Could lead
|
||||
// to a race condition
|
||||
if ([chat unreadMessageCount] > 0) {
|
||||
[chat markAllMessagesAsRead];
|
||||
}
|
||||
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 {
|
||||
// TODO: be smarter about this and mark individual messages as read? Could lead
|
||||
// to a race condition
|
||||
if ([chat unreadMessageCount] > 0) {
|
||||
[chat markAllMessagesAsRead];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
response = [[HTTPErrorResponse alloc] initWithErrorCode:200];
|
||||
} while (0);
|
||||
|
||||
Reference in New Issue
Block a user