feat: 添加点赞功能支持及 Swift API Helper 集成

主要变更:
1. 在 EPMomentAPISwiftHelper 中新增点赞/取消点赞功能,支持动态 ID 和用户 UID。
2. 更新 EPMomentCell 以使用新的 Swift API Helper 进行点赞操作,简化点赞逻辑。
3. 优化点赞状态和数量的更新逻辑,确保用户界面及时反映点赞结果。

此更新旨在提升用户互动体验,简化点赞操作流程。
This commit is contained in:
edwinQQQ
2025-10-14 19:06:44 +08:00
parent f60a0eef14
commit 3a12a18687
2 changed files with 67 additions and 23 deletions

View File

@@ -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