diff options
author | Robert Widmann <devteam.codafi@gmail.com> | 2014-10-21 17:31:59 -0600 |
---|---|---|
committer | Robert Widmann <devteam.codafi@gmail.com> | 2014-10-21 17:31:59 -0600 |
commit | 96f2623c2f1cba2fb5f625dbeae8a38eb20203c1 (patch) | |
tree | a11c883f368161e9d6f5b4600e66158eed90a502 /src/objc/nntp | |
parent | db7ec6896ffa7e1072d814d02fee2c5abae22ff2 (diff) |
XOVER
Diffstat (limited to 'src/objc/nntp')
-rw-r--r-- | src/objc/nntp/MCONNTPFetchOverviewOperation.h | 32 | ||||
-rw-r--r-- | src/objc/nntp/MCONNTPFetchOverviewOperation.mm | 69 | ||||
-rw-r--r-- | src/objc/nntp/MCONNTPSession.h | 22 | ||||
-rw-r--r-- | src/objc/nntp/MCONNTPSession.mm | 12 |
4 files changed, 134 insertions, 1 deletions
diff --git a/src/objc/nntp/MCONNTPFetchOverviewOperation.h b/src/objc/nntp/MCONNTPFetchOverviewOperation.h new file mode 100644 index 00000000..d63668e8 --- /dev/null +++ b/src/objc/nntp/MCONNTPFetchOverviewOperation.h @@ -0,0 +1,32 @@ +// +// MCONNTPFetchOverviewOperation.h +// mailcore2 +// +// Created by Robert Widmann on 10/21/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#ifndef MAILCORE_MCONNTPFETCHOVERVIEWOPERATION_H + +#define MAILCORE_MCONNTPFETCHOVERVIEWOPERATION_H + +#import <Foundation/Foundation.h> +#import <MailCore/MCONNTPOperation.h> + +@interface MCONNTPFetchOverviewOperation : MCONNTPOperation + +/** + Starts the asynchronous fetch operation. + + @param completionBlock Called when the operation is finished. + + - On success `error` will be nil and `messages` will be an array of MCOMessageHeaders + + - On failure, `error` will be set with `MCOErrorDomain` as domain and an + error code available in MCOConstants.h, `messages` will be null + */ +- (void) start:(void (^)(NSError * error, NSArray * /* MCOMessageHeader */ messages))completionBlock; + +@end + +#endif diff --git a/src/objc/nntp/MCONNTPFetchOverviewOperation.mm b/src/objc/nntp/MCONNTPFetchOverviewOperation.mm new file mode 100644 index 00000000..60bf2161 --- /dev/null +++ b/src/objc/nntp/MCONNTPFetchOverviewOperation.mm @@ -0,0 +1,69 @@ +// +// MCONNTPFetchOverviewOperation.m +// mailcore2 +// +// Created by Robert Widmann on 10/21/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#import "MCONNTPFetchOverviewOperation.h" + +#include "MCAsyncNNTP.h" + +#import "MCOUtils.h" +#import "MCOOperation+Private.h" + +typedef void (^CompletionType)(NSError *error, NSArray * groups); + +@implementation MCONNTPFetchOverviewOperation { + CompletionType _completionBlock; +} + +#define nativeType mailcore::NNTPFetchOverviewOperation + ++ (void) load +{ + MCORegisterClass(self, &typeid(nativeType)); +} + ++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object +{ + nativeType * op = (nativeType *) object; + return [[[self alloc] initWithMCOperation:op] autorelease]; +} + +- (void) dealloc +{ + [_completionBlock release]; + [super dealloc]; +} + +- (void) start:(void (^)(NSError *error, NSArray * groups))completionBlock +{ + _completionBlock = [completionBlock copy]; + [self start]; +} + +- (void) cancel +{ + [_completionBlock release]; + _completionBlock = nil; + [super cancel]; +} + +- (void) operationCompleted +{ + if (_completionBlock == NULL) + return; + + nativeType *op = MCO_NATIVE_INSTANCE; + if (op->error() == mailcore::ErrorNone) { + _completionBlock(nil, MCO_TO_OBJC(op->articles())); + } else { + _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil); + } + [_completionBlock release]; + _completionBlock = nil; +} + +@end
\ No newline at end of file diff --git a/src/objc/nntp/MCONNTPSession.h b/src/objc/nntp/MCONNTPSession.h index 8b632647..c5fb04cc 100644 --- a/src/objc/nntp/MCONNTPSession.h +++ b/src/objc/nntp/MCONNTPSession.h @@ -20,7 +20,9 @@ @class MCONNTPFetchHeaderOperation; @class MCONNTPFetchArticleOperation; @class MCONNTPListNewsgroupsOperation; +@class MCONNTPFetchOverviewOperation; @class MCONNTPOperation; +@class MCOIndexSet; /** This class implements asynchronous access to the NNTP protocol.*/ @@ -85,6 +87,16 @@ - (MCONNTPFetchHeaderOperation *) fetchHeaderOperationWithIndex:(unsigned int)index inGroup:(NSString *)group; /** + Returns an operation that will fetch an overview (headers) for a set of messages. + + MCONNTPFetchHeaderOperation * op = [session fetchOverviewOperationWithIndexes:indexes inGroup:@"Group"]; + [op start:^(NSError * error, NSArray * headers) { + // headers are the parsed headers of each part of the overview. + }]; + */ +- (MCONNTPFetchOverviewOperation *)fetchOverviewOperationWithIndexes:(MCOIndexSet *)indexes inGroup:(NSString *)group; + +/** Returns an operation that will fetch the content of the given message. MCONNTPFetchArticleOperation * op = [session fetchArticleOperationWithIndex:idx inGroup:@"Group"]; @@ -95,6 +107,16 @@ - (MCONNTPFetchArticleOperation *) fetchArticleOperationWithIndex:(unsigned int)index inGroup:(NSString *)group; /** + Returns an operation that will fetch the content of a message with the given messageID. + + MCONNTPFetchArticleOperation * op = [session fetchArticleOperationWithMessageID:@"<26>" inGroup:@"Group"]; + [op start:^(NSError * error, NSData * messageData) { + // messageData is the RFC 822 formatted message data. + }]; + */ +- (MCONNTPFetchArticleOperation *) fetchArticleOperationWithMessageID:(NSString *)messageID inGroup:(NSString *)group; + +/** Returns an operation that will list all available newsgroups. MCONNTPListNewsgroupsOperation * op = [session listAllNewsgroupsOperation]; diff --git a/src/objc/nntp/MCONNTPSession.mm b/src/objc/nntp/MCONNTPSession.mm index ed5bd81d..094c5886 100644 --- a/src/objc/nntp/MCONNTPSession.mm +++ b/src/objc/nntp/MCONNTPSession.mm @@ -124,7 +124,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue, - (MCONNTPFetchArticlesOperation *) fetchAllArticlesOperation:(NSString *)group { - mailcore::MCNNTPFetchArticlesOperation * coreOp = MCO_NATIVE_INSTANCE->fetchAllArticlesOperation(MCO_FROM_OBJC(mailcore::String, group)); + mailcore::NNTPFetchArticlesOperation * coreOp = MCO_NATIVE_INSTANCE->fetchAllArticlesOperation(MCO_FROM_OBJC(mailcore::String, group)); return MCO_TO_OBJC_OP(coreOp); } @@ -140,6 +140,16 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue, return MCO_TO_OBJC_OP(coreOp); } +- (MCONNTPFetchArticleOperation *) fetchArticleOperationWithMessageID:(NSString *)messageID inGroup:(NSString *)group { + mailcore::NNTPFetchArticleOperation * coreOp = MCO_NATIVE_INSTANCE->fetchArticleByMessageIDOperation(MCO_FROM_OBJC(mailcore::String, group), MCO_FROM_OBJC(mailcore::String, messageID)); + return MCO_TO_OBJC_OP(coreOp); +} + +- (MCONNTPFetchOverviewOperation *)fetchOverviewOperationWithIndexes:(MCOIndexSet *)indexes inGroup:(NSString *)group { + mailcore::NNTPFetchOverviewOperation * coreOp = MCO_NATIVE_INSTANCE->fetchOverviewOperationWithIndexes(MCO_FROM_OBJC(mailcore::String, group), MCO_FROM_OBJC(mailcore::IndexSet, indexes)); + return MCO_TO_OBJC_OP(coreOp); +} + - (MCONNTPListNewsgroupsOperation *) listAllNewsgroupsOperation { mailcore::NNTPListNewsgroupsOperation * coreOp = MCO_NATIVE_INSTANCE->listAllNewsgroupsOperation(); return MCO_TO_OBJC_OP(coreOp); |