feat: 添加点赞功能支持及 Swift API Helper 集成
主要变更: 1. 在 EPMomentAPISwiftHelper 中新增点赞/取消点赞功能,支持动态 ID 和用户 UID。 2. 更新 EPMomentCell 以使用新的 Swift API Helper 进行点赞操作,简化点赞逻辑。 3. 优化点赞状态和数量的更新逻辑,确保用户界面及时反映点赞结果。 此更新旨在提升用户互动体验,简化点赞操作流程。
This commit is contained in:
@@ -9,10 +9,10 @@
|
||||
#import "EPMomentCell.h"
|
||||
#import "MomentsInfoModel.h"
|
||||
#import "AccountInfoStorage.h"
|
||||
#import "Api+Moments.h"
|
||||
#import "NetImageView.h"
|
||||
#import "EPEmotionColorStorage.h"
|
||||
#import "SDPhotoBrowser.h"
|
||||
#import "YuMi-Swift.h" // Swift 互操作
|
||||
|
||||
@interface EPMomentCell () <SDPhotoBrowserDelegate>
|
||||
|
||||
@@ -51,6 +51,9 @@
|
||||
/// 当前数据模型
|
||||
@property (nonatomic, strong) MomentsInfoModel *currentModel;
|
||||
|
||||
/// API Helper (Swift 版本)
|
||||
@property (nonatomic, strong) EPMomentAPISwiftHelper *apiHelper;
|
||||
|
||||
@end
|
||||
|
||||
@implementation EPMomentCell
|
||||
@@ -307,31 +310,32 @@
|
||||
- (void)performLikeAction:(BOOL)isLike {
|
||||
NSLog(@"[EPMomentCell] %@ 动态: %@", isLike ? @"点赞" : @"取消点赞", self.currentModel.dynamicId);
|
||||
|
||||
NSString *uid = [[AccountInfoStorage instance] getUid];
|
||||
NSString *dynamicId = self.currentModel.dynamicId;
|
||||
NSString *status = isLike ? @"1" : @"0"; // 0=取消,1=点赞
|
||||
NSString *likedUid = self.currentModel.uid;
|
||||
NSString *worldId = [NSString stringWithFormat:@"%ld", self.currentModel.worldId];
|
||||
long worldId = self.currentModel.worldId;
|
||||
|
||||
[Api momentsLike:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
if (code == 200) {
|
||||
// 更新点赞状态
|
||||
self.currentModel.isLike = isLike;
|
||||
NSInteger likeCount = [self.currentModel.likeCount integerValue];
|
||||
likeCount += isLike ? 1 : -1;
|
||||
likeCount = MAX(0, likeCount); // 防止负数
|
||||
self.currentModel.likeCount = @(likeCount).stringValue;
|
||||
|
||||
// 更新 UI
|
||||
self.likeButton.selected = self.currentModel.isLike;
|
||||
[self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCount] forState:UIControlStateNormal];
|
||||
[self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCount] forState:UIControlStateSelected];
|
||||
|
||||
NSLog(@"[EPMomentCell] %@ 成功", isLike ? @"点赞" : @"取消点赞");
|
||||
} else {
|
||||
NSLog(@"[EPMomentCell] %@ 失败: %@", isLike ? @"点赞" : @"取消点赞", msg);
|
||||
}
|
||||
} dynamicId:dynamicId uid:uid status:status likedUid:likedUid worldId:worldId];
|
||||
// 使用 Swift API Helper
|
||||
[self.apiHelper likeMomentWithDynamicId:dynamicId
|
||||
isLike:isLike
|
||||
likedUid:likedUid
|
||||
worldId:worldId
|
||||
completion:^{
|
||||
// 更新点赞状态
|
||||
self.currentModel.isLike = isLike;
|
||||
NSInteger likeCount = [self.currentModel.likeCount integerValue];
|
||||
likeCount += isLike ? 1 : -1;
|
||||
likeCount = MAX(0, likeCount); // 防止负数
|
||||
self.currentModel.likeCount = @(likeCount).stringValue;
|
||||
|
||||
// 更新 UI
|
||||
self.likeButton.selected = self.currentModel.isLike;
|
||||
[self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCount] forState:UIControlStateNormal];
|
||||
[self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCount] forState:UIControlStateSelected];
|
||||
|
||||
NSLog(@"[EPMomentCell] %@ 成功", isLike ? @"点赞" : @"取消点赞");
|
||||
} failure:^(NSInteger code, NSString * _Nonnull msg) {
|
||||
NSLog(@"[EPMomentCell] %@ 失败 (code: %ld): %@", isLike ? @"点赞" : @"取消点赞", (long)code, msg);
|
||||
}];
|
||||
}
|
||||
|
||||
// 评论功能已隐藏
|
||||
@@ -481,4 +485,11 @@
|
||||
return _imageViews;
|
||||
}
|
||||
|
||||
- (EPMomentAPISwiftHelper *)apiHelper {
|
||||
if (!_apiHelper) {
|
||||
_apiHelper = [[EPMomentAPISwiftHelper alloc] init];
|
||||
}
|
||||
return _apiHelper;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user