Commit 84d2d2b2 cgx

完成消息中心query_user_message_count和query_user_dynamic_notice接口

1 个父辈 42404eb7
正在显示 24 个修改的文件 包含 546 行增加70 行删除
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
@interface MessageController () <MessageNotiViewDelegate> @interface MessageController () <MessageNotiViewDelegate>
@property (nonatomic, strong) MessageNotiView *messageNotiView; @property (nonatomic, strong) MessageNotiView *messageNotiView;
@property (nonatomic, strong) MessageCenterViewModel *messageCenterVM;
@end @end
@implementation MessageController @implementation MessageController
- (void)loadView { - (void)loadView {
self.messageCenterVM = [MessageCenterViewModel new];
self.view = self.messageNotiView; self.view = self.messageNotiView;
} }
...@@ -25,6 +27,10 @@ ...@@ -25,6 +27,10 @@
[super viewDidLoad]; [super viewDidLoad];
self.navigationItem.title = @"消息中心"; self.navigationItem.title = @"消息中心";
[self.messageCenterVM muiltiRequestWithCompletion:^(BOOL isSuccess) {
if (isSuccess) { [self.messageNotiView reloadData]; }
}];
} }
#pragma mark - MessageNotiViewDelegate #pragma mark - MessageNotiViewDelegate
...@@ -46,7 +52,7 @@ ...@@ -46,7 +52,7 @@
#pragma mark - lazy #pragma mark - lazy
- (MessageNotiView *)messageNotiView { - (MessageNotiView *)messageNotiView {
if (!_messageNotiView) { if (!_messageNotiView) {
_messageNotiView = [[MessageNotiView alloc] initWithDelegate:self]; _messageNotiView = [[MessageNotiView alloc] initWithDelegate:self viewModel:self.messageCenterVM];
} }
return _messageNotiView; return _messageNotiView;
} }
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
[self.comDetailViewModel queryCommentRelpyListWithCommentID:self.commentID completion:^(ComDetailViewModel * _Nonnull requestModel) { [self.comDetailViewModel queryCommentRelpyListWithCommentID:self.commentID completion:^(ComDetailViewModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) { if (requestModel.resCode == DSResCodeSuccess) {
[self.replyDetailView updateReplyDetailView:requestModel.replyGroupDatas]; [self.replyDetailView updateReplyDetailView:requestModel.replyGroupDatas];
} else {
[DSProgressHUD showToast:requestModel.errMessage];
} }
}]; }];
} }
......
//
// MessageComReplyModel.h
// DreamSleep
//
// Created by peter on 2022/10/17.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/// 消息中心评论和回复数据model
@interface MessageComReplyModel : NSObject
/// 动态或评论 id
@property (nonatomic, assign) NSInteger identifier;
/// 0:动态评论 1 评论回复
@property (nonatomic, assign) NSInteger type;
/// 发布评论或回复的用户 Id
@property (nonatomic, assign) NSInteger userID;
/// 被评论或被回复的用户 id
@property (nonatomic, assign) NSInteger preUserID;
/// 评论的内容或回复内容
@property (nonatomic, copy) NSString *content;
/// 动态内容或评论内容
@property (nonatomic, copy) NSString *preContent;
/// 阅读状态 0 未读 1 已读
@property (nonatomic, assign) NSInteger status;
/// 时间显示
@property (nonatomic, copy) NSString *publishTime;
/// 评论或者回复用户昵称
@property (nonatomic, copy) NSString *nickName;
/// 评论或者回复用户头像
@property (nonatomic, copy) NSString *userProfile;
+ (UIFont *)contentFont;
+ (UIFont *)preContentFont;
+ (CGFloat)contentLeftMargin;
+ (CGFloat)contentRightMargin;
- (CGFloat)contentHeight;
- (CGFloat)preContentHeight;
- (CGFloat)cellHeight;
@end
NS_ASSUME_NONNULL_END
//
// MessageComReplyModel.m
// DreamSleep
//
// Created by peter on 2022/10/17.
//
#import "MessageComReplyModel.h"
@implementation MessageComReplyModel
#pragma mark - YYModel
+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
return @{@"identifier" : @"id",
@"userID" : @"user_id",
@"preUserID" : @"pre_user_id",
@"preContent" : @"pre_content",
@"publishTime" : @"publish_time",
@"nickName" : @"nick_name",
@"userProfile" : @"user_profile"
};
}
#pragma mark - public
+ (UIFont *)contentFont {
return SysFont(14);
}
+ (UIFont *)preContentFont {
return SysFont(14);
}
+ (CGFloat)contentLeftMargin {
return 67;
}
+ (CGFloat)contentRightMargin {
return 50;
}
- (CGFloat)contentHeight {
CGFloat contentW = kScreenWidth - [MessageComReplyModel contentLeftMargin] - [MessageComReplyModel contentRightMargin];
return [UILabel getHeightByWidth:contentW text:self.content font:[MessageComReplyModel contentFont]];
}
- (CGFloat)preContentHeight {
return 20;
}
- (CGFloat)cellHeight {
CGFloat iconH = 40;
CGFloat contentH = [self contentHeight];
CGFloat space = 6;
CGFloat preContentHeight = [self preContentHeight];
CGFloat bottomH = 72;
return iconH +contentH + space + preContentHeight + bottomH;
}
@end
// //
// MessageNotiModel.h // MessageOfficialModel.h
// DreamSleep // DreamSleep
// //
// Created by peter on 2022/10/11. // Created by peter on 2022/10/11.
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/// 消息中心官方通知和收到点赞数据model /// 消息中心官方通知和收到点赞数据model
@interface MessageNotiModel : NSObject @interface MessageOfficialModel : NSObject
@property (nonatomic, copy) NSString *iconName; @property (nonatomic, copy) NSString *iconName;
@property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *detail; @property (nonatomic, copy) NSString *detail;
......
// //
// MessageNotiModel.m // MessageOfficialModel.m
// DreamSleep // DreamSleep
// //
// Created by peter on 2022/10/11. // Created by peter on 2022/10/11.
// //
#import "MessageNotiModel.h" #import "MessageOfficialModel.h"
@implementation MessageNotiModel @implementation MessageOfficialModel
@end @end
//
// CommentReplyCell.m
// DreamSleep
//
// Created by peter on 2022/10/10.
//
#import "CommentReplyCell.h"
@implementation CommentReplyCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = DSClearColor;
}
return self;
}
@end
// //
// CommentReplyCell.h // MessageComReplyCell.h
// DreamSleep // DreamSleep
// //
// Created by peter on 2022/10/10. // Created by peter on 2022/10/10.
// //
#import <UIKit/UIKit.h> #import "BaseTableViewCell.h"
#import "MessageComReplyModel.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/// 消息中心评论回复cell /// 回复按钮点击回调
@interface CommentReplyCell : UITableViewCell typedef void (^TapReplyBtnBlock)(void);
/// 消息中心评论回复cell
@interface MessageComReplyCell : BaseTableViewCell
@property (nonatomic, copy) TapReplyBtnBlock tapReplyBtnBlock;
@property (nonatomic, strong) MessageComReplyModel *comReplyModel;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
//
// MessageComReplyCell.m
// DreamSleep
//
// Created by peter on 2022/10/10.
//
#import "MessageComReplyCell.h"
@interface MessageComReplyCell ()
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *detailLab;
@property (nonatomic, strong) UILabel *mesCountLab;
@property (nonatomic, strong) UILabel *contentLab;
@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, strong) UILabel *preContentLab;
@property (nonatomic, strong) UIButton *replyBtn;
@end
@implementation MessageComReplyCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.backgroundColor = DSClearColor;
[self.contentView addSubview:self.icon];
[self.contentView addSubview:self.nameLab];
[self.contentView addSubview:self.timeLab];
[self.contentView addSubview:self.detailLab];
[self.contentView addSubview:self.mesCountLab];
[self.contentView addSubview:self.contentLab];
[self.contentView addSubview:self.lineView];
[self.contentView addSubview:self.preContentLab];
[self.contentView addSubview:self.replyBtn];
[self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(15);
make.top.equalTo(self.contentView);
make.size.mas_equalTo(CGSizeMake(40, 40));
}];
[self.detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.icon.mas_right).offset(12);
make.bottom.equalTo(self.icon);
make.right.equalTo(self.contentView).offset(-12);
}];
}
return self;
}
- (void)setComReplyModel:(MessageComReplyModel *)comReplyModel {
_comReplyModel = comReplyModel;
[self.icon yy_setImageWithURL:[NSURL URLWithString:comReplyModel.userProfile] placeholder:[UIImage defaultPlaceholderWithSize:CGSizeMake(40, 40)]];
self.nameLab.text = comReplyModel.nickName;
self.timeLab.text = comReplyModel.publishTime;
self.detailLab.text = comReplyModel.type == 0 ? @"评论了你的动态" : @"回复你的评论";
self.contentLab.text = comReplyModel.content;
self.preContentLab.text = comReplyModel.preContent;
[self.timeLab sizeToFit];
[self.timeLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView).offset(-15);
make.top.equalTo(self.contentView).offset(3);
}];
[self.nameLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.detailLab);
make.top.equalTo(self.icon);
make.right.equalTo(self.timeLab.mas_left).offset(-12);
}];
[self.contentLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.icon.mas_bottom).offset(3);
make.left.equalTo(self.contentView).offset([MessageComReplyModel contentLeftMargin]);
make.right.equalTo(self.contentView).offset(-[MessageComReplyModel contentRightMargin]);
make.height.equalTo(@([comReplyModel contentHeight]));
}];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentLab);
make.top.equalTo(self.contentLab.mas_bottom).offset(9);
make.size.mas_equalTo(CGSizeMake(2, 14));
}];
[self.preContentLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentLab.mas_bottom).offset(6);
make.left.equalTo(self.lineView.mas_right).offset(4);
make.right.equalTo(self.contentLab);
make.height.equalTo(@([comReplyModel preContentHeight]));
}];
[self.replyBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentLab);
make.size.mas_equalTo(CGSizeMake(116, 30));
make.bottom.equalTo(self.contentView).offset(-30);
}];
}
#pragma mark - private
- (void)replyAction {
if (self.tapReplyBtnBlock) { self.tapReplyBtnBlock(); }
}
#pragma mark - lazy
- (UIImageView *)icon {
if (!_icon) {
_icon = [UIImageView new];
_icon.dk_alphaPicker = DKAlphaPickerWithAlphas(1, .5, .5);
[_icon cornerRadius:20];
}
return _icon;
}
- (UILabel *)nameLab {
if (!_nameLab) {
_nameLab = [UILabel labWithFont:BoldFont(15)];
_nameLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
}
return _nameLab;
}
- (UILabel *)timeLab {
if (!_timeLab) {
_timeLab = [UILabel labWithFont:SysFont(12)];
_timeLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
_timeLab.textAlignment = NSTextAlignmentRight;
}
return _timeLab;
}
- (UILabel *)detailLab {
if (!_detailLab) {
_detailLab = [UILabel labWithFont:SysFont(12)];
_detailLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
}
return _detailLab;
}
- (UILabel *)contentLab {
if (!_contentLab) {
_contentLab = [UILabel labWithFont:[MessageComReplyModel contentFont]];
_contentLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
_contentLab.numberOfLines = 0;
}
return _contentLab;
}
- (UILabel *)preContentLab {
if (!_preContentLab) {
_preContentLab = [UILabel labWithFont:[MessageComReplyModel preContentFont]];
_preContentLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .4), DSWhite);
}
return _preContentLab;
}
- (UIView *)lineView {
if (!_lineView) {
_lineView = [UIView new];
_lineView.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHex(0xF0F0F0), ColorFromHex(0x1F263F), DSWhite);
[_lineView cornerRadius:3];
}
return _lineView;
}
- (UIButton *)replyBtn {
if (!_replyBtn) {
_replyBtn = [UIButton btnWithTitle:@"回复评论" font:SysFont(12)];
[_replyBtn cornerRadius:15];
[_replyBtn dk_setImage:DKImagePickerWithNames(@"ic_shequ_pinlun", @"dk_ic_shequ_pinlun", @"ic_shequ_pinlun") forState:UIControlStateNormal];
[_replyBtn dk_setTitleColorPicker:DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite) forState:UIControlStateNormal];
_replyBtn.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, AlertDarkColor, DSWhite);
[_replyBtn addTarget:self action:@selector(replyAction) forControlEvents:UIControlEventTouchUpInside];
_replyBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 8);
}
return _replyBtn;
}
@end
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "MessageCenterViewModel.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
...@@ -18,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -18,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, weak) id<MessageNotiViewDelegate> messageDelegate; @property (nonatomic, weak) id<MessageNotiViewDelegate> messageDelegate;
- (instancetype)initWithDelegate:(id<MessageNotiViewDelegate>)messageDelegate; - (instancetype)initWithDelegate:(id<MessageNotiViewDelegate>)messageDelegate viewModel:(MessageCenterViewModel *)vm;
@end @end
......
...@@ -6,32 +6,31 @@ ...@@ -6,32 +6,31 @@
// //
#import "MessageNotiView.h" #import "MessageNotiView.h"
#import "MessageNotiCell.h" #import "MessageOfficialNotiCell.h"
#import "CommentReplyCell.h" #import "MessageComReplyCell.h"
static int secHeaderHeight = 52; static int secHeaderHeight = 52;
static int secFooterHeight = 8; static int secFooterHeight = 8;
@interface MessageNotiView () <UITableViewDelegate, UITableViewDataSource> @interface MessageNotiView () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) NSArray *messageListArr; @property (nonatomic, strong) MessageCenterViewModel *messageCenterVM;
@end @end
@implementation MessageNotiView @implementation MessageNotiView
- (instancetype)initWithDelegate:(id<MessageNotiViewDelegate>)messageDelegate { - (instancetype)initWithDelegate:(id<MessageNotiViewDelegate>)messageDelegate viewModel:(MessageCenterViewModel *)vm {
if (self = [super initWithFrame:CGRectZero style:UITableViewStyleGrouped]) { if (self = [super initWithFrame:CGRectZero style:UITableViewStyleGrouped]) {
self.messageDelegate = messageDelegate; self.messageDelegate = messageDelegate;
self.messageCenterVM = vm;
self.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, DarkColor, DSWhite); self.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, DarkColor, DSWhite);
self.messageListArr = @[@"1", @"2"];
self.delegate = self; self.delegate = self;
self.dataSource = self; self.dataSource = self;
self.showsVerticalScrollIndicator = NO; self.showsVerticalScrollIndicator = NO;
self.separatorStyle = UITableViewCellSeparatorStyleNone; self.separatorStyle = UITableViewCellSeparatorStyleNone;
[self registerClass:[MessageNotiCell class] forCellReuseIdentifier:NSStringFromClass([MessageNotiCell class])]; [self registerClass:[MessageOfficialNotiCell class] forCellReuseIdentifier:NSStringFromClass([MessageOfficialNotiCell class])];
[self registerClass:[CommentReplyCell class] forCellReuseIdentifier:NSStringFromClass([CommentReplyCell class])]; [self registerClass:[MessageComReplyCell class] forCellReuseIdentifier:NSStringFromClass([MessageComReplyCell class])];
self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, CGFLOAT_MIN)]; UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, CGFLOAT_MIN)];
self.tableFooterView = footView; self.tableFooterView = footView;
...@@ -41,22 +40,21 @@ static int secFooterHeight = 8; ...@@ -41,22 +40,21 @@ static int secFooterHeight = 8;
#pragma mark - UITableViewDelegate, UITableViewDataSource #pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.messageListArr.count; return self.messageCenterVM.messageListArr.count;
} }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) { NSArray *sectionArr = self.messageCenterVM.messageListArr[section];
return 2; return sectionArr.count;
} else {
return 10;
}
} }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) { if (indexPath.section == 0) {
return 77; return 77;
} else { } else {
return 100; NSArray *userNotiList = self.messageCenterVM.messageListArr[indexPath.section];
MessageComReplyModel *model = userNotiList[indexPath.row];
return [model cellHeight];
} }
} }
...@@ -72,11 +70,12 @@ static int secFooterHeight = 8; ...@@ -72,11 +70,12 @@ static int secFooterHeight = 8;
header.height = 0; header.height = 0;
} else { } else {
header.height = secHeaderHeight; header.height = secHeaderHeight;
NSArray *userNotiList = self.messageCenterVM.messageListArr[section];
UILabel *totalReplyCountLab = [UILabel labWithFont:BoldFont(15)]; UILabel *totalReplyCountLab = [UILabel labWithFont:BoldFont(15)];
totalReplyCountLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE); totalReplyCountLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
totalReplyCountLab.origin = CGPointMake(15, 15); totalReplyCountLab.origin = CGPointMake(15, 15);
totalReplyCountLab.text = @"评论和回复"; totalReplyCountLab.text = userNotiList.count ? @"评论和回复" : @"暂无评论回复";
[totalReplyCountLab sizeToFit]; [totalReplyCountLab sizeToFit];
[header addSubview:totalReplyCountLab]; [header addSubview:totalReplyCountLab];
} }
...@@ -85,21 +84,29 @@ static int secFooterHeight = 8; ...@@ -85,21 +84,29 @@ static int secFooterHeight = 8;
} }
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return section == self.messageListArr.count - 1 ? CGFLOAT_MIN : secFooterHeight; return section == self.messageCenterVM.messageListArr.count - 1 ? CGFLOAT_MIN : secFooterHeight;
} }
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, section == self.messageListArr.count - 1 ? CGFLOAT_MIN : secFooterHeight)]; UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, section == self.messageCenterVM.messageListArr.count - 1 ? CGFLOAT_MIN : secFooterHeight)];
footer.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, AlertDarkColor, DSWhite); footer.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, AlertDarkColor, DSWhite);
return footer; return footer;
} }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) { if (indexPath.section == 0) {
MessageNotiCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MessageNotiCell class]) forIndexPath:indexPath]; MessageOfficialNotiCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MessageOfficialNotiCell class]) forIndexPath:indexPath];
NSArray *officialNotiList = self.messageCenterVM.messageListArr[indexPath.section];
cell.officialModel = officialNotiList[indexPath.row];
return cell; return cell;
} else { } else {
CommentReplyCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([CommentReplyCell class]) forIndexPath:indexPath]; MessageComReplyCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MessageComReplyCell class]) forIndexPath:indexPath];
NSArray *userNotiList = self.messageCenterVM.messageListArr[indexPath.section];
cell.comReplyModel = userNotiList[indexPath.row];
cell.tapReplyBtnBlock = ^{
#warning 回复功能逻辑未完成...
};
return cell; return cell;
} }
} }
......
// //
// MessageNotiCell.h // MessageOfficialNotiCell.h
// DreamSleep // DreamSleep
// //
// Created by peter on 2022/10/10. // Created by peter on 2022/10/10.
// //
#import <UIKit/UIKit.h> #import "BaseTableViewCell.h"
#import "MessageNotiModel.h" #import "MessageOfficialModel.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/// 消息中心顶部官方通知和点赞通知cell /// 消息中心顶部官方通知和点赞通知cell
@interface MessageNotiCell : UITableViewCell @interface MessageOfficialNotiCell : BaseTableViewCell
@property (nonatomic, strong) MessageNotiModel *messageNotiModel; @property (nonatomic, strong) MessageOfficialModel *officialModel;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
// //
// MessageNotiCell.m // MessageOfficialNotiCell.m
// DreamSleep // DreamSleep
// //
// Created by peter on 2022/10/10. // Created by peter on 2022/10/10.
// //
#import "MessageNotiCell.h" #import "MessageOfficialNotiCell.h"
@interface MessageNotiCell () @interface MessageOfficialNotiCell ()
@property (nonatomic, strong) UIImageView *icon; @property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *titleLab; @property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *detailLab; @property (nonatomic, strong) UILabel *detailLab;
@property (nonatomic, strong) UILabel *mesCountLab; @property (nonatomic, strong) UILabel *mesCountLab;
@end @end
@implementation MessageNotiCell @implementation MessageOfficialNotiCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = DSClearColor; self.backgroundColor = DSClearColor;
[self.contentView addSubview:self.icon]; [self.contentView addSubview:self.icon];
[self.contentView addSubview:self.titleLab]; [self.contentView addSubview:self.titleLab];
[self.contentView addSubview:self.detailLab]; [self.contentView addSubview:self.detailLab];
[self.contentView addSubview:self.mesCountLab]; [self.contentView addSubview:self.mesCountLab];
[self.icon mas_makeConstraints:^(MASConstraintMaker *make) { [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(15); make.left.equalTo(self.contentView).offset(15);
make.top.equalTo(self.contentView).offset(18); make.top.equalTo(self.contentView).offset(18);
...@@ -50,14 +49,14 @@ ...@@ -50,14 +49,14 @@
return self; return self;
} }
- (void)setMessageNotiModel:(MessageNotiModel *)messageNotiModel { - (void)setOfficialModel:(MessageOfficialModel *)officialModel {
_messageNotiModel = messageNotiModel; _officialModel = officialModel;
self.icon.image = [UIImage imageNamed:messageNotiModel.iconName]; [self.icon yy_setImageWithURL:[NSURL URLWithString:officialModel.iconName] placeholder:[UIImage defaultPlaceholderWithSize:CGSizeMake(40, 40)]];
self.titleLab.text = messageNotiModel.title; self.titleLab.text = officialModel.title;
self.detailLab.text = messageNotiModel.detail; self.detailLab.text = officialModel.detail;
self.mesCountLab.hidden = !messageNotiModel.messageCount; self.mesCountLab.hidden = !officialModel.messageCount;
self.mesCountLab.text = [NSString stringWithFormat:@"%d", messageNotiModel.messageCount]; self.mesCountLab.text = [NSString stringWithFormat:@"%d", officialModel.messageCount];
} }
#pragma mark - lazy #pragma mark - lazy
......
//
// MessageCenterViewModel.h
// DreamSleep
//
// Created by peter on 2022/10/17.
//
#import "DSNetworkTool.h"
NS_ASSUME_NONNULL_BEGIN
/// 消息中心viewModel
@interface MessageCenterViewModel : DSNetworkTool
/// 官方消息列表和评论回复列表数据
@property (nonatomic, strong) NSArray *messageListArr;
/// 官方通知和用户通知合并请求
/// @param completion completion
- (void)muiltiRequestWithCompletion:(void (^)(BOOL isSuccess))completion;
@end
NS_ASSUME_NONNULL_END
//
// MessageCenterViewModel.m
// DreamSleep
//
// Created by peter on 2022/10/17.
//
#import "MessageCenterViewModel.h"
#import "MessageOfficialModel.h"
#import "MessageComReplyModel.h"
@interface MessageCenterViewModel ()
/// 官方通知列表数据
@property (nonatomic, strong) NSArray<MessageOfficialModel *> *offNotiArr;
/// 用户动态通知列表数据
@property (nonatomic, strong) NSArray<MessageComReplyModel *> *userNotiArr;
@end
@implementation MessageCenterViewModel
#pragma mark - YYModel
+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
return @{@"userNotiArr" : @"result"
};
}
+ (NSDictionary *)modelContainerPropertyGenericClass {
return @{@"userNotiArr":[MessageComReplyModel class]};
}
#pragma mark - 初始化
- (instancetype)init {
if (self = [super init]) {
self.offNotiArr = @[];
self.userNotiArr = @[];
}
return self;
}
#pragma mark - public
- (void)muiltiRequestWithCompletion:(void (^)(BOOL isSuccess))completion {
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, queue, ^{
[self queryUserMessageCountWithCompletion:^(MessageCenterViewModel *requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
DSLog(@"获取社区动态消息中心官方和点赞统计未读通知数据成功...");
dispatch_semaphore_signal(semaphore);
} else {
completion(NO);
}
}];
});
dispatch_group_async(group, queue, ^{
[self queryUserDynamicNoticeWithCompletion:^(MessageCenterViewModel *requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
DSLog(@"社区动态消息中心接口数据成功...");
dispatch_semaphore_signal(semaphore);
} else {
completion(NO);
}
}];
});
dispatch_group_notify(group, queue, ^{
// 2个请求对应2次信号等待
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
// 在这里进行请求后的方法,回到主线程
dispatch_async(dispatch_get_main_queue(), ^{
self.messageListArr = @[self.offNotiArr, self.userNotiArr];
completion(YES);
});
});
}
#pragma mark - private
- (NSURLSessionDataTask *)queryUserMessageCountWithCompletion:(void (^)(MessageCenterViewModel *requestModel))completion {
MessageCenterViewModel *requestModel = [MessageCenterViewModel new];
NSString *api = @"query_user_message_count";
NSString *argStr = [NSString stringWithFormat:@"query{%@}", api];
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;
NSDictionary *resutDic = apiDic[@"result"];
NSArray *titleArr = @[@"官方通知", @"收到的赞"];
NSArray *detailArr = @[@"暂无消息", @"好高好高好高好高好高好"];
NSArray *messageCountArr = @[resutDic[@"message_count"], resutDic[@"praise_count"]];
NSMutableArray *tmpArr = [NSMutableArray array];
for (int i = 0; i < 2; i++) {
MessageOfficialModel *officialModel = [MessageOfficialModel new];
officialModel.iconName = @"";
officialModel.title = titleArr[i];
officialModel.detail = detailArr[i];
officialModel.messageCount = [messageCountArr[i] intValue];
[tmpArr addObject:officialModel];
}
self.offNotiArr = tmpArr.copy;
completion(requestModel);
} failure:^(id _Nonnull failureInfo) {
requestModel.resCode = [failureInfo[@"errorCode"] integerValue];
requestModel.errMessage = failureInfo[@"errMessage"];
completion(requestModel);
}];
}
- (NSURLSessionDataTask *)queryUserDynamicNoticeWithCompletion:(void (^)(MessageCenterViewModel *viewModel))completion {
MessageCenterViewModel *requestModel = [MessageCenterViewModel new];
NSString *api = @"query_user_dynamic_notice";
NSString *argStr = [NSString stringWithFormat:@"query{%@}", api];
return [MessageCenterViewModel httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:NO success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"社区动态消息中心接口apiDic:%@", apiDic);
MessageCenterViewModel *vm = [MessageCenterViewModel yy_modelWithDictionary:apiDic];
requestModel.resCode = DSResCodeSuccess;
self.userNotiArr = vm.userNotiArr.copy;
completion(requestModel);
} failure:^(id _Nonnull failureInfo) {
requestModel.resCode = [failureInfo[@"errorCode"] integerValue];
requestModel.errMessage = failureInfo[@"errMessage"];
completion(requestModel);
}];
}
@end
{
"images" : [
{
"filename" : "dk_ic_shequ_pinlun.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "dk_ic_shequ_pinlun@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "dk_ic_shequ_pinlun@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "ic_shequ_pinlun.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_shequ_pinlun@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_shequ_pinlun@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!