MessageListViewController.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // MessageListViewController.m
  3. // 千模
  4. //
  5. // Created by MUMEI on 2018/6/28.
  6. // Copyright © 2018年 MUMEI. All rights reserved.
  7. //
  8. #import "MessageListViewController.h"
  9. #import "MessageViewController.h"
  10. #import "NTESVideoChatViewController.h"
  11. @interface MessageListViewController ()<NIMNetCallManagerDelegate>
  12. @end
  13. @implementation MessageListViewController
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. self.navigationItem.title = @"会话";
  17. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tcpConnectStateChange) name:@"reloadUnRead" object:nil];
  18. NIMUser *user = [[NIMSDK sharedSDK].userManager userInfo:[Helper sharedAccount].accid];
  19. NSLog(@"user = %@",user);
  20. // [[NIMKit sharedKit] setProvider:[NTESDataProvider new]];
  21. //
  22. //// [[NIMKit sharedKit] setProvider:[NTESDataProvider new]];
  23. //
  24. // NIMSession *session = [NIMSession session:@"hoong" type:NIMSessionTypeP2P];
  25. // NIMTipObject *object = [[NIMTipObject alloc] init];
  26. //
  27. // NIMMessage *message = [[NIMMessage alloc] init];
  28. // message.messageObject = object;
  29. // message.text = @"可以开始对话了";
  30. // NIMKitInfoFetchOption *option = [[NIMKitInfoFetchOption alloc] init];
  31. // option.session = session;
  32. // NIMKitInfo *info = [[NIMKit sharedKit] infoByUser:@"hoong" option:option];
  33. // // 错误反馈对象
  34. // NSError *error = nil;
  35. // // 发送消息
  36. // [[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:&error];
  37. [[NIMAVChatSDK sharedSDK].netCallManager addDelegate:self];
  38. // [[NIMSDK sharedSDK].userManager updateMyUserInfo:@{@(NIMUserInfoUpdateTagAvatar) : [NSString stringWithFormat:@"%@%@",imageURl,user.userInfo.avatarUrl]} completion:nil];
  39. // Do any additional setup after loading the view.
  40. }
  41. - (void)viewWillAppear:(BOOL)animated{
  42. [self changeLoginState:@"1"];
  43. NSInteger count = [[[NIMSDK sharedSDK] conversationManager] allUnreadCount];
  44. self.navigationController.tabBarItem.badgeValue = count ? [NSString stringWithFormat:@"%ld",count] : nil;
  45. }
  46. - (void)tcpConnectStateChange{
  47. NSInteger count = [[[NIMSDK sharedSDK] conversationManager] allUnreadCount];
  48. self.navigationController.tabBarItem.badgeValue = count ? [NSString stringWithFormat:@"%ld",count] : nil;
  49. }
  50. - (void)onLogin:(NIMLoginStep)step{
  51. if (step == NIMLoginStepSyncOK) {
  52. [self.tableView reloadData];
  53. }
  54. }
  55. - (void)changeLoginState:(NSString *)state{
  56. NSString *str = [NSString stringWithFormat:@"%@modelInfo?action=doPutOnline&modelpk=%@&online=%@",imageURl,[ModelUser user].modelpk,state];
  57. [[AHHttpManager sharedManager]POST:str parameters:nil success:^(id responseObject) {
  58. NSLog(@"%@",responseObject);
  59. if ([[responseObject objectForKey:@"msg"]isEqualToString:@"success"]) {
  60. }else{
  61. }
  62. } failure:^(NSError *error) {
  63. NSLog(@"error = %@",error);
  64. }];
  65. }
  66. - (NSInteger)findInsertPlace:(NIMRecentSession *)recentSession{
  67. __block NSUInteger matchIdx = 0;
  68. __block BOOL find = NO;
  69. [self.recentSessions enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  70. NIMRecentSession *item = obj;
  71. if (item.lastMessage.timestamp <= recentSession.lastMessage.timestamp && ![item.lastMessage.session.sessionId isEqualToString:@"system"]) {
  72. *stop = YES;
  73. find = YES;
  74. matchIdx = idx;
  75. }
  76. }];
  77. if (find) {
  78. return matchIdx;
  79. }else{
  80. return self.recentSessions.count;
  81. }
  82. }
  83. - (void)didReceiveMemoryWarning {
  84. [super didReceiveMemoryWarning];
  85. // Dispose of any resources that can be recreated.
  86. }
  87. - (void)onSelectedRecent:(NIMRecentSession *)recentSession atIndexPath:(NSIndexPath *)indexPath{
  88. MessageViewController *vc = [[MessageViewController alloc] initWithSession:recentSession.session];
  89. // vc.hidesBottomBarWhenPushed = YES;
  90. [self.navigationController pushViewController:vc animated:YES];
  91. }
  92. //- (void)onReceive:(UInt64)callID from:(NSString *)caller type:(NIMNetCallMediaType)type message:(NSString *)extendMessage{
  93. //
  94. // // NTESMainTabController *tabVC = [NTESMainTabController instance];
  95. // // [tabVC.view endEditing:YES];
  96. // // UINavigationController *nav = tabVC.selectedViewController;
  97. // //
  98. // // if ([self shouldResponseBusy]){
  99. // // [[NIMAVChatSDK sharedSDK].netCallManager control:callID type:NIMNetCallControlTypeBusyLine];
  100. // // }
  101. // // else {
  102. // //
  103. // // if ([self shouldFireNotification:caller]) {
  104. // // NSString *text = [self textByCaller:caller
  105. // // type:type];
  106. // // [_notifier start:text];
  107. // // }
  108. // UIViewController *vc;
  109. // switch (type) {
  110. // case NIMNetCallTypeVideo:{
  111. // vc = [[NTESVideoChatViewController alloc] initWithCaller:caller callId:callID];
  112. // NSLog(@"11111");
  113. //// [self response:NO];
  114. // }
  115. // break;
  116. // case NIMNetCallTypeAudio:{
  117. // // vc = [[NTESAudioChatViewController alloc] initWithCaller:caller callId:callID];
  118. // }
  119. // break;
  120. // default:
  121. // break;
  122. // }
  123. // if (!vc) {
  124. // return;
  125. // }
  126. //
  127. // // 由于音视频聊天里头有音频和视频聊天界面的切换,直接用present的话页面过渡会不太自然,这里还是用push,然后做出present的效果
  128. // // CATransition *transition = [CATransition animation];
  129. // // transition.duration = 0.25;
  130. // // transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
  131. // // transition.type = kCATransitionPush;
  132. // // transition.subtype = kCATransitionFromTop;
  133. // // [nav.view.layer addAnimation:transition forKey:nil];
  134. // // nav.navigationBarHidden = YES;
  135. // // if (nav.presentedViewController) {
  136. // // // fix bug MMC-1431
  137. // // [nav.presentedViewController dismissViewControllerAnimated:NO completion:nil];
  138. // // }
  139. // // [nav pushViewController:vc animated:NO];
  140. // // }
  141. //// [self presentViewController:vc
  142. //// animated:YES
  143. //// completion:nil];
  144. // vc.hidesBottomBarWhenPushed = YES;
  145. // [self.navigationController pushViewController:vc animated:NO];
  146. //}
  147. /*
  148. #pragma mark - Navigation
  149. // In a storyboard-based application, you will often want to do a little preparation before navigation
  150. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  151. // Get the new view controller using [segue destinationViewController].
  152. // Pass the selected object to the new view controller.
  153. }
  154. */
  155. @end