Commit 9d9b6a85 cgx

优化我的动态模块删除、点赞、评论操作后数据同步到社区列表

1 个父辈 ab334129
......@@ -54,8 +54,10 @@ FOUNDATION_EXTERN NSString * const NeedUpdateStartAI;
FOUNDATION_EXTERN NSString * const UnlockAudioSuccess;
// 监听息屏播放页面点击播放、上一首、下一首通知
FOUNDATION_EXTERN NSString * const RemoteCommandCenterDidClick;
// 刷新社区动态列表
// 刷新社区动态列表通知
FOUNDATION_EXTERN NSString * const NeedUpdateComList;
// 重新下拉刷新社区动态列表标记
FOUNDATION_EXTERN NSString * const ReBeginRefresh;
// 用户基础信息
FOUNDATION_EXTERN NSString * const UserBasicInfo;
......
......@@ -35,6 +35,7 @@ NSString * const NeedUpdateStartAI = @"NeedUpdateStartAINoti";
NSString * const UnlockAudioSuccess = @"UnlockAudioSuccessNoti";
NSString * const RemoteCommandCenterDidClick = @"RemoteCommandCenterDidClickNoti";
NSString * const NeedUpdateComList = @"NeedUpdateComListNoti";
NSString * const ReBeginRefresh = @"ReBeginRefresh";
NSString * const UserBasicInfo = @"UserBasicInfo";
......
......@@ -5,7 +5,7 @@
// Created by peter on 2022/9/26.
//
#import <UIKit/UIKit.h>
#import "BaseViewController.h"
#import "ComDynModel.h"
@protocol DynamicDetailControllerDelegate <NSObject>
......@@ -15,13 +15,16 @@
NS_ASSUME_NONNULL_BEGIN
/// 动态详情页
@interface DynamicDetailController : UIViewController
/// 动态详情页(社区动态列表和我的动态列表点击进入)
@interface DynamicDetailController : BaseViewController
@property (nonatomic, weak) id<DynamicDetailControllerDelegate> delegate;
@property (nonatomic, strong) ComDynModel *comDynModel;
/// 是否从我的动态列表页面点击进来的
@property (nonatomic, assign) BOOL isFromMyDynamicList;
@end
NS_ASSUME_NONNULL_END
......@@ -48,14 +48,19 @@
[self.comDetailViewModel userCommentDynamicWithComDynModel:self.comDynModel content:content completion:^(ComDetailViewModel * _Nonnull requestModel) {
[DSProgressHUD dissmissProgressHUD];
if (requestModel.resCode == DSResCodeSuccess) {
// 更新评论数
// 更新详情页底部评论数
self.comDynModel.remarkCount += 1;
[self.detailView updateRemarkCount:self.comDynModel.remarkCount];
[self.detailView updateCommentSection:requestModel.groupDatas];
// 更新社区列表(评论数)
if (self.delegate && [self.delegate respondsToSelector:@selector(updateLikeOrRemark)]) {
[self.delegate updateLikeOrRemark];
}
[self.detailView updateCommentSection:requestModel.groupDatas];
if (self.isFromMyDynamicList) {
// 刷新社区动态列表匹配的动态评论数据(跨页面数据传递)
NSDictionary *userInfo = @{@"dynamicID" : @(self.comDynModel.dynamicID), @"remarkCount" : @(self.comDynModel.remarkCount)};
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateComList object:MyDynLikeOrRemark userInfo:userInfo];
}
} else {
[DSProgressHUD showToast:requestModel.errMessage];
}
......@@ -82,6 +87,11 @@
if (self.delegate && [self.delegate respondsToSelector:@selector(updateLikeOrRemark)]) {
[self.delegate updateLikeOrRemark];
}
if (self.isFromMyDynamicList) {
// 刷新社区动态列表匹配的动态点赞数据(跨页面数据传递)
NSDictionary *userInfo = @{@"dynamicID" : @(self.comDynModel.dynamicID), @"likeModel" : self.comDynModel};
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateComList object:MyDynLikeOrRemark userInfo:userInfo];
}
} else {
// 4、如果请求失败,延迟执行回退
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
......@@ -100,9 +110,4 @@
return _detailView;
}
#pragma mark - 品牌模式
- (NaviStyle)navigationBarStyle {
return NaviStyleDefault;
}
@end
......@@ -61,11 +61,21 @@
[messageBtn addSubview:self.redDot];
// 监听社区动态列表需要刷新数据通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needUpdateNoti) name:NeedUpdateComList object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needUpdateNoti:) name:NeedUpdateComList object:nil];
}
- (void)needUpdateNoti {
[self.communityView notiRefresh];
- (void)needUpdateNoti:(NSNotification *)noti {
DSLog(@"object:%@, userInfo:%@", noti.object, noti.userInfo);
if ([noti.object isEqual:MyDynDeleteOpt]) {
[self.comListViewModel deleteMyDynmic:[noti.userInfo[@"dynamicID"] intValue]];
[self.communityView updateListView];
} else if ([noti.object isEqual:MyDynLikeOrRemark]) {
[self.comListViewModel lookDynamicAndUpdateLikeOrRemarkWithUserInfo:noti.userInfo];
[self.communityView updateListView];
} else if ([noti.object isEqual:ReBeginRefresh]) {
[self.communityView notiRefresh];
}
}
- (void)messageAction {
......@@ -122,7 +132,7 @@
[self.communityView endRefreshing:loadMore];
}
}];
[DataStatisticsUtil event:AccessComList attributes:@{@"name":[LoginUtils getUserLoginData] ? @"登录状态" : @"未登录状态"}];
}
......
......@@ -15,6 +15,11 @@ typedef NS_ENUM(int, DynModelType) {
NS_ASSUME_NONNULL_BEGIN
/// 我的动态删除操作后刷新社区动态列表
FOUNDATION_EXTERN NSString * const MyDynDeleteOpt;
/// 我的动态列表和详情页点赞/评论操作刷新动态列表
FOUNDATION_EXTERN NSString * const MyDynLikeOrRemark;
/// 社区动态列表数据model
@interface ComDynModel : NSObject
/// 动态ID
......
......@@ -7,6 +7,9 @@
#import "ComDynModel.h"
NSString * const MyDynDeleteOpt = @"MyDynDeleteOpt";
NSString * const MyDynLikeOrRemark = @"MyDynLikeOrRemark";
// 用户动态内容显示最大行数
#define kMaxUserDynContentLine 5
......
......@@ -41,6 +41,14 @@ NS_ASSUME_NONNULL_BEGIN
/// @param comDynModel comDynModel
+ (void)updateLikeData:(ComDynModel *)comDynModel;
/// 我的动态列表删除我的动态操作
/// @param dynamicID 动态id
- (void)deleteMyDynmic:(int)dynamicID;
/// 我的动态列表点赞、我的动态详情点赞和评论操作需要更新社区动态列表匹配上的动态点赞和评论UI
/// @param userInfo 动态id+点赞数据/评论数据
- (void)lookDynamicAndUpdateLikeOrRemarkWithUserInfo:(NSDictionary *)userInfo;
/// 用户点赞、取消点赞接口
/// @param comDynModel comDynModel
/// @param completion completion
......
......@@ -99,6 +99,46 @@
comDynModel.isLike = !comDynModel.isLike;
}
- (void)deleteMyDynmic:(int)dynamicID {
NSMutableArray *tmpListArr = [NSMutableArray arrayWithArray:self.listArr];
[tmpListArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[ComDynModel class]]) {
ComDynModel *tmpObj = (ComDynModel *)obj;
if (tmpObj.dynamicID == dynamicID) {
[tmpListArr removeObject:obj];
*stop = YES;
}
}
}];
self.listArr = tmpListArr.copy;
}
- (void)lookDynamicAndUpdateLikeOrRemarkWithUserInfo:(NSDictionary *)userInfo {
if (!userInfo) { return; }
// 1、匹配动态
__block ComDynModel *tmpDynModel = nil;
[self.listArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[ComDynModel class]]) {
ComDynModel *tmpObj = (ComDynModel *)obj;
if (tmpObj.dynamicID == [userInfo[@"dynamicID"] intValue]) {
tmpDynModel = tmpObj;
*stop = YES;
}
}
}];
// 2、修改数据
if (tmpDynModel) {
BOOL isLike = [userInfo.allKeys containsObject:@"likeModel"];
if (isLike) {
ComDynModel *likeModel = userInfo[@"likeModel"];
tmpDynModel.isLike = likeModel.isLike;
tmpDynModel.likeCount = likeModel.likeCount;
} else {
tmpDynModel.remarkCount = [userInfo[@"remarkCount"] intValue];
}
}
}
+ (NSURLSessionDataTask *)userDynamicPraiseWithComDynModel:(ComDynModel *)comDynModel completion:(void (^)(ComListViewModel *requestModel))completion {
ComListViewModel * requestModel = [[ComListViewModel alloc] init];
NSString *api = @"user_dynamic_praise";
......
......@@ -73,6 +73,7 @@
DynamicDetailController *detailVC = [DynamicDetailController new];
detailVC.comDynModel = comDynModel;
detailVC.delegate = self;
detailVC.isFromMyDynamicList = YES;
[self.navigationController pushViewController:detailVC animated:YES];
}
......@@ -95,6 +96,10 @@
[cell updateLikeUI];
[DSProgressHUD showToast:requestModel.errMessage];
});
} else {
// 刷新社区动态列表匹配的动态点赞数据(跨页面数据传递)
NSDictionary *userInfo = @{@"dynamicID" : @(comDynModel.dynamicID), @"likeModel" : comDynModel};
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateComList object:MyDynLikeOrRemark userInfo:userInfo];
}
}];
}
......@@ -113,7 +118,7 @@
[self updateDefalutView:DefaultTypeEmpty info:@""];
}
// 刷新社区动态列表
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateComList object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateComList object:MyDynDeleteOpt userInfo:@{@"dynamicID" : @(self.myDynVM.delete_id)}];
} else {
[DSProgressHUD showToast:requestModel.errMessage];
}
......
......@@ -141,7 +141,7 @@
// 刷新AI睡眠教练
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateAICoach object:nil];
// 刷新社区动态列表
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateComList object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateComList object:ReBeginRefresh];
}
+ (void)saveCookie {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!