This commit is contained in:
2025-12-04 16:59:59 +08:00
parent f593ef0b4a
commit 8f63741d8c
5 changed files with 94 additions and 6 deletions

View File

@@ -41,7 +41,6 @@ NS_ASSUME_NONNULL_BEGIN
/// 排名序号1、2、3... /// 排名序号1、2、3...
@property (nonatomic, assign) NSInteger rank; @property (nonatomic, assign) NSInteger rank;
/// 本地字段:是否已添加到键盘(仅客户端使用)
@property (nonatomic, assign) BOOL added; @property (nonatomic, assign) BOOL added;
@property (nonatomic, copy) NSString *emoji; @property (nonatomic, copy) NSString *emoji;

View File

@@ -16,6 +16,7 @@
#import "HomeRankDetailPopView.h" #import "HomeRankDetailPopView.h"
#import "LSTPopView.h" #import "LSTPopView.h"
#import <HWPanModal/HWPanModal.h> #import <HWPanModal/HWPanModal.h>
#import "KBMyVM.h" //
@interface HomeHotVC () <UITableViewDataSource, UITableViewDelegate> @interface HomeHotVC () <UITableViewDataSource, UITableViewDelegate>
@@ -53,9 +54,24 @@
// //
self.homeVM = [KBHomeVM new]; self.homeVM = [KBHomeVM new];
[self kb_reloadRankListWithShowHUD:YES];
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(kb_onUserCharacterDeleted:)
name:KBUserCharacterDeletedNotification
object:nil];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
///
- (void)kb_reloadRankListWithShowHUD:(BOOL)needShow {
KBWeakSelf KBWeakSelf
[self.homeVM fetchRankListWithParams:nil [self.homeVM fetchRankListWithParams:nil
needShow:YES needShow:needShow
completion:^(NSArray<KBCharacter *> * _Nullable list, NSError * _Nullable error) { completion:^(NSArray<KBCharacter *> * _Nullable list, NSError * _Nullable error) {
if (error) { if (error) {
// VM HUD // VM HUD
@@ -104,6 +120,26 @@
}]; }];
} }
/// id
- (void)kb_onUserCharacterDeleted:(NSNotification *)note {
NSNumber *cid = note.userInfo[@"characterId"];
if (!cid) { return; }
NSInteger targetId = cid.integerValue;
if (targetId <= 0) { return; }
BOOL contains = NO;
for (KBCharacter *c in self.allCharacters) {
if (c.characterId.integerValue == targetId) {
contains = YES;
break;
}
}
if (!contains) { return; }
// HUD
[self kb_reloadRankListWithShowHUD:NO];
}
#pragma mark - UITableViewDataSource #pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

View File

@@ -14,6 +14,7 @@
#import "HomeRankCardCell.h" #import "HomeRankCardCell.h"
#import "KBHomeVM.h" #import "KBHomeVM.h"
#import "KBCharacter.h" #import "KBCharacter.h"
#import "KBMyVM.h" //
@interface HomeRankContentVC () @interface HomeRankContentVC ()
@property (nonatomic, copy, nullable) NSString *tagId; // id @property (nonatomic, copy, nullable) NSString *tagId; // id
@@ -46,14 +47,29 @@
make.edges.equalTo(self.view); make.edges.equalTo(self.view);
}]; }];
//
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(kb_onUserCharacterDeleted:)
name:KBUserCharacterDeletedNotification
object:nil];
// tag // tag
[self loadCharactersForCurrentTag]; [self loadCharactersForCurrentTag];
} }
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)loadCharactersForCurrentTag { - (void)loadCharactersForCurrentTag {
[self kb_requestCharactersWithShowHUD:YES];
}
// tag
- (void)kb_requestCharactersWithShowHUD:(BOOL)needShow {
KBWeakSelf KBWeakSelf
[self.homeVM fetchRankListByTagId:self.tagId [self.homeVM fetchRankListByTagId:self.tagId
needShow:YES needShow:needShow
completion:^(NSArray<KBCharacter *> * _Nullable list, NSError * _Nullable error) { completion:^(NSArray<KBCharacter *> * _Nullable list, NSError * _Nullable error) {
if (error) { if (error) {
return; return;
@@ -63,6 +79,26 @@
}]; }];
} }
/// id
- (void)kb_onUserCharacterDeleted:(NSNotification *)note {
NSNumber *cid = note.userInfo[@"characterId"];
if (!cid) { return; }
NSInteger targetId = cid.integerValue;
if (targetId <= 0) { return; }
BOOL contains = NO;
for (KBCharacter *c in self.characters) {
if (c.characterId.integerValue == targetId) {
contains = YES;
break;
}
}
if (!contains) { return; }
// added UI
[self kb_requestCharactersWithShowHUD:NO];
}
- (UICollectionView *)collectionView{ - (UICollectionView *)collectionView{
if (!_collectionView) { if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];

View File

@@ -11,6 +11,11 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/// 用户人设发生变更(例如从“我的键盘”中删除)时的进程内通知。
/// userInfo:
/// @"characterId" : NSNumber(NSInteger) 被删除或变更的人设 id
extern NSString * const KBUserCharacterDeletedNotification;
typedef void(^KBMyUserDetailCompletion)(KBUser *_Nullable user, NSError *_Nullable error); typedef void(^KBMyUserDetailCompletion)(KBUser *_Nullable user, NSError *_Nullable error);
typedef void(^KBCharacterListCompletion)(NSArray<KBCharacter *> *characterArray, NSError *_Nullable error); typedef void(^KBCharacterListCompletion)(NSArray<KBCharacter *> *characterArray, NSError *_Nullable error);
typedef void(^KBUpLoadAvatarCompletion)(BOOL success, NSError * _Nullable error); typedef void(^KBUpLoadAvatarCompletion)(BOOL success, NSError * _Nullable error);

View File

@@ -11,6 +11,8 @@
#import "KBUser.h" #import "KBUser.h"
#import "KBAPI.h" #import "KBAPI.h"
NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNotification";
@implementation KBMyVM @implementation KBMyVM
- (void)fetchUserDetailWithCompletion:(KBMyUserDetailCompletion)completion { - (void)fetchUserDetailWithCompletion:(KBMyUserDetailCompletion)completion {
@@ -111,7 +113,6 @@
} }
NSDictionary *params = @{@"id": characterId}; NSDictionary *params = @{@"id": characterId};
[KBHUD show];
[[KBNetworkManager shared] GET:API_CHARACTER_DEL_USER_CHARACTER [[KBNetworkManager shared] GET:API_CHARACTER_DEL_USER_CHARACTER
parameters:params parameters:params
headers:nil headers:nil
@@ -119,9 +120,20 @@
completion:^(NSDictionary *jsonOrData, completion:^(NSDictionary *jsonOrData,
NSURLResponse * _Nullable response, NSURLResponse * _Nullable response,
NSError * _Nullable error) { NSError * _Nullable error) {
[KBHUD dismiss]; BOOL success = (error == nil);
if (success) {
// App HomeRankContentVC / HomeHotVC
NSDictionary *info = @{@"characterId": characterId ?: @0};
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:KBUserCharacterDeletedNotification
object:nil
userInfo:info];
});
}
if (completion) { if (completion) {
completion(error == nil, error); completion(success, error);
} }
}]; }];
} }