Files
keyboard/keyBoard/Class/AiTalk/VC/KBAIMessageZanVC.m

122 lines
3.6 KiB
Mathematica
Raw Normal View History

2026-01-28 16:35:47 +08:00
//
// KBAIMessageZanVC.m
// keyBoard
//
// Created by Mac on 2026/1/28.
//
#import "KBAIMessageZanVC.h"
#import "AiVM.h"
#import "KBLikedCompanionModel.h"
#import "KBHUD.h"
@interface KBAIMessageZanVC ()
@property (nonatomic, strong) AiVM *viewModel;
@property (nonatomic, strong) NSMutableArray<KBLikedCompanionModel *> *likedList;
@end
@implementation KBAIMessageZanVC
#pragma mark - Lifecycle
- (void)viewDidLoad {
self.listType = 0; // Thumbs Up
[super viewDidLoad];
}
2026-01-28 18:11:46 +08:00
#pragma mark - UITableViewDelegate Override
// Thumbs Up tab
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return NO; //
}
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) {
return nil; //
}
2026-01-28 16:35:47 +08:00
#pragma mark - 2
- (void)loadData {
[KBHUD show];
__weak typeof(self) weakSelf = self;
[self.viewModel fetchLikedCompanionsWithCompletion:^(NSArray<KBLikedCompanionModel *> * _Nullable list, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
[KBHUD dismiss];
if (error) {
[KBHUD showError:error.localizedDescription];
return;
}
[weakSelf.likedList removeAllObjects];
if (list.count > 0) {
[weakSelf.likedList addObjectsFromArray:list];
}
[weakSelf.dataArray removeAllObjects];
//
for (KBLikedCompanionModel *model in weakSelf.likedList) {
NSMutableDictionary *item = [NSMutableDictionary dictionary];
item[@"avatar"] = model.avatarUrl ?: @"";
item[@"name"] = model.name ?: @"";
item[@"content"] = model.shortDesc ?: @"";
item[@"time"] = model.createdAt ?: @"";
item[@"isPinned"] = @NO;
item[@"companionId"] = @(model.companionId);
[weakSelf.dataArray addObject:item];
}
[weakSelf.tableView reloadData];
});
}];
}
#pragma mark -
- (void)deleteItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row >= self.likedList.count) {
return;
}
KBLikedCompanionModel *model = self.likedList[indexPath.row];
__weak typeof(self) weakSelf = self;
[self.viewModel likeCompanionWithCompanionId:model.companionId completion:^(KBCommentLikeResponse * _Nullable response, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
[KBHUD showError:error.localizedDescription];
return;
}
//
if (indexPath.row < weakSelf.likedList.count) {
[weakSelf.likedList removeObjectAtIndex:indexPath.row];
}
if (indexPath.row < weakSelf.dataArray.count) {
[weakSelf.dataArray removeObjectAtIndex:indexPath.row];
}
[weakSelf.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
});
}];
}
#pragma mark - Lazy Load
- (AiVM *)viewModel {
if (!_viewModel) {
_viewModel = [[AiVM alloc] init];
}
return _viewModel;
}
- (NSMutableArray<KBLikedCompanionModel *> *)likedList {
if (!_likedList) {
_likedList = [NSMutableArray array];
}
return _likedList;
}
@end