MessagesList: Add support for beforeMessageGUID and beforeDate
This commit is contained in:
@@ -9,9 +9,12 @@
|
||||
#import "MBIMMessagesListOperation.h"
|
||||
#import "MBIMHTTPUtilities.h"
|
||||
#import "IMMessageItem+Encoded.h"
|
||||
#import "MBIMErrorResponse.h"
|
||||
|
||||
#import "IMCore_ClassDump.h"
|
||||
|
||||
#define kDefaultMessagesLimit 75
|
||||
|
||||
@implementation MBIMMessagesListOperation
|
||||
|
||||
+ (void)load { [super load]; }
|
||||
@@ -25,11 +28,26 @@
|
||||
{
|
||||
__block NSObject<HTTPResponse> *response = nil;
|
||||
do {
|
||||
// Required parameters
|
||||
NSString *guid = [self valueForQueryItemWithName:@"guid"];
|
||||
|
||||
// Optional
|
||||
NSString *limitValue = [self valueForQueryItemWithName:@"limit"];
|
||||
|
||||
NSDate *beforeDate = nil;
|
||||
NSString *beforeDateValue = [self valueForQueryItemWithName:@"beforeDate"];
|
||||
if (beforeDateValue) {
|
||||
beforeDate = [beforeDateValue ISO8601Date];
|
||||
if (!beforeDate) {
|
||||
response = [[MBIMErrorResponse alloc] initWithErrorCode:500 message:@"Unable to decode ISO8601 beforeDate value"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
NSString *beforeMessageGUID = [self valueForQueryItemWithName:@"beforeMessageGUID"];
|
||||
|
||||
if (!guid) {
|
||||
MBIMLogInfo(@"No query item provided");
|
||||
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
|
||||
response = [[MBIMErrorResponse alloc] initWithErrorCode:500 message:@"No GUID provided."];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -41,12 +59,33 @@
|
||||
response = [[HTTPErrorResponse alloc] initWithErrorCode:500];
|
||||
} else {
|
||||
// Load messages
|
||||
[chat loadMessagesBeforeDate:[NSDate date] limit:50 loadImmediately:YES];
|
||||
|
||||
[[chat chatItems] enumerateMessagesWithOptions:0 usingBlock:^(IMMessage *message, BOOL *stop) {
|
||||
NSDictionary *messageDict = [message mbim_dictionaryRepresentation];
|
||||
[messages addObject:messageDict];
|
||||
}];
|
||||
// (Must be done on main queue for some reason)
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
NSUInteger limit = kDefaultMessagesLimit;
|
||||
if (limitValue) {
|
||||
limit = [limitValue integerValue];
|
||||
}
|
||||
|
||||
if (beforeMessageGUID) {
|
||||
if ([chat respondsToSelector:@selector(loadMessagesBeforeAndAfterGUID:numberOfMessagesToLoadBeforeGUID:numberOfMessagesToLoadAfterGUID:loadImmediately:threadIdentifier:)]) {
|
||||
[chat loadMessagesBeforeAndAfterGUID:beforeMessageGUID numberOfMessagesToLoadBeforeGUID:limit numberOfMessagesToLoadAfterGUID:0 loadImmediately:YES threadIdentifier:nil];
|
||||
} else {
|
||||
[chat loadMessagesBeforeAndAfterGUID:beforeMessageGUID numberOfMessagesToLoadBeforeGUID:limit numberOfMessagesToLoadAfterGUID:0 loadImmediately:YES];
|
||||
}
|
||||
} else {
|
||||
[chat loadMessagesBeforeDate:beforeDate limit:limit loadImmediately:YES];
|
||||
}
|
||||
|
||||
[[chat chatItems] enumerateMessagesWithOptions:0 usingBlock:^(IMMessage *message, BOOL *stop) {
|
||||
if ([[message guid] isEqual:beforeMessageGUID]) {
|
||||
*stop = YES;
|
||||
return;
|
||||
}
|
||||
|
||||
NSDictionary *messageDict = [message mbim_dictionaryRepresentation];
|
||||
[messages addObject:messageDict];
|
||||
}];
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
18
kordophone/Bridge/Operations/Utilities/MBIMErrorResponse.h
Normal file
18
kordophone/Bridge/Operations/Utilities/MBIMErrorResponse.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// MBIMErrorResponse.h
|
||||
// kordophoned
|
||||
//
|
||||
// Created by James Magahern on 8/3/22.
|
||||
// Copyright © 2022 James Magahern. All rights reserved.
|
||||
//
|
||||
|
||||
#import "HTTPDataResponse.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MBIMErrorResponse : HTTPDataResponse
|
||||
- (instancetype)initWithErrorCode:(int)httpErrorCode;
|
||||
- (instancetype)initWithErrorCode:(int)httpErrorCode message:(NSString *)message;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
38
kordophone/Bridge/Operations/Utilities/MBIMErrorResponse.m
Normal file
38
kordophone/Bridge/Operations/Utilities/MBIMErrorResponse.m
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// MBIMErrorResponse.m
|
||||
// kordophoned
|
||||
//
|
||||
// Created by James Magahern on 8/3/22.
|
||||
// Copyright © 2022 James Magahern. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MBIMErrorResponse.h"
|
||||
|
||||
@implementation MBIMErrorResponse {
|
||||
int _status;
|
||||
}
|
||||
|
||||
- (instancetype)initWithErrorCode:(int)httpErrorCode
|
||||
{
|
||||
if (self = [super initWithData:nil]) {
|
||||
_status = httpErrorCode;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithErrorCode:(int)httpErrorCode message:(NSString *)message
|
||||
{
|
||||
if (self = [super initWithData:[message dataUsingEncoding:NSUTF8StringEncoding]]) {
|
||||
_status = httpErrorCode;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSInteger)status
|
||||
{
|
||||
return _status;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -10,3 +10,13 @@
|
||||
|
||||
NSString* MBIMWebServerFormatRFC822(NSDate *date);
|
||||
NSString* MBIMWebServerFormatISO8601(NSDate *date);
|
||||
|
||||
@interface NSDate (MBIMWebServerFormat)
|
||||
- (NSString *)RFC822StringValue;
|
||||
- (NSString *)ISO8601StringValue;
|
||||
@end
|
||||
|
||||
@interface NSString (MBIMWebServerFormat)
|
||||
- (NSDate *)RFC822Date;
|
||||
- (NSDate *)ISO8601Date;
|
||||
@end
|
||||
|
||||
@@ -47,3 +47,31 @@ NSString* MBIMWebServerFormatISO8601(NSDate *date)
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
@implementation NSDate (MBIMWebServerFormat)
|
||||
|
||||
- (NSString *)RFC822StringValue
|
||||
{
|
||||
return MBIMWebServerFormatRFC822(self);
|
||||
}
|
||||
|
||||
- (NSString *)ISO8601StringValue
|
||||
{
|
||||
return MBIMWebServerFormatISO8601(self);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSString (MBIMWebServerFormat)
|
||||
|
||||
- (NSDate *)RFC822Date
|
||||
{
|
||||
return [_dateFormatterRFC822 dateFromString:self];
|
||||
}
|
||||
|
||||
- (NSDate *)ISO8601Date
|
||||
{
|
||||
return [_dateFormatterISO8601 dateFromString:self];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
16
kordophone/kordophoned-Entitlements.plist
Normal file
16
kordophone/kordophoned-Entitlements.plist
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.imagent</key>
|
||||
<true/>
|
||||
<key>com.apple.private.imagent</key>
|
||||
<true/>
|
||||
<key>com.apple.private.imcore.imagent</key>
|
||||
<true/>
|
||||
<key>com.apple.imagent.av</key>
|
||||
<true/>
|
||||
<key>com.apple.imagent.chat</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
Reference in New Issue
Block a user