Browse Source

开打聊天界面时,双击聊天按钮滑动到列表中未读消息

Steven 2 years ago
parent
commit
9eb61d0450

+ 2 - 0
KulexiuForTeacher/KulexiuForTeacher/AppDelegate.h

@@ -31,5 +31,7 @@
 
 
 - (void)handleNotiferSource;
 - (void)handleNotiferSource;
 
 
+- (void)displayUnreadMessageCount;
+
 @end
 @end
 
 

+ 10 - 0
KulexiuForTeacher/KulexiuForTeacher/AppDelegate.m

@@ -178,6 +178,16 @@
     [self versionCheck];
     [self versionCheck];
 }
 }
 
 
+- (void)displayUnreadMessageCount {
+    int unreadMsgCount = [[RCIMClient sharedRCIMClient] getUnreadCount:@[ @(ConversationType_PRIVATE),@(ConversationType_APPSERVICE), @(ConversationType_GROUP),@(ConversationType_SYSTEM)
+    ]];
+    if (unreadMsgCount >= 1) {
+        [self.tabBarController noteNewsWithIndex:2 count:unreadMsgCount];
+    } else {
+        [self.tabBarController clearNewsWithIndex:2];
+    }
+}
+
 - (void)registerSDK {
 - (void)registerSDK {
     NSString *universalLinkUrl = [NSString stringWithFormat:@"%@%@",hostURL,@"/teacherApp/"];
     NSString *universalLinkUrl = [NSString stringWithFormat:@"%@%@",hostURL,@"/teacherApp/"];
     [WXApi registerApp:@"wx149a928c415c137a" universalLink:universalLinkUrl];
     [WXApi registerApp:@"wx149a928c415c137a" universalLink:universalLinkUrl];

+ 1 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSBaseWKWebViewController.m

@@ -541,6 +541,7 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
         NSString *targetId = [valueDic stringValueForKey:@"id"];
         NSString *targetId = [valueDic stringValueForKey:@"id"];
         if ([[valueDic stringValueForKey:@"type"] isEqualToString:@"single"]) { // 单聊
         if ([[valueDic stringValueForKey:@"type"] isEqualToString:@"single"]) { // 单聊
             
             
+            
             KSChatConversationViewController *ctrl = [[KSChatConversationViewController alloc] init];
             KSChatConversationViewController *ctrl = [[KSChatConversationViewController alloc] init];
             ctrl.targetId = targetId;
             ctrl.targetId = targetId;
             ctrl.conversationType = ConversationType_PRIVATE;
             ctrl.conversationType = ConversationType_PRIVATE;

+ 1 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSNetworkingManager.m

@@ -673,6 +673,7 @@
     [parm setValue:avatal forKey:@"avatar"];
     [parm setValue:avatal forKey:@"avatar"];
     [parm setValue:gender forKey:@"gender"];
     [parm setValue:gender forKey:@"gender"];
     [parm setValue:username forKey:@"username"];
     [parm setValue:username forKey:@"username"];
+    [parm setValue:@"TEACHER" forKey:@"clientType"];
     [self request:post andWithUrl:url and:parm success:success faliure:faliure];
     [self request:post andWithUrl:url and:parm success:success faliure:faliure];
 }
 }
 
 

+ 3 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSTabBarViewController.h

@@ -7,6 +7,9 @@
 
 
 #import <UIKit/UIKit.h>
 #import <UIKit/UIKit.h>
 
 
+#define CHATVIEW_REFRESH (@"chatViewRefresh")
+
+
 NS_ASSUME_NONNULL_BEGIN
 NS_ASSUME_NONNULL_BEGIN
 
 
 @interface KSTabBarViewController : UITabBarController
 @interface KSTabBarViewController : UITabBarController

+ 25 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSTabBarViewController.m

@@ -100,6 +100,10 @@
 
 
 #pragma mark ----- UITabBarControllerDelegate
 #pragma mark ----- UITabBarControllerDelegate
 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
+    BOOL isDoubleClick = [self checkIsDoubleClick:viewController];
+    if ([viewController isEqual:[tabBarController.viewControllers objectAtIndex:2]] && isDoubleClick) {
+        [[NSNotificationCenter defaultCenter] postNotificationName:CHATVIEW_REFRESH object:nil];
+    }
     [self setAnaimationWithTabBarController:tabBarController selectViewController:viewController];
     [self setAnaimationWithTabBarController:tabBarController selectViewController:viewController];
 }
 }
 - (void)setAnaimationWithTabBarController:(UITabBarController *)tabBarController selectViewController:(UIViewController *)viewController {
 - (void)setAnaimationWithTabBarController:(UITabBarController *)tabBarController selectViewController:(UIViewController *)viewController {
@@ -120,6 +124,27 @@
     __block UIView *currentTabBarSwappableImageView = tabBarSwappableImageViews[index];
     __block UIView *currentTabBarSwappableImageView = tabBarSwappableImageViews[index];
     [AnimationHelper lottieAnimation:currentTabBarSwappableImageView index:index];
     [AnimationHelper lottieAnimation:currentTabBarSwappableImageView index:index];
 }
 }
+
+- (BOOL)checkIsDoubleClick:(UIViewController *)viewController {
+
+    static UIViewController *lastViewController = nil;
+    static NSTimeInterval lastClickTime = 0;
+    if (lastViewController != viewController) {
+        
+        lastViewController = viewController;
+        lastClickTime = [NSDate timeIntervalSinceReferenceDate];
+        return NO;
+    }
+    NSTimeInterval clickTime = [NSDate timeIntervalSinceReferenceDate];
+    if (clickTime - lastClickTime > 0.5) {
+        
+        lastClickTime = clickTime;
+        return NO;
+    }
+    lastViewController = nil;
+    lastClickTime = 0;
+    return YES;
+}
 /*
 /*
 #pragma mark - Navigation
 #pragma mark - Navigation
 
 

+ 14 - 0
KulexiuForTeacher/KulexiuForTeacher/Module/Chat/Controller/ChatViewController.m

@@ -10,6 +10,7 @@
 #import "CreateFansGroupViewController.h"
 #import "CreateFansGroupViewController.h"
 #import "ChatAddressViewController.h"
 #import "ChatAddressViewController.h"
 #import "KSChatListViewController.h"
 #import "KSChatListViewController.h"
+#import "KSTabBarViewController.h"
 
 
 @interface ChatViewController ()<JXCategoryViewDelegate>
 @interface ChatViewController ()<JXCategoryViewDelegate>
 
 
@@ -19,6 +20,9 @@
 
 
 @property (nonatomic, assign) NSInteger currentIndex;
 @property (nonatomic, assign) NSInteger currentIndex;
 
 
+@property (nonatomic, strong) KSChatListViewController *chatListCtrl;
+
+
 @end
 @end
 
 
 @implementation ChatViewController
 @implementation ChatViewController
@@ -29,6 +33,14 @@
     self.ks_prefersNavigationBarHidden = YES;
     self.ks_prefersNavigationBarHidden = YES;
     self.titles = @[@"聊天", @"联系人"];
     self.titles = @[@"聊天", @"联系人"];
     [self configUI];
     [self configUI];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshChatList) name:CHATVIEW_REFRESH object:nil];
+
+}
+
+- (void)refreshChatList {
+    if (self.chatListCtrl) {
+        [self.chatListCtrl refreshChatListMessage];
+    }
 }
 }
 
 
 - (void)configUI {
 - (void)configUI {
@@ -102,6 +114,8 @@
 
 
     if (index == 0) {
     if (index == 0) {
         KSChatListViewController *listVC = [[KSChatListViewController alloc] init];
         KSChatListViewController *listVC = [[KSChatListViewController alloc] init];
+        listVC.view.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight - kNaviBarHeight - kTabBarHeight);
+        self.chatListCtrl = listVC;
         return listVC;
         return listVC;
     }
     }
     else {
     else {

+ 2 - 0
KulexiuForTeacher/KulexiuForTeacher/Module/Chat/Controller/KSChatListViewController.h

@@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic, strong) JXPagerView *pagerView;
 @property (nonatomic, strong) JXPagerView *pagerView;
 @property (nonatomic, strong, readonly) JXCategoryTitleView *categoryView;
 @property (nonatomic, strong, readonly) JXCategoryTitleView *categoryView;
 
 
+- (void)refreshChatListMessage;
+
 @end
 @end
 
 
 NS_ASSUME_NONNULL_END
 NS_ASSUME_NONNULL_END

+ 47 - 5
KulexiuForTeacher/KulexiuForTeacher/Module/Chat/Controller/KSChatListViewController.m

@@ -23,6 +23,52 @@
 
 
 @implementation KSChatListViewController
 @implementation KSChatListViewController
 
 
+- (void)refreshChatListMessage {
+    NSArray *visiableIndexArray = self.conversationListTableView.indexPathsForVisibleRows;
+    if (visiableIndexArray.count) {
+        NSIndexPath *firstIndexPath = [visiableIndexArray firstObject];
+
+        NSInteger firstIndex = firstIndexPath.row;
+        if ([self isAtTheBottomOfTableView]) {
+            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
+            [self.conversationListTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
+        }
+        else {
+            for (NSInteger index = firstIndex+1; index < self.conversationListDataSource.count; index++) {
+                RCConversationModel *model = self.conversationListDataSource[index];
+                if (model.unreadMessageCount > 0) {
+                    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
+                    [self.conversationListTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
+                    break;
+                }
+                
+                if (index == self.conversationListDataSource.count - 1) {
+                    
+                }
+            }
+        }
+    }
+}
+
+/**
+ *  判断消息是否在collectionView的底部
+ *
+ *  @return 是否在底部
+ */
+- (BOOL)isAtTheBottomOfTableView {
+    if (self.conversationListTableView.contentSize.height <= self.conversationListTableView.frame.size.height) {
+        return YES;
+    }
+    CGFloat height = self.conversationListTableView.frame.size.height;
+    CGFloat contentOffsetY = self.conversationListTableView.contentOffset.y;
+    CGFloat bottomOffset = self.conversationListTableView.contentSize.height - contentOffsetY;
+    if (bottomOffset <= height) {
+        return YES;
+    }else{
+        return NO;
+    }
+}
+
 - (instancetype)init {
 - (instancetype)init {
     self = [super init];
     self = [super init];
     if (self) {
     if (self) {
@@ -44,11 +90,7 @@
 
 
 - (void)viewWillAppear:(BOOL)animated {
 - (void)viewWillAppear:(BOOL)animated {
     [super viewWillAppear:animated];
     [super viewWillAppear:animated];
-    if (self.isSubList == NO) {
-        self.conversationListTableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTabBarHeight);
-    }
-    else {
-        self.conversationListTableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
+    if (self.isSubList) {
         [self allocLeftButton];
         [self allocLeftButton];
         self.conversationListTableView.tableHeaderView = [UIView new];
         self.conversationListTableView.tableHeaderView = [UIView new];
     }
     }

+ 6 - 0
KulexiuForTeacher/KulexiuForTeacher/Module/Login/Model/UserInfoManager.m

@@ -298,6 +298,12 @@
         currentUserInfo.extra = [extraDic mj_JSONString];
         currentUserInfo.extra = [extraDic mj_JSONString];
         [RCIM sharedRCIM].currentUserInfo = currentUserInfo;
         [RCIM sharedRCIM].currentUserInfo = currentUserInfo;
         
         
+        dispatch_async(dispatch_get_main_queue(), ^{
+            
+            AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+            [appDelegate displayUnreadMessageCount];
+        });
+        
     } error:^(RCConnectErrorCode errorCode) {
     } error:^(RCConnectErrorCode errorCode) {
         
         
         if (errorCode == RC_CONN_TOKEN_INCORRECT) {
         if (errorCode == RC_CONN_TOKEN_INCORRECT) {