YOUPAIBBMessageVC.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. //
  2. // YOUPAIBBMessageVC.m
  3. // VQU
  4. //
  5. // Created by Elaine on 2021/10/22.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIBBMessageVC.h"
  9. #import "NTESBundleSetting.h"
  10. #import "NTESSessionUtil.h"
  11. #import "YOUPAILCGiftAttachment.h"
  12. #import "YOUPAILCMultiImageAttachment.h"
  13. #import "YOUPAILCOneImageAttachment.h"
  14. #import "YOUPAILCMessageTxtAttachment.h"
  15. #import "YOUPAILCCallAttachment.h"
  16. #import "UIViewController+TFPresent.h"
  17. #import "YOUPAIZYUpdateRemarkWindow.h"
  18. #import "YOUPAILCReportVC.h"
  19. #import "LZAlertWindow.h"
  20. @interface YOUPAIBBMessageVC ()<UIViewControllerPreviewingDelegate,UIGestureRecognizerDelegate>
  21. @property (nonatomic,strong) UILabel *youpaiptitleLabel;
  22. @property (nonatomic,assign) BOOL youpaipsupportsForceTouch;
  23. @property (nonatomic,strong) NSMutableDictionary *youpaippreviews;
  24. @property (nonatomic,strong) NSArray *youpaiptop_listArray;//置顶列表
  25. @end
  26. @implementation YOUPAIBBMessageVC
  27. - (UIStatusBarStyle)preferredStatusBarStyle{
  28. return UIStatusBarStyleLightContent;
  29. }
  30. - (void)viewWillAppear:(BOOL)animated{
  31. [super viewWillAppear:animated];
  32. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.left.mas_equalTo(0);
  34. make.right.mas_equalTo(0);
  35. make.top.mas_equalTo(0);
  36. make.bottom.mas_equalTo(0);
  37. }];
  38. // self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;////设置子视图的宽度、高度随着父视图变化
  39. //消息列表适配暗黑模式 v1.5.6
  40. [self.tableView setBackgroundColor:[UIColor whiteColor]];
  41. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(youpaiflongTapAction:)];
  42. longPress.minimumPressDuration = 0.5; //定义按的时间
  43. longPress.numberOfTouchesRequired = 1;
  44. [self.tableView addGestureRecognizer:longPress];
  45. [self youpaifrefreshList];
  46. }
  47. - (void)viewWillDisappear:(BOOL)animated{
  48. [super viewWillDisappear:animated];
  49. [self.navigationController.navigationBar setDefaultBar];
  50. }
  51. - (void)youpaifinitConfig{ //系统配置信息
  52. [LCHttpHelper requestWithURLString:AppConfig parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  53. NSDictionary* dict = (NSDictionary*)responseObject;
  54. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  55. if (code==0) {//成功
  56. self->_youpaiptop_listArray = [[[dict objectForKey:@"data"]objectForKey:@"config"] objectForKey:@"top_list"];
  57. for (NSString *sessionId in self->_youpaiptop_listArray) {
  58. NIMSession *session = [NIMSession session:sessionId type:NIMSessionTypeP2P];
  59. [NTESSessionUtil addRecentSessionMark:session type:NTESRecentSessionMarkTypeTop];
  60. }
  61. }
  62. } failure:^(NSError *error) {
  63. }];
  64. }
  65. - (void)viewDidLoad {
  66. [super viewDidLoad];
  67. [self.view setBackgroundColor:[UIColor whiteColor]];
  68. self.youpaipsupportsForceTouch = [self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable;
  69. [self youpaifinitConfig];
  70. }
  71. - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
  72. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  73. if (self) {
  74. _youpaippreviews = [[NSMutableDictionary alloc] init];
  75. self.autoRemoveRemoteSession = [[NTESBundleSetting sharedConfig] autoRemoveRemoteSession];
  76. }
  77. return self;
  78. }
  79. - (void)youpaifrefreshList{
  80. if (self.recentSessions.count == 0) {//有时候会拿不到数据
  81. // self.recentSessions = [[NIMSDK sharedSDK].conversationManager.allRecentSessions mutableCopy];//获取所有最近会话。
  82. }
  83. self.recentSessions = [self customSortRecents:self.recentSessions];
  84. //过虑系统通知和动态通知
  85. for (NSInteger i = 0; i< self.recentSessions.count; i++) {
  86. NIMRecentSession *recentSession = self.recentSessions[i];
  87. if ( [recentSession.session.sessionId isEqual:@"11"] || [recentSession.session.sessionId isEqual:@"2"]) {
  88. [self.recentSessions removeObject:recentSession];
  89. i --;
  90. }
  91. }
  92. [self.tableView reloadData];
  93. if (self.recentSessions.count != 0) {
  94. [self.tableView lz_hideEmptyView];
  95. }else{
  96. [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_call_video_data"] content:@"暂无消息记录"];
  97. }
  98. }
  99. //对最近会话重新排序
  100. - (NSMutableArray *)customSortRecents:(NSMutableArray *)recentSessions
  101. {
  102. NSMutableArray *array = [[NSMutableArray alloc] initWithArray:recentSessions];
  103. [array sortUsingComparator:^NSComparisonResult(NIMRecentSession *obj1, NIMRecentSession *obj2) {
  104. NSInteger score1 = [NTESSessionUtil recentSessionIsMark:obj1 type:NTESRecentSessionMarkTypeTop]? 10 : 0;
  105. NSInteger score2 = [NTESSessionUtil recentSessionIsMark:obj2 type:NTESRecentSessionMarkTypeTop]? 10 : 0;
  106. if (obj1.lastMessage.timestamp > obj2.lastMessage.timestamp)
  107. {
  108. score1 += 1;
  109. }
  110. else if (obj1.lastMessage.timestamp < obj2.lastMessage.timestamp)
  111. {
  112. score2 += 1;
  113. }
  114. if (score1 == score2)
  115. {
  116. return NSOrderedSame;
  117. }
  118. return score1 > score2? NSOrderedAscending : NSOrderedDescending;
  119. }];
  120. return array;
  121. }
  122. #pragma mark - UITableViewDelegate
  123. //- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  124. // return YES;
  125. //}
  126. //- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  127. //{
  128. // return UITableViewCellEditingStyleDelete;
  129. //}
  130. //- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  131. // NIMRecentSession *recentSession = self.recentSessions[indexPath.row];
  132. // if (editingStyle == UITableViewCellEditingStyleDelete) {
  133. //// id<NIMConversationManager> manager = [[NIMSDK sharedSDK] conversationManager]; //删除最近会话
  134. //// [manager deleteRecentSession:recentSession];
  135. // //删除最近会话并且删除消息
  136. // id<NIMConversationManager> manager = [[NIMSDK sharedSDK] conversationManager];
  137. // NIMDeleteMessagesOption* deleteOption = [[NIMDeleteMessagesOption alloc]init];
  138. // deleteOption.removeSession = YES;
  139. // deleteOption.removeTable = YES;
  140. // [manager deleteAllmessagesInSession:recentSession.session option:deleteOption];
  141. // }
  142. //}
  143. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  144. {
  145. if (self.youpaipsupportsForceTouch) {
  146. id<UIViewControllerPreviewing> preview = [self registerForPreviewingWithDelegate:self sourceView:cell];
  147. [self.youpaippreviews setObject:preview forKey:@(indexPath.row)];
  148. }
  149. }
  150. - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  151. {
  152. if (self.youpaipsupportsForceTouch) {
  153. id<UIViewControllerPreviewing> preview = [self.youpaippreviews objectForKey:@(indexPath.row)];
  154. [self unregisterForPreviewingWithContext:preview];
  155. [self.youpaippreviews removeObjectForKey:@(indexPath.row)];
  156. }
  157. }
  158. - (void)onSelectedRecent:(NIMRecentSession *)recentSession atIndexPath:(NSIndexPath *)indexPath{
  159. @weakify(self);
  160. [ZCHUDHelper show];
  161. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[recentSession.session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  162. @strongify(self);
  163. [ZCHUDHelper dismiss];
  164. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:recentSession.session];
  165. [self.navigationController pushViewController:vc animated:YES];
  166. }];
  167. }
  168. - (NSString *)messageContent:(NIMMessage*)lastMessage{
  169. if (lastMessage.messageType == NIMMessageTypeCustom)
  170. {
  171. NIMCustomObject *object = (NIMCustomObject*)lastMessage.messageObject;
  172. NSString *text = @"";
  173. if ([object.attachment isKindOfClass:[YOUPAILCMessageTxtAttachment class]])
  174. {
  175. YOUPAILCMessageTxtAttachment* attachment = (YOUPAILCMessageTxtAttachment*)object.attachment;
  176. text = attachment.title;
  177. }
  178. if ([object.attachment isKindOfClass:[YOUPAILCOneImageAttachment class]])
  179. {
  180. YOUPAILCOneImageAttachment* attachment = (YOUPAILCOneImageAttachment*)object.attachment;
  181. if (attachment.act_type==1) {
  182. text = attachment.act_string;
  183. }else{
  184. text = attachment.title;
  185. }
  186. }
  187. if ([object.attachment isKindOfClass:[YOUPAILCMultiImageAttachment class]])
  188. {
  189. YOUPAILCMultiImageAttachment* attachment = (YOUPAILCMultiImageAttachment*)object.attachment;
  190. if (attachment.imageArray.count != 0) {
  191. NSDictionary* topDict = attachment.imageArray[0];
  192. text = [topDict objectForKey:@"title"];
  193. }
  194. }
  195. if ([object.attachment isKindOfClass:[YOUPAILCGiftAttachment class]])
  196. {
  197. YOUPAILCGiftAttachment* attachment = (YOUPAILCGiftAttachment*)object.attachment;
  198. if ([[NSString stringWithFormat:@"%zd",attachment.from_uid] isEqualToString:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  199. text = @"[赠送礼物]";
  200. }else{
  201. text = @"[收到礼物]";
  202. }
  203. }
  204. if ([object.attachment isKindOfClass:[YOUPAILPFollowAttachment class]]){
  205. //modify by leo v1.0.7 上线通知
  206. YOUPAILPFollowAttachment* attachment = (YOUPAILPFollowAttachment *)object.attachment;
  207. if(attachment.type == 16)
  208. {
  209. text = @"新增粉丝";
  210. }
  211. //modify by leo v1.0.8 动态更新
  212. else if(attachment.type == 17)
  213. {
  214. NSString *nickeName = attachment.nickname;
  215. text = [NSString stringWithFormat:@"%@更新了动态",nickeName];
  216. }
  217. else
  218. {
  219. NSString *nickeName = attachment.nickname;
  220. text = [NSString stringWithFormat:@"%@上线啦!",nickeName];
  221. }
  222. }
  223. if ([object.attachment isKindOfClass:[YOUPAILCCallAttachment class]])
  224. {
  225. YOUPAILCCallAttachment* attachment = (YOUPAILCCallAttachment*)object.attachment;
  226. if (attachment.calltype==1) {
  227. text = @"[视频通话]";
  228. }
  229. NSString* txtStr = @"";
  230. if (attachment.status==3) {
  231. txtStr =@"[超时未接听]";
  232. }else if (attachment.status==4){
  233. txtStr = [NSString stringWithFormat:@"[通话时长:%@]",[ZCUtils getMinTimeStrFromSS:attachment.call_time]];
  234. }
  235. NSLog(@"代表是自己发的%@-----%ld", [LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id , (long)attachment.from_uid);
  236. if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id integerValue] == attachment.from_uid) {//代表是自己发的
  237. // NSLog(@"代表是自己发的%@-----%@", [LCSaveModel getUserModel].userinfo.user_id , attachment.from_uid);
  238. if (attachment.status==1) {
  239. txtStr = @"[已取消]";
  240. }else if (attachment.status==2){
  241. txtStr = @"[对方已拒绝]";
  242. }
  243. }else{
  244. if (attachment.status==1) {
  245. txtStr = @"[对方已取消]";
  246. }else if (attachment.status==2){
  247. txtStr = @"[已拒绝]";
  248. }
  249. }
  250. text = [NSString stringWithFormat:@"%@%@",text,txtStr];
  251. }
  252. return text;
  253. }else{
  254. return [super messageContent:lastMessage];
  255. }
  256. }
  257. -(void)youpaiflongTapAction:(UILongPressGestureRecognizer *)longPress {
  258. if (longPress.state == UIGestureRecognizerStateBegan) {
  259. AudioServicesPlaySystemSound(1519);
  260. NSLog(@"long pressTap state :begin");
  261. }else if (longPress.state == UIGestureRecognizerStateEnded){
  262. CGPoint p = [longPress locationInView:self.tableView] ;// get longpress pt
  263. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p] ; // get indexpath from table with point .
  264. NIMRecentSession *recentSession = self.recentSessions[indexPath.row];
  265. if ([_youpaiptop_listArray containsObject:recentSession.session.sessionId]) {//置顶列表
  266. return;
  267. }
  268. @weakify(self);
  269. ZCAlertAction* deleteAction = [ZCAlertAction actionWithTitle:@"删除" andblock:^{
  270. @strongify(self);
  271. [self messagePopupWindowAction:@"deleteChat" andSession:recentSession.session];
  272. }];
  273. ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:@[deleteAction]];
  274. alertSheet.alertWindow.hidden = NO;
  275. [alertSheet show];
  276. }
  277. }
  278. -(void)dealloc
  279. {
  280. NSLog(@"lcmessage dealloc");
  281. }
  282. #pragma mark VQ_ZYMessagePopupWindowDelegate
  283. -(void)messagePopupWindowAction:(NSString *)type andSession:(NIMSession *)session
  284. {
  285. if ([type isEqualToString:@"updateRemark"]) {//设置备注名
  286. YOUPAIZYUpdateRemarkWindow *VC= [[YOUPAIZYUpdateRemarkWindow alloc]init];
  287. VC.vWidth = KScreenWidth -68;
  288. VC.vHeight = ScaleHeight(187)+10;
  289. VC.youpaipsession = session;
  290. VC.isTouchDismiss = YES;
  291. [kAppDelegate.window.rootViewController TFPresentVC:VC completion:^{
  292. }];
  293. }
  294. if ([type isEqualToString:@"deleteChat"]) {//删除聊天
  295. WeakSelf;
  296. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
  297. }];
  298. cancelAction.cornerRadius = 5.0f;
  299. cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
  300. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"删除" handler:^(LZAlertAction *action) {
  301. [weakSelf deleteChatWithSession:session];
  302. }];
  303. confimAction.cornerRadius = 5.0f;
  304. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
  305. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"确定删除该聊天?" action:@[cancelAction,confimAction]];
  306. alert.contentTextAlignment = NSTextAlignmentCenter;
  307. [self TFPresentVC:alert completion:^{}];
  308. }
  309. if ([type isEqualToString:@"top"]) {//置顶该聊天
  310. }
  311. if ([type isEqualToString:@"blacklist"]) {//加入黑名单
  312. }
  313. if ([type isEqualToString:@"report"]) {//举报
  314. YOUPAILCReportVC* report = [[YOUPAILCReportVC alloc]init];
  315. report.youpaipreport_uid = session.sessionId;
  316. report.youpaiptype = 4;
  317. [self.navigationController pushViewController:report animated:YES];
  318. }
  319. }
  320. #pragma mark ZYDeleteChatWindowDelegate
  321. -(void)deleteChatWithSession:(NIMSession *)session
  322. {
  323. id<NIMConversationManager> manager = [[NIMSDK sharedSDK] conversationManager];
  324. NIMDeleteMessagesOption* deleteOption = [[NIMDeleteMessagesOption alloc]init];
  325. deleteOption.removeSession = YES;
  326. deleteOption.removeTable = YES;
  327. [manager deleteAllmessagesInSession:session option:deleteOption];
  328. }
  329. #pragma mark - JXCategoryListContainerView
  330. - (UIView *)listView{
  331. return self.view;
  332. }
  333. @end