2018-11-13 12:29:15 -08:00
|
|
|
//
|
|
|
|
|
// MBIMConversationListOperation.m
|
|
|
|
|
// kordophoned
|
|
|
|
|
//
|
|
|
|
|
// Created by James Magahern on 11/13/18.
|
|
|
|
|
// Copyright © 2018 James Magahern. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "MBIMConversationListOperation.h"
|
2018-11-16 01:30:38 -08:00
|
|
|
#import "MBIMHTTPUtilities.h"
|
2018-11-13 12:29:15 -08:00
|
|
|
|
|
|
|
|
#import <IMCore/IMCore.h>
|
|
|
|
|
|
|
|
|
|
@implementation MBIMConversationListOperation
|
|
|
|
|
|
|
|
|
|
+ (void)load { [super load]; }
|
|
|
|
|
|
|
|
|
|
+ (NSString *)endpointName
|
|
|
|
|
{
|
|
|
|
|
return @"conversations";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)main
|
|
|
|
|
{
|
|
|
|
|
NSArray<IMChat *> *chats = [sChatRegistry allExistingChats];
|
|
|
|
|
|
|
|
|
|
NSMutableArray *conversations = [NSMutableArray array];
|
|
|
|
|
for (IMChat *chat in chats) {
|
|
|
|
|
NSMutableDictionary *chatDict = [NSMutableDictionary dictionary];
|
|
|
|
|
chatDict[@"guid"] = [chat guid];
|
|
|
|
|
chatDict[@"displayName"] = [chat displayName];
|
2018-11-16 01:30:38 -08:00
|
|
|
chatDict[@"date"] = MBIMWebServerFormatRFC822([chat lastFinishedMessageDate]);
|
2018-11-13 12:29:15 -08:00
|
|
|
|
2018-11-14 23:12:41 -08:00
|
|
|
IMMessage *lastMessage = [chat lastMessage];
|
|
|
|
|
if (lastMessage) {
|
|
|
|
|
chatDict[@"lastMessagePreview"] = [[lastMessage text] string];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSMutableArray *participantStrings = [NSMutableArray array];
|
|
|
|
|
for (IMHandle *participantHandle in chat.participants) {
|
|
|
|
|
NSString *participantString = [participantHandle displayNameForChat:chat];
|
|
|
|
|
if (participantString) {
|
|
|
|
|
[participantStrings addObject:participantString];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chatDict[@"participantDisplayNames"] = participantStrings;
|
|
|
|
|
|
2018-11-13 12:29:15 -08:00
|
|
|
[conversations addObject:chatDict];
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-16 01:30:38 -08:00
|
|
|
MBIMJSONDataResponse *response = [MBIMJSONDataResponse responseWithJSONObject:conversations];
|
2018-11-13 12:29:15 -08:00
|
|
|
self.serverCompletionBlock(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|