修复了消息未读书不会更新的问题

This commit is contained in:
fengshuo
2023-03-15 17:27:06 +08:00
parent 2055a0cc7a
commit aebeb945bc
2 changed files with 40 additions and 12 deletions

View File

@@ -397,9 +397,9 @@ NSString * const kMessageShowReadDotKey = @"kMessageShowReadDotKey";
return; return;
} }
if (value > 0) { if (value > 0) {
[self.tabBarItem setBadgeValue:[NSString stringWithFormat:@"%ld", value]]; [self.tabBarController.tabBar.items[3] setBadgeValue:[NSString stringWithFormat:@"%ld", value]];
} else { } else {
[self.tabBarItem setBadgeValue:nil]; [self.tabBarController.tabBar.items[3] setBadgeValue:@"0"];
} }
} }

View File

@@ -401,6 +401,12 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
[self.presenter logout]; [self.presenter logout];
} }
- (void)onLogin:(NIMLoginStep)step {
if (step == NIMLoginStepLoginOK) {
[self addMessageBadge];
}
}
- (void)onKickout:(NIMLoginKickoutResult *)result { - (void)onKickout:(NIMLoginKickoutResult *)result {
[XCHUDTool showErrorWithMessage:@"您已被踢下线,若非正常行为,请及时修改密码"]; [XCHUDTool showErrorWithMessage:@"您已被踢下线,若非正常行为,请及时修改密码"];
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController; UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
@@ -598,16 +604,16 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
#pragma mark - #pragma mark -
- (void)monentsUnReadCount { - (void)monentsUnReadCount {
[Api monentsUnReadCount:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { [Api monentsUnReadCount:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200) { // if (code == 200) {
MonentsUnReadModel * model = [MonentsUnReadModel modelWithDictionary:data.data]; // MonentsUnReadModel * model = [MonentsUnReadModel modelWithDictionary:data.data];
NSString *badge = model.total > 0 ? @(model.total).stringValue : nil; // NSString *badge = model.total > 0 ? @(model.total).stringValue : nil;
if (model.total > 99) { // if (model.total > 99) {
badge = @"99+"; // badge = @"99+";
} // }
NSUInteger index = 1; // NSUInteger index = 2;
UITabBarItem *item = self.tabBar.items.count > index ? self.tabBar.items[index] : nil; // UITabBarItem *item = self.tabBar.items.count > index ? self.tabBar.items[index] : nil;
[item setBadgeValue:badge]; // [item setBadgeValue:badge];
} // }
} uid:[AccountInfoStorage instance].getUid]; } uid:[AccountInfoStorage instance].getUid];
} }
@@ -699,6 +705,28 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
[TTPopup popupView:view style:TTPopupStyleAlert]; [TTPopup popupView:view style:TTPopupStyleAlert];
} }
- (void)addMessageBadge {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSArray * array = [NIMSDK sharedSDK].conversationManager.allRecentSessions;
__block int unreadCount = 0;
[array enumerateObjectsUsingBlock:^(NIMRecentSession * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (![[ClientConfig shareConfig].configInfo.officialMsgUids containsObject:obj.session.sessionId]) {
if (obj.session.sessionId.integerValue > 0) {
unreadCount += obj.unreadCount;
}
}
}];
if (self.parentMode) {
unreadCount = 0;
}
if (unreadCount > 0) {
[self.tabBar.items[3] setBadgeValue:[NSString stringWithFormat:@"%d", unreadCount]];
} else {
[self.tabBar.items[3] setBadgeValue:@"0"];
}
});
}
#pragma mark - #pragma mark -
// //
- (void)showNewUserRecharge { - (void)showNewUserRecharge {