Commit 96bade53 cgx

完成通知已读功能(query_community_notify_flag、update_comment_reply_read_status)

1 个父辈 2b7e7d5b
......@@ -19,6 +19,7 @@
@property (nonatomic, strong) CommunityView *communityView;
@property (nonatomic, strong) ComListViewModel *comListViewModel;
@property (nonatomic, strong) NSURLSessionDataTask *likeDataTask;
@property (nonatomic, strong) UIView *redDot;
@end
@implementation CommunityController
......@@ -34,6 +35,12 @@
[self setupUI];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self getCommunityNotifyFlag];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NeedUpdateComList object:nil];
}
......@@ -51,6 +58,7 @@
[messageBtn addTarget:self action:@selector(messageAction) forControlEvents:UIControlEventTouchUpInside];
[messageBtn dk_setImage:DKImagePickerWithNames(@"ic_message_shequ", @"dk_ic_message_shequ", @"ic_message_shequ") forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:messageBtn];
[messageBtn addSubview:self.redDot];
// 监听社区动态列表需要刷新数据通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needUpdateNoti) name:NeedUpdateComList object:nil];
......@@ -68,6 +76,15 @@
[self.navigationController pushViewController:[MessageController new] animated:YES];
}
#pragma mark - 获取社区列表通知按钮状态
- (void)getCommunityNotifyFlag {
[ComListViewModel queryCommunityNotifyFlagWithCompletion:^(ComListViewModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
self.redDot.hidden = !requestModel.hasNoti;
}
}];
}
#pragma mark - CommunityViewDelegate
- (void)tapCommunityHeaderModule:(NSInteger)index {
if (![LoginUtils getUserLoginData]) {
......@@ -79,7 +96,12 @@
}
- (void)getDynamicListRequest:(BOOL)loadMore {
if (loadMore == NO) { self.offset = 1; }
// 下拉刷新
if (loadMore == NO) {
[self getCommunityNotifyFlag];
self.offset = 1;
}
[self.comListViewModel querySleepDynamicListWithLoadMore:loadMore offset:self.offset completion:^(ComListViewModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
......@@ -181,6 +203,16 @@
return _communityView;
}
- (UIView *)redDot {
if (!_redDot) {
_redDot = [[UIView alloc] initWithFrame:CGRectMake(17, 5, 5, 5)];
[_redDot cornerRadius:2.5];
_redDot.hidden = YES;
_redDot.backgroundColor = ColorFromHex(0xF04B77);
}
return _redDot;
}
#pragma mark - 导航栏日间、黑夜模式
- (NaviStyle)navigationBarStyle {
return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? NaviStyleLight : NaviStyleDark;
......
......@@ -21,6 +21,9 @@ NS_ASSUME_NONNULL_BEGIN
/// 自定义字段,用于标识是否是官方发布的动态
@property (nonatomic, assign) BOOL isOfficial;
/// 社区列表通知图标是否有新的通知标识
@property (nonatomic, assign) BOOL hasNoti;
/// 社区动态查询列表接口
/// @param loadMore 上下拉标识
/// @param offset offset
......@@ -42,6 +45,10 @@ NS_ASSUME_NONNULL_BEGIN
/// @param comDynModel comDynModel
/// @param completion completion
+ (NSURLSessionDataTask *)userDynamicPraiseWithComDynModel:(ComDynModel *)comDynModel completion:(void (^)(ComListViewModel *requestModel))completion;
/// 社区广场右上角通知标识的接口
/// @param completion completion
+ (NSURLSessionDataTask *)queryCommunityNotifyFlagWithCompletion:(void (^)(ComListViewModel *requestModel))completion;
@end
NS_ASSUME_NONNULL_END
......@@ -117,4 +117,20 @@
}];
}
+ (NSURLSessionDataTask *)queryCommunityNotifyFlagWithCompletion:(void (^)(ComListViewModel *requestModel))completion {
ComListViewModel * requestModel = [[ComListViewModel alloc] init];
NSString *api = @"query_community_notify_flag";
NSString *argStr = [NSString stringWithFormat:@"query{%@}", api];
return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:NO success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"社区广场右上角通知标识的接口apiDic:%@", apiDic);
requestModel.resCode = DSResCodeSuccess;
requestModel.hasNoti = [apiDic[@"result"] boolValue];
completion(requestModel);
} failure:^(id _Nonnull failureInfo) {
requestModel.resCode = [failureInfo[@"errorCode"] integerValue];
requestModel.errMessage = failureInfo[@"errMessage"];
completion(requestModel);
}];
}
@end
......@@ -36,6 +36,10 @@
#pragma mark - MessageNotiViewDelegate
- (void)didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
// 点击官方通知或者收到点赞里面标记已读
[self.messageCenterVM updateOfficialReadStatus:indexPath];
[self.messageNotiView refreshReadStatusView:indexPath];
if (indexPath.row == 0) {
OfficialNoticeController *officialVC = [OfficialNoticeController new];
[self.navigationController pushViewController:officialVC animated:YES];
......@@ -44,6 +48,19 @@
[self.navigationController pushViewController:praiseVC animated:YES];
}
} else {
// 1、先更新阅读状态
[self.messageCenterVM updateReadStatus:indexPath status:1];
[self.messageNotiView refreshReadStatusView:indexPath];
// 2、调用更新状态接口
int notiID = (int)[self.messageCenterVM getNotiIDWithIndexPath:indexPath];
[MessageCenterViewModel updateCommentReplyReadStatusWithID:notiID completion:^(MessageCenterViewModel * _Nonnull requestModel) {
if (requestModel.resCode != DSResCodeSuccess) {
// 3、阅读状态回滚
[self.messageCenterVM updateReadStatus:indexPath status:0];
[self.messageNotiView refreshReadStatusView:indexPath];
}
}];
ReplyListController *replyList = [ReplyListController new];
replyList.commentID = (int)[self.messageCenterVM getUserCommentIDWithIndexPath:indexPath];
[self.navigationController pushViewController:replyList animated:YES];
......
......@@ -11,6 +11,8 @@ NS_ASSUME_NONNULL_BEGIN
/// 消息中心评论和回复数据model
@interface MessageComReplyModel : NSObject
/// 评论回复id
@property (nonatomic, assign) NSInteger notiID;
/// 动态id
@property (nonatomic, assign) NSInteger talkID;
/// 评论id
......
......@@ -11,7 +11,8 @@
#pragma mark - YYModel
+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
return @{@"talkID" : @"talk_id",
return @{@"notiID" : @"id",
@"talkID" : @"talk_id",
@"commentID" : @"comment_id",
@"userID" : @"user_id",
@"preUserID" : @"pre_user_id",
......
......@@ -11,6 +11,7 @@
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UIView *readStatusView;
@property (nonatomic, strong) UILabel *detailLab;
@property (nonatomic, strong) UILabel *mesCountLab;
@property (nonatomic, strong) UILabel *contentLab;
......@@ -28,6 +29,7 @@
[self.contentView addSubview:self.icon];
[self.contentView addSubview:self.nameLab];
[self.contentView addSubview:self.timeLab];
[self.contentView addSubview:self.readStatusView];
[self.contentView addSubview:self.detailLab];
[self.contentView addSubview:self.mesCountLab];
[self.contentView addSubview:self.contentLab];
......@@ -59,11 +61,17 @@
self.contentLab.text = comReplyModel.content;
self.preContentLab.text = comReplyModel.preContent;
[self.timeLab sizeToFit];
self.readStatusView.hidden = comReplyModel.status;
[self.timeLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView).offset(-15);
make.top.equalTo(self.contentView).offset(3);
}];
[self.readStatusView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.timeLab);
make.top.equalTo(self.contentView).offset(40);
make.size.mas_equalTo(CGSizeMake(6, 6));
}];
[self.nameLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.detailLab);
make.top.equalTo(self.icon);
......@@ -116,6 +124,15 @@
return _nameLab;
}
- (UIView *)readStatusView {
if (!_readStatusView) {
_readStatusView = [UIView new];
_readStatusView.backgroundColor = ColorFromHex(0xF04B77);
[_readStatusView cornerRadius:3];
}
return _readStatusView;
}
- (UILabel *)timeLab {
if (!_timeLab) {
_timeLab = [UILabel labWithFont:SysFont(12)];
......
......@@ -28,6 +28,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)dismissKeyBoard;
/// 更新阅读状态
/// @param indexPath indexPath
- (void)refreshReadStatusView:(NSIndexPath *)indexPath;
@end
NS_ASSUME_NONNULL_END
......@@ -44,6 +44,10 @@ static int secFooterHeight = 8;
[self.textInputAlertView dismiss];
}
- (void)refreshReadStatusView:(NSIndexPath *)indexPath {
[self reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
}
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.messageCenterVM.messageListArr.count;
......
......@@ -28,6 +28,23 @@ NS_ASSUME_NONNULL_BEGIN
/// 获取消息中心评论回复用户评论id
/// @param indexPath indexPath
- (NSInteger)getUserCommentIDWithIndexPath:(NSIndexPath *)indexPath;
/// 获取消息中心评论回复通知id
/// @param indexPath indexPath
- (NSInteger)getNotiIDWithIndexPath:(NSIndexPath *)indexPath;
// 更新官方通知阅读状态(用户点击立马标记已读)
- (void)updateOfficialReadStatus:(NSIndexPath *)indexPath;
/// 更新评论回复cell阅读状态
/// @param indexPath indexPath
/// @param status status(阅读状态)
- (void)updateReadStatus:(NSIndexPath *)indexPath status:(int)status;
/// 消息中心-动态评论或回复 更新通知阅读状态
/// @param notiID 通知id
/// @param completion completion
+ (NSURLSessionDataTask *)updateCommentReplyReadStatusWithID:(NSInteger)notiID completion:(void (^)(MessageCenterViewModel *requestModel))completion;
@end
NS_ASSUME_NONNULL_END
......@@ -99,6 +99,43 @@
return model.commentID;
}
- (NSInteger)getNotiIDWithIndexPath:(NSIndexPath *)indexPath {
NSArray *userNotiList = self.messageListArr[indexPath.section];
MessageComReplyModel *model = userNotiList[indexPath.row];
return model.notiID;
}
- (void)updateOfficialReadStatus:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
NSArray *offNotiArr = self.messageListArr[0];
MessageOfficialModel *model = offNotiArr[indexPath.row];
model.messageCount = 0;
}
}
- (void)updateReadStatus:(NSIndexPath *)indexPath status:(int)status {
if (indexPath.section == 1) {
NSArray *userNotiList = self.messageListArr[1];
MessageComReplyModel *model = userNotiList[indexPath.row];
model.status = status;
}
}
+ (NSURLSessionDataTask *)updateCommentReplyReadStatusWithID:(NSInteger)notiID completion:(void (^)(MessageCenterViewModel *requestModel))completion {
MessageCenterViewModel * requestModel = [[MessageCenterViewModel alloc] init];
NSString *api = @"update_comment_reply_read_status";
NSString *argStr = [NSString stringWithFormat:@"mutation{%@(id:%ld)}", api, notiID];
return [MessageCenterViewModel httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:NO success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"消息中心-动态评论或回复 更新通知阅读状态接口apiDic:%@", apiDic);
requestModel.resCode = DSResCodeSuccess;
completion(requestModel);
} failure:^(id _Nonnull failureInfo) {
requestModel.resCode = [failureInfo[@"errorCode"] integerValue];
requestModel.errMessage = failureInfo[@"errMessage"];
completion(requestModel);
}];
}
#pragma mark - private
- (NSURLSessionDataTask *)queryUserMessageCountWithCompletion:(void (^)(MessageCenterViewModel *requestModel))completion {
MessageCenterViewModel *requestModel = [MessageCenterViewModel new];
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!