2018-11-20 19:57:35 -07:00
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
{
|
2018-11-21 15:51:51 -07:00
|
|
|
__block NSObject<HTTPResponse> *response = nil;
|
2018-11-20 19:57:35 -07:00
|
|
|
do {
|
2018-11-21 15:51:51 -07:00
|
|
|
NSString *guid = [self valueForQueryItemWithName:@"guid"];
|
2018-11-20 19:57:35 -07:00
|
|
|
|
|
|
|
|
if (!guid) {
|
2019-01-22 23:31:36 -08:00
|
|
|
MBIMLogInfo(@"No query item provided");
|
2018-11-20 19:57:35 -07:00
|
|
|
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 15:51:51 -07:00
|
|
|
dispatch_sync([[self class] sharedIMAccessQueue], ^{
|
|
|
|
|
IMChat *chat = [sChatRegistry existingChatWithGUID:guid];
|
|
|
|
|
if (!chat) {
|
2019-01-22 23:31:36 -08:00
|
|
|
MBIMLogInfo(@"Chat with guid: %@ not found", guid);
|
2018-11-21 15:51:51 -07:00
|
|
|
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];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-11-20 19:57:35 -07:00
|
|
|
|
|
|
|
|
response = [[HTTPErrorResponse alloc] initWithErrorCode:200];
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
|
|
self.serverCompletionBlock(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|