Initial commit
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// UMComCommentDataController.h
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 16/6/28.
|
||||
// Copyright © 2016年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class UMComComment, UMComFeed;
|
||||
|
||||
typedef void(^UMComCommentOperationCompletion)(UMComComment *comment, NSError *error);
|
||||
|
||||
@interface UMComCommentDataController : NSObject
|
||||
|
||||
@property (nonatomic, strong) UMComFeed *feed;
|
||||
|
||||
@property (nonatomic, strong) UMComComment *comment;
|
||||
|
||||
- (instancetype)initWithComment:(UMComComment *)comment;
|
||||
|
||||
- (void)deletedCommentCompletion:(UMComCommentOperationCompletion)completion;
|
||||
|
||||
- (void)likeCommentCompletion:(UMComCommentOperationCompletion)completion;
|
||||
|
||||
- (void)spamCommentCompletion:(UMComCommentOperationCompletion)completion;
|
||||
|
||||
|
||||
@end
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
//
|
||||
// UMComCommentDataController.m
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 16/6/28.
|
||||
// Copyright © 2016年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UMComCommentDataController.h"
|
||||
#import <UMComDataStorage/UMComComment.h>
|
||||
#import <UMComDataStorage/UMComFeed.h>
|
||||
#import <UMCommunitySDK/UMComDataRequestManager.h>
|
||||
#import <UMComNetwork/UMComHttpCode.h>
|
||||
#import "UMComDataOperationErrorHandler.h"
|
||||
|
||||
@implementation UMComCommentDataController
|
||||
|
||||
- (instancetype)initWithComment:(UMComComment *)comment
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.comment = comment;
|
||||
if (comment.feed) {
|
||||
self.feed = comment.feed;
|
||||
}else{
|
||||
self.feed = [[UMComFeed alloc] init];
|
||||
self.feed.feedID = comment.feed_id;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)deletedCommentCompletion:(UMComCommentOperationCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[UMComDataRequestManager defaultManager] commentDeleteWithCommentID:self.comment.commentID feedID:self.feed.feedID completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
if (!error) {
|
||||
if ([weakSelf.feed.comments_count intValue] > 0) {
|
||||
weakSelf.feed.comments_count = @([weakSelf.feed.comments_count intValue]-1);
|
||||
}
|
||||
if (completion) {
|
||||
completion(weakSelf.comment, nil);
|
||||
}
|
||||
}else{
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
[UMComDataOperationErrorHandler handleCommentErrorWithComment:strongSelf.comment error:error];
|
||||
if (completion) {
|
||||
completion(nil, error);
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)likeCommentCompletion:(UMComCommentOperationCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
BOOL isLike = ![self.comment.liked boolValue];
|
||||
[[UMComDataRequestManager defaultManager] commentLikeWithCommentID:self.comment.commentID isLike:isLike completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
NSInteger likeCount = [weakSelf.comment.likes_count integerValue];
|
||||
if (!error) {
|
||||
if (isLike) {
|
||||
weakSelf.comment.liked = @1;
|
||||
likeCount += 1;
|
||||
}else{
|
||||
weakSelf.comment.liked = @0;
|
||||
likeCount -= 1;
|
||||
}
|
||||
if (likeCount < 0) {
|
||||
likeCount = 0;
|
||||
}
|
||||
weakSelf.comment.likes_count = @(likeCount);
|
||||
if (completion) {
|
||||
completion(weakSelf.comment, nil);
|
||||
}
|
||||
}else{
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
[UMComDataOperationErrorHandler handleCommentErrorWithComment:strongSelf.comment error:error];
|
||||
if (completion) {
|
||||
completion(nil, error);
|
||||
}
|
||||
}
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)spamCommentCompletion:(UMComCommentOperationCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[UMComDataRequestManager defaultManager] commentSpamWithCommentID:self.comment.commentID completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
if (!error) {
|
||||
if (completion) {
|
||||
completion(weakSelf.comment, nil);
|
||||
}
|
||||
}else{
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
[UMComDataOperationErrorHandler handleCommentErrorWithComment:strongSelf.comment error:error];
|
||||
if (completion) {
|
||||
completion(nil, error);
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// UMComCommentListDataController.h
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 16/5/18.
|
||||
// Copyright © 2016年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UMComListDataController.h"
|
||||
#import "UMComResouceDefines.h"
|
||||
|
||||
@class UMComFeed;
|
||||
typedef void(^UMComCommentListOperationCompletion)(NSError *error);
|
||||
|
||||
@interface UMComCommentListDataController : UMComListDataController
|
||||
|
||||
- (void)deletedComment:(UMComComment *)comment completion:(UMComCommentListOperationCompletion)completion;
|
||||
|
||||
- (void)likeComment:(UMComComment *)comment completion:(UMComCommentListOperationCompletion)completion;
|
||||
|
||||
- (void)spamComment:(UMComComment *)comment completion:(UMComCommentListOperationCompletion)completion;
|
||||
|
||||
- (void)commentFeed:(UMComFeed *)feed
|
||||
content:(NSString *)content
|
||||
images:(NSArray *)images
|
||||
completion:(UMComDataRequestCompletion)completion;
|
||||
|
||||
|
||||
- (void)replyCommentFeed:(UMComFeed *)feed
|
||||
comment:(UMComComment *)comment
|
||||
content:(NSString *)content
|
||||
images:(NSArray *)images
|
||||
completion:(UMComDataRequestCompletion)completion;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface UMComFeedCommnetListDataController : UMComCommentListDataController
|
||||
|
||||
@property (nonatomic, assign)UMComCommentListSortType commentSortType;
|
||||
|
||||
@property (nonatomic, copy) NSString *comment_uid;
|
||||
|
||||
@property (nonatomic, copy) NSString *feedId;
|
||||
|
||||
/**
|
||||
获取Feed所有评论的初始化方法
|
||||
|
||||
@param count 单页请求评论数量
|
||||
@param feedId FeedId
|
||||
@param comment_uid 发出评论用户id(用于实现只看楼主)
|
||||
@param order: commentorderByTimeDesc时间倒序排列,commentorderByTimeAsc时间正序排列,不传默认为倒序
|
||||
|
||||
@returns 获取Feed所有评论请求对象
|
||||
*/
|
||||
- (instancetype)initWithCount:(NSInteger)count
|
||||
feedId:(NSString *)feedId
|
||||
commentUserId:(NSString *)comment_uid
|
||||
order:(UMComCommentListSortType)orderType;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface UMComUserReceivedCommentListDataController : UMComCommentListDataController
|
||||
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface UMComUserSentCommentListDataController : UMComCommentListDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
//
|
||||
// UMComCommentListDataController.m
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 16/5/18.
|
||||
// Copyright © 2016年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UMComCommentListDataController.h"
|
||||
#import "UMComCommentDataController.h"
|
||||
#import "UMComFeedDetailDataController.h"
|
||||
#import <UMComNetwork/UMComHttpCode.h>
|
||||
|
||||
@interface UMComCommentListDataController ()
|
||||
|
||||
@property (nonatomic, strong) UMComCommentDataController *commentDataController;
|
||||
|
||||
@property (nonatomic, strong) UMComFeedDetailDataController *feedDetailDataController;
|
||||
|
||||
- (void)handleCommentData:(NSDictionary *)data error:(NSError *)error completion:(UMComDataListRequestCompletion)completion;
|
||||
|
||||
@end
|
||||
|
||||
@implementation UMComCommentListDataController
|
||||
|
||||
|
||||
- (void)deletedComment:(UMComComment *)comment completion:(UMComCommentListOperationCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
self.commentDataController = [[UMComCommentDataController alloc] initWithComment:comment];
|
||||
[self.commentDataController deletedCommentCompletion:^(UMComComment *returnComment, NSError *error) {
|
||||
if (error) {
|
||||
[weakSelf handleComment:comment error:error];
|
||||
}else{
|
||||
if ([weakSelf.dataArray containsObject:comment]) {
|
||||
[weakSelf.dataArray removeObject:comment];
|
||||
}
|
||||
}
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)likeComment:(UMComComment *)comment completion:(UMComCommentListOperationCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
self.commentDataController = [[UMComCommentDataController alloc] initWithComment:comment];
|
||||
[self.commentDataController likeCommentCompletion:^(UMComComment *comment, NSError *error) {
|
||||
[weakSelf handleComment:comment error:error];
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)spamComment:(UMComComment *)comment completion:(UMComCommentListOperationCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
self.commentDataController = [[UMComCommentDataController alloc] initWithComment:comment];
|
||||
[self.commentDataController spamCommentCompletion:^(UMComComment *comment, NSError *error) {
|
||||
[weakSelf handleComment:comment error:error];
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)handleComment:(UMComComment *)comment error:(NSError *)error
|
||||
{
|
||||
if (error.code == ERR_CODE_FEED_COMMENT_UNAVAILABLE) {
|
||||
if (![self.dataArray containsObject:comment]) {
|
||||
[self.dataArray removeObject:comment];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)commentFeed:(UMComFeed *)feed
|
||||
content:(NSString *)content
|
||||
images:(NSArray *)images
|
||||
completion:(UMComDataRequestCompletion)completion
|
||||
{
|
||||
self.feedDetailDataController = [[UMComFeedDetailDataController alloc] initWithFeed:feed viewExtra:nil];
|
||||
[self.feedDetailDataController commentFeedWithContent:content images:images completion:^(id responseObject, NSError *error) {
|
||||
if (completion) {
|
||||
completion(responseObject, error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
- (void)replyCommentFeed:(UMComFeed *)feed
|
||||
comment:(UMComComment *)comment
|
||||
content:(NSString *)content
|
||||
images:(NSArray *)images
|
||||
completion:(UMComDataRequestCompletion)completion
|
||||
{
|
||||
self.feedDetailDataController = [[UMComFeedDetailDataController alloc] initWithFeed:feed viewExtra:nil];
|
||||
[self.feedDetailDataController replyCommentFeedWithComment:comment content:content images:images completion:^(id responseObject, NSError *error) {
|
||||
if (completion) {
|
||||
completion(responseObject, error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
- (void)handleCommentData:(NSDictionary *)data error:(NSError *)error completion:(UMComDataListRequestCompletion)completion
|
||||
{
|
||||
[self handleNewData:data error:error completion:completion];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation UMComFeedCommnetListDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count
|
||||
feedId:(NSString *)feedId
|
||||
commentUserId:(NSString *)comment_uid
|
||||
order:(UMComCommentListSortType)orderType
|
||||
{
|
||||
self = [super initWithRequestType:UMComRequestType_FeedComment count:count];
|
||||
if (self) {
|
||||
self.feedId = feedId;
|
||||
self.comment_uid = comment_uid;
|
||||
self.commentSortType = orderType;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)refreshNewDataCompletion:(UMComDataListRequestCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[UMComDataRequestManager defaultManager] fetchCommentsWithFeedId:self.feedId commentUserId:self.comment_uid sortType:self.commentSortType count:self.count completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
[weakSelf handleCommentData:responseObject error:error completion:completion];
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
@implementation UMComUserReceivedCommentListDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count
|
||||
{
|
||||
self = [super initWithRequestType:UMComRequestType_UserReceiveComment count:count];
|
||||
if (self) {
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)refreshNewDataCompletion:(UMComDataListRequestCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[UMComDataRequestManager defaultManager] fetchCommentsUserReceivedWithCount:self.count completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
[weakSelf handleCommentData:responseObject error:error completion:completion];
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
@implementation UMComUserSentCommentListDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count
|
||||
{
|
||||
self = [super initWithRequestType:UMComRequestType_UserSendComment count:count];
|
||||
if (self) {
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)refreshNewDataCompletion:(UMComDataListRequestCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[UMComDataRequestManager defaultManager] fetchCommentsUserSentWithCount:self.count completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
[weakSelf handleCommentData:responseObject error:error completion:completion];
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user