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

@@ -0,0 +1,60 @@
//
// MBIMMarkOperation.m
// kordophoned
//
// Created by James Magahern on 11/19/18.
// Copyright © 2018 James Magahern. All rights reserved.
//
#import "MBIMMarkOperation.h"
#import <IMCore/IMCore.h>
@implementation MBIMMarkOperation
+ (void)load { [super load]; }
+ (NSString *)endpointName
{
return @"markConversation";
}
- (void)main
{
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;
}
}
if (!guid) {
NSLog(@"No query item provided");
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
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];
}
response = [[HTTPErrorResponse alloc] initWithErrorCode:200];
} while (0);
self.serverCompletionBlock(response);
}
@end