ChatMsgListVC.m 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  1. //
  2. // ChatMsgListVC.m
  3. // smartRhino
  4. //
  5. // Created by armin on 2019/11/2.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "ChatMsgListVC.h"
  9. #import "ChatMsgListCell.h"
  10. #import "GHRefreshCollectionView.h"
  11. #import "ChatMsgCollectionCell.h"
  12. #import "YCMenuView.h"
  13. #import "ChatMsgTopSearchVC.h"
  14. #import "WorkingGroupMainVC.h"
  15. #import "ShowNewGroupAlert.h"
  16. #import "ChatMsgNoticeVC.h"
  17. #import "MoreAppVC.h"
  18. #import "ChatNewGroupVC.h"
  19. #import "NoticeUnreadVC.h"
  20. #import "MailListVC.h"
  21. #import "EMChatViewController.h"
  22. #import "TDInterLeterHomeViewController.h"
  23. #import "EMRealtimeSearch.h"
  24. #import "EMConversationHelper.h"
  25. #import "MoreAppModel.h"
  26. #import "NavigationController.h"
  27. #import "TabBarController.h"
  28. #import "MyTDGroupViewController.h"
  29. #import "WaitWorkVC.h"
  30. #import "ChatMsgWorkModel.h"
  31. #import "MyTDTopicViewController.h"
  32. #import "TDInterLeterHomeViewController.h"
  33. #import "ChatListMoveVC.h"
  34. #import "NSDate+Extension.h"
  35. #import "SWQRCodeConfig.h"
  36. #import "SWQRCodeViewController.h"
  37. #import "MailListDetailVC.h"
  38. #import "ChatJoinGroupVC.h"
  39. #import "TDQrJoinVC.h"
  40. #import "MyTDGroupView.h"
  41. #import "ChatTestingVC.h"
  42. #import "ReplayMeVC.h"
  43. #import "TDGroupInfoListVC.h"
  44. static NSString *kConversation_IsRead = @"kHaveAtMessage";
  45. static int kConversation_AtYou = 1;
  46. static int kConversation_AtAll = 2;
  47. @interface ChatMsgListVC ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,EMChatManagerDelegate, EMGroupManagerDelegate, EMConversationsDelegate,SWQRCodeViewControllerDelegate>
  48. @property (weak,nonatomic) IBOutlet UIButton *operationBackButton;
  49. @property (weak,nonatomic) IBOutlet UIButton *operationAllSelectButton;
  50. @property (weak, nonatomic) IBOutlet UILabel *titleL;
  51. @property (weak, nonatomic) IBOutlet UIButton *menuBtn;
  52. @property (weak,nonatomic) IBOutlet UIButton *rightButton;
  53. @property (weak, nonatomic) IBOutlet UIView *HeadView;
  54. @property (strong,nonatomic) UITableView *tableView;
  55. //菜单列表数据源
  56. @property (strong,nonatomic) NSMutableArray *taskActionArray;
  57. @property (strong, nonatomic) MyTDGroupView *SearchView;
  58. @property (nonatomic, strong) GHRefreshCollectionView *collectionView;
  59. @property (strong,nonatomic) NSMutableArray *collectionDataSource;
  60. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *searchConstant;
  61. //界面操作状态参数
  62. @property (assign,nonatomic) OperationStateEnum operationStateEnum;
  63. @property (weak, nonatomic) IBOutlet UIView *NavBar;
  64. //界面操作视图
  65. @property (strong,nonatomic) UIButton *operationBottomDeleteBtn;
  66. @property (strong,nonatomic) UIButton *operationBottomMoveBtn;
  67. @property (strong,nonatomic) UIView *operationBottomBgView;
  68. @property (strong,nonatomic) NSMutableArray *dataArray;
  69. @property (strong,nonatomic) NSMutableArray *chatListIMArray;
  70. @property (strong,nonatomic) NSMutableArray *selectArray;
  71. @property (assign,nonatomic) BOOL isAllselect;
  72. @property (copy,nonatomic) NSString *ConfirmationDate;
  73. @property (copy,nonatomic) NSString *ReplyDate;
  74. @property (assign,nonatomic) NSInteger ReplyCount;
  75. @property (assign,nonatomic) NSInteger UReadVerifyCount;
  76. @end
  77. @implementation ChatMsgListVC
  78. +(ChatMsgListVC *)initChatMsgListVC{
  79. ChatMsgListVC *controller = [StoryboardManager.shared.chatMsg instantiateViewControllerWithIdentifier:@"ChatMsgListVC"];
  80. return controller;
  81. }
  82. - (void)viewWillAppear:(BOOL)animated{
  83. [super viewWillAppear:animated];
  84. [self headRefresh];
  85. }
  86. - (void)addTableRefresh
  87. {
  88. WS(weakSelf);
  89. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  90. [weakSelf headRefresh];
  91. }];
  92. }
  93. - (void)removeTableRefresh
  94. {
  95. [self.tableView.mj_header removeFromSuperview];
  96. }
  97. - (void)headRefresh{
  98. [self.chatListIMArray removeAllObjects];
  99. [self getUnreadCount];
  100. }
  101. - (void)getUnreadCount
  102. {
  103. [self initCollectionData];
  104. [self initChatMsgIMData];
  105. }
  106. - (UITableView *)tableView
  107. {
  108. if (!_tableView) {
  109. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  110. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  111. }
  112. return _tableView;
  113. }
  114. - (void)conversationListDidUpdate:(NSArray *)aConversationList
  115. {
  116. [self _loadAllConversationsFromDBWithIsShowHud:NO];
  117. }
  118. - (void)messagesDidReceive:(NSArray *)aMessages
  119. {
  120. [self performSelector:@selector(getUnreadCount) withObject:nil afterDelay:0.8];
  121. }
  122. - (void)_reSortedConversationModelsAndReloadView
  123. {
  124. NSArray *sorted = [self.dataArray sortedArrayUsingComparator:^(EMConversationModel *obj1, EMConversationModel *obj2) {
  125. EMMessage *message1 = [obj1.emModel latestMessage];
  126. EMMessage *message2 = [obj2.emModel latestMessage];
  127. if(message1.timestamp > message2.timestamp) {
  128. return(NSComparisonResult)NSOrderedAscending;
  129. } else {
  130. return(NSComparisonResult)NSOrderedDescending;
  131. }}];
  132. NSMutableArray *conversationModels = [NSMutableArray array];
  133. for (EMConversationModel *model in sorted) {
  134. if (!model.emModel.latestMessage) {
  135. [EMClient.sharedClient.chatManager deleteConversation:model.emModel.conversationId
  136. isDeleteMessages:NO
  137. completion:nil];
  138. continue;
  139. }
  140. [conversationModels addObject:model];
  141. }
  142. [self.dataArray removeAllObjects];
  143. [self.dataArray addObjectsFromArray:conversationModels];
  144. [self replaceChatData];
  145. }
  146. - (void)_loadAllConversationsFromDBWithIsShowHud:(BOOL)aIsShowHUD
  147. {
  148. __weak typeof(self) weakself = self;
  149. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  150. NSArray *conversations = [[EMClient sharedClient].chatManager getAllConversations];
  151. NSArray *sorted = [conversations sortedArrayUsingComparator:^(EMConversation *obj1, EMConversation *obj2) {
  152. EMMessage *message1 = [obj1 latestMessage];
  153. EMMessage *message2 = [obj2 latestMessage];
  154. if(message1.timestamp > message2.timestamp) {
  155. return(NSComparisonResult)NSOrderedAscending;
  156. } else {
  157. return(NSComparisonResult)NSOrderedDescending;
  158. }}];
  159. [weakself.dataArray removeAllObjects];
  160. NSArray *models = [EMConversationHelper modelsFromEMConversations:sorted];
  161. [weakself.dataArray addObjectsFromArray:models];
  162. [weakself replaceChatData];
  163. });
  164. }
  165. #pragma mark - EMConversationsDelegate
  166. - (void)didConversationUnreadCountToZero:(EMConversationModel *)aConversation
  167. {
  168. [self replaceChatData];
  169. }
  170. - (void)didResortConversationsLatestMessage
  171. {
  172. [self _reSortedConversationModelsAndReloadView];
  173. }
  174. - (void)viewDidLoad {
  175. [super viewDidLoad];
  176. self.fd_prefersNavigationBarHidden = YES;
  177. self.view.backgroundColor = RGB(240, 239, 244);
  178. [self initBottomBgView];
  179. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleGroupSubjectUpdated:) name:GROUP_SUBJECT_UPDATED object:nil];
  180. [self.HeadView addSubview:self.SearchView];
  181. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  182. make.top.mas_offset(6);
  183. make.left.right.mas_equalTo(self.HeadView);
  184. make.height.mas_offset(36);
  185. }];
  186. WS(weakSelf);
  187. [self.SearchView.button setAction:^{
  188. ChatMsgTopSearchVC *vc = [[ChatMsgTopSearchVC alloc] init];
  189. [weakSelf.navigationController pushViewController:vc animated:YES];
  190. }];
  191. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  192. [self.view addSubview:self.tableView];
  193. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  194. make.left.right.mas_equalTo(self.view);
  195. make.top.mas_equalTo(self.HeadView.mas_bottom);
  196. if (@available(iOS 11.0, *)) {
  197. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  198. } else {
  199. make.bottom.equalTo(self.view.mas_bottom);
  200. }
  201. }];
  202. self.tableView.delegate = self;
  203. self.tableView.dataSource = self;
  204. self.tableView.backgroundColor = [UIColor clearColor];
  205. [self.operationBackButton setAction:^{
  206. if(weakSelf.operationStateEnum == OperationStateEnum1){
  207. [weakSelf changeSelectStatus];
  208. [weakSelf changeToOperation:NO];
  209. }else if (weakSelf.operationStateEnum == OperationStateEnum2){
  210. [weakSelf userDidMove:NO isEdit:YES];
  211. }else{
  212. [super backAction:self.operationBackButton];
  213. }
  214. }];
  215. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushTDGroupController:) name:PUSHTDGROUPCOTROLLER object:nil];
  216. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushEMChatViewController:) name:PUSHEMCHATVIEWCOTROLLER object:nil];
  217. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushSubViewController:) name:DRAWERPUSHVC object:nil];
  218. [self changeToOperation:NO];
  219. [self resetRightBtnAction:YES];
  220. }
  221. -(void)resetRightBtnAction:(BOOL)isShowMenu{
  222. WS(weakSelf);
  223. if(isShowMenu){
  224. [self.rightButton setImage:[UIImage imageNamed:@"chatmsg_right_add_icon"] forState:UIControlStateNormal];
  225. [self.rightButton setAction:^{
  226. NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.taskActionArray];
  227. YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:106 relyonView:weakSelf.rightButton];
  228. view.menuColor = RGB(255, 255, 255);
  229. view.separatorColor = RGB(234, 234, 234);
  230. view.textColor = RGB(102, 102, 102);
  231. view.textFont = [UIFont systemFontOfSize:16.0];
  232. view.menuCellHeight = 43.5;
  233. view.maxDisplayCount = 10;
  234. view.offset = - 6;
  235. [view show];
  236. }];
  237. }else{
  238. // [self.rightButton setImage:[UIImage imageNamed:@"chatmsg_right_fileadd_icon"] forState:UIControlStateNormal];
  239. // [self.rightButton setAction:^{
  240. // [ShowtipTool showErrorWithStatus:@"未做"];
  241. // }];
  242. }
  243. }
  244. -(void)initCollectionData{
  245. [self.collectionDataSource removeAllObjects];
  246. id chatMenuDict = [[NSUserDefaults standardUserDefaults] objectForKey:CHATMENUBAR];
  247. NSMutableArray * commonArray = [NSMutableArray array];
  248. NSMutableArray * moreArray = [NSMutableArray array];
  249. NSMutableArray * array = [NSMutableArray array];
  250. if (![chatMenuDict isKindOfClass:[NSDictionary class]]) {
  251. for (int i= 0;i < 5; i++) {
  252. MoreAppInfoModel *model = [[MoreAppInfoModel alloc] init];
  253. switch (i) {
  254. case 0:{
  255. model.title = @"通知";
  256. model.imgName = @"chatmsg_tz_icon";
  257. model.notImgName = @"chatmsg_tz_hui_icon";
  258. model.type = ChatMenuNoticeType;
  259. model.readNum = 0;
  260. model.showEditFlag = NO;
  261. }break;
  262. case 1:{
  263. model.title = @"站内信";
  264. model.imgName = @"chatmsg_znx_icon";
  265. model.notImgName = @"chatmsg_tz_hui_icon";
  266. model.type = ChatMenuZhanXinType;
  267. model.readNum = 0;
  268. model.showEditFlag = YES;
  269. }break;
  270. case 2:{
  271. model.title = @"通讯录";
  272. model.imgName = @"chatmsg_txl_icon";
  273. model.notImgName = @"chatmsg_tz_hui_icon";
  274. model.type = ChatMenuTeleListType;
  275. model.readNum = 0;
  276. model.showEditFlag = YES;
  277. }break;
  278. case 3:{
  279. model.title = @"小组";
  280. model.imgName = @"chatmsg_xiaozu_icon";
  281. model.notImgName = @"chatmsg_tz_hui_icon";
  282. model.type = ChatMenuGroupType;
  283. model.readNum = 0;
  284. model.showEditFlag = YES;
  285. }break;
  286. case 4:{
  287. model.title = @"话题";
  288. model.imgName = @"chatmsg_ht_icon";
  289. model.notImgName = @"chatmsg_tz_hui_icon";
  290. model.type = ChatMenutopicType;
  291. model.readNum = 0;
  292. model.showEditFlag = YES;
  293. }break;
  294. default:
  295. break;
  296. }
  297. [array addObject:model];
  298. NSDictionary *json = [model modelToJSONObject];
  299. [commonArray addObject:json];
  300. }
  301. for (NSInteger j = 0; j < 1; j ++) {
  302. MoreAppInfoModel *model = [[MoreAppInfoModel alloc] init];
  303. model.title = @"待办事项";
  304. model.imgName = @"chatmsg_dbsx_icon";
  305. model.notImgName = @"chatmsg_tz_hui_icon";
  306. model.type = ChatMenuWaitType;
  307. model.readNum = 0;
  308. model.showEditFlag = YES;
  309. [moreArray addObject:[model modelToJSONObject]];
  310. }
  311. self.collectionDataSource = array;
  312. [[NSUserDefaults standardUserDefaults] setObject:@{@"common":[NSArray arrayWithArray:commonArray],@"more":[NSArray arrayWithArray:moreArray]} forKey:CHATMENUBAR];
  313. [[NSUserDefaults standardUserDefaults] synchronize];
  314. }else{
  315. NSArray * array = [chatMenuDict objectForKey:@"common"];
  316. for (NSDictionary * dict in array) {
  317. MoreAppInfoModel *model = [MoreAppInfoModel modelWithDictionary:dict];
  318. [self.collectionDataSource addObject:model];
  319. }
  320. }
  321. }
  322. -(void)initChatMsgIMData{
  323. [self.chatListIMArray removeAllObjects];
  324. ChatMsgListImModel * amodel = [[ChatMsgListImModel alloc] init];
  325. amodel.AttributeValue = 3;
  326. amodel.Name = @"通讯录";
  327. amodel.AvatarUrl = @"chat_phone_list";
  328. [self.chatListIMArray addObject:amodel];
  329. ChatMsgListImModel * bmodel = [[ChatMsgListImModel alloc] init];
  330. bmodel.AttributeValue = 4;
  331. bmodel.Name = @"验证信息";
  332. bmodel.AvatarUrl = @"chat_yan_message";
  333. [self.chatListIMArray addObject:bmodel];
  334. ChatMsgListImModel * cmodel = [[ChatMsgListImModel alloc] init];
  335. cmodel.AttributeValue = 5;
  336. cmodel.Name = @"回复我的";
  337. cmodel.AvatarUrl = @"chat_replay_me";
  338. [self.chatListIMArray addObject:cmodel];
  339. WS(weakSelf);
  340. SHOWLOADING
  341. NSString * url = [NSString stringWithFormat:@"%@0",Host(Often_Contact_List)];
  342. [[HttpManager sharedHttpManager] GETUrl:url parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  343. NSLog(@"%@",responseObject);
  344. REMOVESHOW
  345. [weakSelf.tableView.mj_header endRefreshing];
  346. if ([responseObject[@"OftenContactInfos"] isKindOfClass:[NSArray class]]) {
  347. for (NSDictionary * dict in responseObject[@"OftenContactInfos"]) {
  348. ChatMsgListImModel * model = [ChatMsgListImModel modelWithDictionary:dict];
  349. [weakSelf.chatListIMArray addObject:model];
  350. }
  351. }
  352. weakSelf.ConfirmationDate = responseObject[@"ConfirmationDate"];
  353. weakSelf.ReplyDate = responseObject[@"ReplyDate"];
  354. weakSelf.ReplyCount = [responseObject[@"ReplyCount"] integerValue];
  355. weakSelf.UReadVerifyCount = [responseObject[@"UReadVerifyCount"] integerValue];
  356. [weakSelf _loadAllConversationsFromDBWithIsShowHud:NO];
  357. } failure:^(NSError * _Nonnull error) {
  358. REMOVESHOW
  359. NSLog(@"%@",error);
  360. }];
  361. }
  362. - (NSString *)isNullWithString:(id)value
  363. {
  364. if ([value isKindOfClass:[NSNull class]]) {
  365. return @"";
  366. }else{
  367. if ([value isKindOfClass:[NSString class]]) {
  368. return value;
  369. }else{
  370. return [value stringValue];
  371. }
  372. }
  373. }
  374. //- (BOOL)hidesBottomBarWhenPushed{
  375. // return NO;
  376. //}
  377. //- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  378. //{
  379. // return YES;
  380. //}
  381. //#pragma mark - 左滑按钮 iOS8以上
  382. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
  383. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){// delete action
  384. WS(weakSelf);
  385. ChatMsgListImModel * model = weakSelf.chatListIMArray[indexPath.row];
  386. if(self.operationStateEnum == OperationStateEnum0){
  387. switch (model.AttributeValue) {
  388. case 2:
  389. {
  390. UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  391. completionHandler (YES);
  392. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  393. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  394. [weakSelf chatListDelete:@[model].copy];
  395. }];
  396. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  397. }];
  398. [alert addAction:sureAction];
  399. [alert addAction:cancelAction];
  400. [weakSelf presentViewController:alert animated:YES completion:^{
  401. }];
  402. }];
  403. action1.backgroundColor = RGB(255, 59, 47);
  404. UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"重命名" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  405. completionHandler (NO);
  406. [weakSelf workGroupReName:model];
  407. }];
  408. action2.backgroundColor = RGB(255, 149, 3);
  409. UIContextualAction *action3 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:model.IsTop ? @"取消置顶" : @"置顶" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  410. completionHandler (YES);
  411. [weakSelf chatListIsTop:model];
  412. }];
  413. action3.backgroundColor = RGB(197, 201, 204);
  414. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1, action2, action3]];
  415. actions.performsFirstActionWithFullSwipe = NO;
  416. return actions;
  417. }
  418. break;
  419. case 0:
  420. {
  421. UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  422. completionHandler (YES);
  423. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  424. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  425. [weakSelf chatListDelete:[NSMutableArray arrayWithArray:@[model]]];
  426. }];
  427. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  428. }];
  429. [alert addAction:sureAction];
  430. [alert addAction:cancelAction];
  431. [weakSelf presentViewController:alert animated:YES completion:^{
  432. }];
  433. }];
  434. action1.backgroundColor = RGB(255, 59, 47);
  435. UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"移动" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  436. completionHandler (YES);
  437. [weakSelf chatListMove:@[@(model.Id)]];
  438. }];
  439. action2.backgroundColor = RGB(61, 156, 248);
  440. UIContextualAction *action3 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:model.IsTop ? @"取消置顶" : @"置顶" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  441. completionHandler (YES);
  442. [weakSelf chatListIsTop:model];
  443. }];
  444. action3.backgroundColor = RGB(197, 201, 204);
  445. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1, action2, action3]];
  446. actions.performsFirstActionWithFullSwipe = NO;
  447. return actions;
  448. }
  449. break;
  450. }
  451. }
  452. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[]];
  453. actions.performsFirstActionWithFullSwipe = NO;
  454. return actions;
  455. }
  456. #else
  457. - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
  458. WS(weakSelf);
  459. ChatMsgListImModel * model = weakSelf.chatListIMArray[indexPath.row];
  460. if(self.operationStateEnum == OperationStateEnum0){
  461. switch (model.AttributeValue) {
  462. case 2:
  463. {
  464. UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  465. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  466. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  467. [weakSelf chatListDelete:@[model].copy];
  468. }];
  469. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  470. }];
  471. [alert addAction:sureAction];
  472. [alert addAction:cancelAction];
  473. [weakSelf presentViewController:alert animated:YES completion:^{
  474. }];
  475. }];
  476. action1.backgroundColor = RGB(255, 59, 47);
  477. UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"重命名" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  478. [weakSelf workGroupReName:model];
  479. }];
  480. action2.backgroundColor = RGB(255, 149, 3);
  481. UITableViewRowAction *action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:model.IsTop ? @"取消置顶" : @"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  482. [weakSelf chatListIsTop:model];
  483. }];
  484. action3.backgroundColor = RGB(197, 201, 204);
  485. return @[action1, action2, action3];
  486. }
  487. break;
  488. case 0:
  489. {
  490. UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  491. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  492. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  493. [weakSelf chatListDelete:[NSMutableArray arrayWithArray:@[model]]];
  494. }];
  495. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  496. }];
  497. [alert addAction:sureAction];
  498. [alert addAction:cancelAction];
  499. [weakSelf presentViewController:alert animated:YES completion:^{
  500. }];
  501. }];
  502. action1.backgroundColor = RGB(255, 59, 47);
  503. UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"移动" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  504. [weakSelf chatListMove:@[@(model.Id)]];
  505. }];
  506. action2.backgroundColor = RGB(61, 156, 248);
  507. UITableViewRowAction *action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:model.IsTop ? @"取消置顶" : @"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  508. [weakSelf chatListIsTop:model];
  509. }];
  510. action3.backgroundColor = RGB(197, 201, 204);
  511. return @[action1, action2, action3];
  512. }
  513. break;
  514. }
  515. }
  516. return @[];
  517. }
  518. #endif
  519. - (void)workGroupReName:(ChatMsgListImModel *)model
  520. {
  521. WS(weakSelf);
  522. [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"重命名" changeStr:model.FolderName confirm:^(NSString * _Nonnull groupName) {
  523. NSLog(@"%@",groupName);
  524. [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_ReName) parameters:@{@"FolderName":groupName,@"Id":@(model.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) {
  525. [weakSelf initChatMsgIMData];
  526. } failure:^(NSError * _Nonnull error) {
  527. NSLog(@"%@",error);
  528. SHOWERROR([ZYCTool handerResultData:error])
  529. }];
  530. } cancle:^{
  531. }] show];
  532. }
  533. - (void)getUserInfoInDocument:(NSString *)ImId{
  534. NSMutableArray * array = [[NSMutableArray alloc] initWithArray:USERDEFAULTSGET(@"ChatList")];
  535. for (NSMutableDictionary * dict in array) {
  536. if ([[dict objectForKey:@"ImId"] isEqualToString:ImId]) {
  537. [array removeObject:dict];
  538. }
  539. }
  540. USERDEFAULTSSET(array,@"ChatList");
  541. }
  542. - (void)chatListDelete:(NSMutableArray *)array
  543. {
  544. NSMutableArray * addArray = [NSMutableArray array];
  545. for (ChatMsgListImModel * model in array) {
  546. [addArray addObject:@(model.Id)];
  547. [self getUserInfoInDocument:[NSString stringWithFormat:@"%ld",(long)model.ImId]];
  548. }
  549. SHOWLOADING
  550. WS(weakSelf);
  551. NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
  552. [dic setValue:addArray forKey:@"MiddleIds"];
  553. [dic setValue:@(10) forKey:@"FolderType"];
  554. [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_DeleteRecord) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) {
  555. REMOVESHOW
  556. [weakSelf initChatMsgIMData];
  557. } failure:^(NSError * _Nonnull error) {
  558. REMOVESHOW
  559. NSLog(@"%@",error);
  560. SHOWERROR([ZYCTool handerResultData:error])
  561. }];
  562. }
  563. - (void)chatListMove:(NSArray *)array
  564. {
  565. ChatListMoveVC * vc = [ChatListMoveVC initChatListMoveVC];
  566. vc.Id = 0;
  567. vc.titleStr = @"移动到";
  568. vc.listArray = [NSMutableArray arrayWithArray:array];
  569. [self.navigationController pushViewController:vc animated:YES];
  570. }
  571. - (void)chatListIsTop:(ChatMsgListImModel *)model
  572. {
  573. WS(weakSelf);
  574. SHOWLOADING
  575. [[HttpManager sharedHttpManager] PUTUrl:[NSString stringWithFormat:@"%@%ld",Host(API_Find_Top),(long)model.Id] parameters:@{} responseStyle:DATA success:^(id _Nonnull responseObject) {
  576. REMOVESHOW
  577. [weakSelf reCreateTable];
  578. } failure:^(NSError * _Nonnull error) {
  579. REMOVESHOW
  580. SHOWERROR([ZYCTool handerResultData:error])
  581. }];
  582. }
  583. - (void)reCreateTable
  584. {
  585. [self.chatListIMArray removeAllObjects];
  586. ChatMsgListImModel * amodel = [[ChatMsgListImModel alloc] init];
  587. amodel.AttributeValue = 3;
  588. amodel.Name = @"通讯录";
  589. amodel.AvatarUrl = @"chat_phone_list";
  590. [self.chatListIMArray addObject:amodel];
  591. ChatMsgListImModel * bmodel = [[ChatMsgListImModel alloc] init];
  592. bmodel.AttributeValue = 4;
  593. bmodel.Name = @"验证信息";
  594. bmodel.AvatarUrl = @"chat_yan_message";
  595. [self.chatListIMArray addObject:bmodel];
  596. ChatMsgListImModel * cmodel = [[ChatMsgListImModel alloc] init];
  597. cmodel.AttributeValue = 5;
  598. cmodel.Name = @"回复我的";
  599. cmodel.AvatarUrl = @"chat_replay_me";
  600. [self.chatListIMArray addObject:cmodel];
  601. WS(weakSelf);
  602. NSString * url = [NSString stringWithFormat:@"%@0",Host(Often_Contact_List)];
  603. [[HttpManager sharedHttpManager] GETUrl:url parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  604. NSLog(@"%@",responseObject);
  605. [weakSelf.tableView.mj_header endRefreshing];
  606. if ([responseObject[@"OftenContactInfos"] isKindOfClass:[NSArray class]]) {
  607. for (NSDictionary * dict in responseObject[@"OftenContactInfos"]) {
  608. ChatMsgListImModel * model = [ChatMsgListImModel modelWithDictionary:dict];
  609. [weakSelf.chatListIMArray addObject:model];
  610. }
  611. }
  612. weakSelf.ConfirmationDate = responseObject[@"ConfirmationDate"];
  613. dispatch_async(dispatch_get_main_queue(), ^{
  614. [weakSelf.tableView removeFromSuperview];
  615. weakSelf.tableView = nil;
  616. [weakSelf.view addSubview:weakSelf.tableView];
  617. weakSelf.tableView.delegate = weakSelf;
  618. weakSelf.tableView.dataSource = weakSelf;
  619. weakSelf.tableView.backgroundColor = [UIColor clearColor];
  620. [weakSelf.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  621. make.left.right.mas_equalTo(weakSelf.view);
  622. make.top.mas_equalTo(weakSelf.HeadView.mas_bottom);
  623. if (@available(iOS 11.0, *)) {
  624. make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom);
  625. } else {
  626. make.bottom.equalTo(weakSelf.view.mas_bottom);
  627. }
  628. }];
  629. });
  630. [weakSelf _loadAllConversationsFromDBWithIsShowHud:NO];
  631. } failure:^(NSError * _Nonnull error) {
  632. NSLog(@"%@",error);
  633. }];
  634. }
  635. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  636. return 1;
  637. }
  638. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  639. return self.chatListIMArray.count;
  640. }
  641. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  642. ChatMsgListImModel * model = self.chatListIMArray[indexPath.row];
  643. switch (model.AttributeValue) {
  644. case 2:
  645. {
  646. return [ChatMsgListCell configCell2Height];
  647. }
  648. break;
  649. case 0:
  650. {
  651. return [ChatMsgListCell configCell3Height];
  652. }
  653. break;
  654. default:
  655. {
  656. if (self.operationStateEnum == OperationStateEnum1) {
  657. return 0.01f;
  658. }
  659. return [ChatMsgListCell configCell3Height];
  660. }
  661. break;
  662. }
  663. }
  664. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  665. WS(weakSelf);
  666. ChatMsgListImModel * model = [self.chatListIMArray objectAtIndex:indexPath.row];
  667. switch (model.AttributeValue) {
  668. case 2:
  669. {
  670. ChatMsgListCell *cell = [ChatMsgListCell configCell2:tableView indexPath:indexPath];
  671. if(self.operationStateEnum == OperationStateEnum0){
  672. cell.cell2TitleLabel.text = model.FolderName;
  673. cell.cell2isTop.hidden = !model.IsTop;
  674. cell.cell2TimeLabel.hidden = NO;
  675. cell.cell2TimeLabel.text = [NSDate getTimeStringAutoShort2:model.LastModifiedDate];
  676. cell.cell2TimeLabel.textColor = RGB(153, 153, 153);
  677. cell.enterBtn.hidden = YES;
  678. return cell;
  679. }
  680. else if (self.operationStateEnum == OperationStateEnum1){
  681. ChatMsgListCell *cell = [ChatMsgListCell configCell6:tableView indexPath:indexPath];
  682. cell.cell6SelectBtn.selected = model.isSelected;
  683. cell.cell2TitleLabel.text = model.FolderName;
  684. cell.cell2TimeLabel.hidden = YES;
  685. cell.enterBtn.hidden = YES;
  686. cell.cell2RightArrowImgView.hidden = YES;
  687. cell.IsTopView.hidden = YES;
  688. self.isAllselect = [self checkChatListArray];
  689. [self checkMoveBtnEnable];
  690. [self.operationAllSelectButton setTitle:self.isAllselect ? @"取消全选": @"全选" forState:UIControlStateNormal];
  691. return cell;
  692. } else {///if (self.operationStateEnum == OperationStateEnum2)
  693. cell.cell2TimeLabel.text = @"进入";
  694. cell.cell2TitleLabel.text = model.FolderName;
  695. cell.cell2isTop.hidden = !model.IsTop;
  696. cell.cell2TimeLabel.textColor = RGB(57, 121, 211);
  697. return cell;
  698. }
  699. }
  700. break;
  701. case 0:
  702. {
  703. if(self.operationStateEnum == OperationStateEnum0){
  704. ChatMsgListCell *cell = [ChatMsgListCell configCell3:tableView indexPath:indexPath];
  705. cell.IsTopView.hidden = YES;
  706. [cell setCell3DataWithModel:model];
  707. return cell;
  708. }else if (self.operationStateEnum == OperationStateEnum1){
  709. ChatMsgListCell *cell = [ChatMsgListCell configCell5:tableView indexPath:indexPath];
  710. self.isAllselect = [self checkChatListArray];
  711. [self checkMoveBtnEnable];
  712. [cell setCell5DataWithModel:model];
  713. cell.IsTopView.hidden = YES;
  714. self.isAllselect = [self checkChatListArray];
  715. [self checkMoveBtnEnable];
  716. [self.operationAllSelectButton setTitle:self.isAllselect ? @"取消全选": @"全选" forState:UIControlStateNormal];
  717. [cell.cell5SelectBtn setAction:^{
  718. model.isSelected = !model.isSelected;
  719. dispatch_async(dispatch_get_main_queue(), ^{
  720. [weakSelf.tableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationAutomatic];
  721. });
  722. }];
  723. return cell;
  724. }else{///(self.operationStateEnum == OperationStateEnum2)
  725. ChatMsgListCell *cell = [ChatMsgListCell configCell3:tableView indexPath:indexPath];
  726. cell.cell3MengCengView.hidden = NO;
  727. [cell setCell3DataWithModel:model];
  728. return cell;
  729. }
  730. }
  731. case 3:{
  732. ChatMsgListCell *cell = [ChatMsgListCell configCell2:tableView indexPath:indexPath];
  733. if(self.operationStateEnum == OperationStateEnum1){
  734. cell.hidden = YES;
  735. }else{
  736. cell.hidden = NO;
  737. cell.cell2TitleLabel.text = model.Name;
  738. cell.cell2IconImgView.image = IMG(model.AvatarUrl);
  739. cell.cell2isTop.hidden = YES;
  740. cell.cell2TimeLabel.hidden = YES;
  741. cell.cell2TimeLabel.text = [NSDate getTimeStringAutoShort2:model.LastModifiedDate];
  742. cell.cell2TimeLabel.textColor = RGB(153, 153, 153);
  743. cell.enterBtn.hidden = YES;
  744. }
  745. return cell;
  746. }break;
  747. case 4:{
  748. ChatMsgListCell *cell = [ChatMsgListCell configCell2:tableView indexPath:indexPath];
  749. if(self.operationStateEnum == OperationStateEnum1){
  750. cell.hidden = YES;
  751. }else{
  752. cell.hidden = NO;
  753. cell.cell2RedBgView.hidden = self.UReadVerifyCount > 0 ? NO : YES;
  754. cell.cell2TitleLabel.text = model.Name;
  755. cell.cell2IconImgView.image = IMG(model.AvatarUrl);
  756. cell.cell2isTop.hidden = YES;
  757. cell.cell2TimeLabel.hidden = NO;
  758. cell.cell2TimeLabel.text = [NSDate getTimeStringAutoShort2:self.ConfirmationDate];
  759. cell.cell2TimeLabel.textColor = RGB(153, 153, 153);
  760. cell.enterBtn.hidden = YES;
  761. }
  762. return cell;
  763. }break;
  764. default:{
  765. ChatMsgListCell *cell = [ChatMsgListCell configCell2:tableView indexPath:indexPath];
  766. if(self.operationStateEnum == OperationStateEnum1){
  767. cell.hidden = YES;
  768. }else{
  769. cell.hidden = NO;
  770. cell.cell2RedBgView.hidden = self.ReplyCount > 0 ? NO : YES;
  771. cell.cell2TitleLabel.text = model.Name;
  772. cell.cell2IconImgView.image = IMG(model.AvatarUrl);
  773. cell.cell2isTop.hidden = YES;
  774. if (self.ReplyDate.length > 0) {
  775. cell.cell2TimeLabel.hidden = NO;
  776. cell.cell2TimeLabel.text = [NSDate getTimeStringAutoShort2:self.ReplyDate];
  777. }else{
  778. cell.cell2TimeLabel.hidden = YES;
  779. }
  780. cell.cell2TimeLabel.textColor = RGB(153, 153, 153);
  781. cell.enterBtn.hidden = YES;
  782. }
  783. return cell;
  784. }break;
  785. break;
  786. }
  787. }
  788. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  789. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  790. ChatMsgListImModel *model = [self.chatListIMArray objectAtIndex:indexPath.row];
  791. switch (model.AttributeValue) {
  792. case 2:
  793. {
  794. if(self.operationStateEnum == OperationStateEnum0){
  795. WorkingGroupMainVC *vc = [WorkingGroupMainVC initWorkingGroupMainVC];
  796. vc.GroupId = [NSString stringWithFormat:@"%ld",(long)model.Id];
  797. vc.GroupTitle = model.FolderName;
  798. [self.navigationController pushViewController:vc animated:YES];
  799. }else if(self.operationStateEnum == OperationStateEnum1){
  800. //多选操作
  801. model.isSelected = !model.isSelected;
  802. [self.tableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  803. }
  804. }
  805. break;
  806. case 0:
  807. {
  808. if(self.operationStateEnum == OperationStateEnum0){
  809. //进入聊天界面
  810. if (model.ChatType == ChatType_SingleChat) {
  811. [self enterChatView:model];
  812. }else{
  813. [self getGroupInfo:model];
  814. }
  815. }
  816. else if(self.operationStateEnum == OperationStateEnum1){
  817. //多选操作
  818. model.isSelected = !model.isSelected;
  819. [self.tableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  820. }
  821. else if(self.operationStateEnum == OperationStateEnum2){
  822. //此时不可操作
  823. }
  824. }
  825. break;
  826. case 3:
  827. {
  828. MailListVC * vc = [MailListVC initMailListVC];
  829. [self.navigationController pushViewController:vc animated:YES];
  830. }
  831. break;
  832. case 4:
  833. {
  834. ChatTestingVC *vc = [ChatTestingVC initChatTestingVC];
  835. [self.navigationController pushViewController:vc animated:YES];
  836. }
  837. break;
  838. default:
  839. {
  840. ReplayMeVC * vc = [ReplayMeVC initReplayMeVC];
  841. [self.navigationController pushViewController:vc animated:YES];
  842. }
  843. break;
  844. }
  845. }
  846. - (void)checkMoveBtnEnable
  847. {
  848. BOOL isEnable = YES;
  849. for (ChatMsgListImModel *model in self.chatListIMArray) {
  850. if (model.AttributeValue == 2 && model.isSelected) {
  851. isEnable = NO;
  852. }
  853. }
  854. [self.operationBottomMoveBtn setEnabled:isEnable];
  855. }
  856. #pragma mark -当环信收到新消息时,更新数据
  857. - (void)replaceChatData
  858. {
  859. WS(weakSelf);
  860. [self.chatListIMArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  861. ChatMsgListImModel * chatModel = (ChatMsgListImModel *)obj;
  862. [weakSelf.dataArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  863. EMConversationModel * model = (EMConversationModel *)obj;
  864. if (chatModel.ImId == [model.emModel.conversationId integerValue]) {
  865. EMConversation *conversation = model.emModel;
  866. if (!chatModel.IsDisturb) {
  867. chatModel.redNum = model.emModel.unreadMessagesCount;
  868. }
  869. chatModel.ChatText = [weakSelf _getDetailWithModel:conversation];
  870. }
  871. }];
  872. }];
  873. dispatch_async(dispatch_get_main_queue(), ^{
  874. [weakSelf.tableView reloadData];
  875. });
  876. }
  877. - (NSAttributedString *)_getDetailWithModel:(EMConversation *)aConversation
  878. {
  879. NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:@""];
  880. EMMessage *lastMessage = [aConversation latestMessage];
  881. if (!lastMessage) {
  882. return attributedStr;
  883. }
  884. NSString *latestMessageTitle = @"";
  885. EMMessageBody *messageBody = lastMessage.body;
  886. switch (messageBody.type) {
  887. case EMMessageBodyTypeText:
  888. {
  889. NSString *str = [EMEmojiHelper convertEmoji:((EMTextMessageBody *)messageBody).text];
  890. latestMessageTitle = str;
  891. }
  892. break;
  893. case EMMessageBodyTypeImage:
  894. latestMessageTitle = @"[图片]";
  895. break;
  896. case EMMessageBodyTypeVoice:
  897. latestMessageTitle = @"[音频]";
  898. break;
  899. case EMMessageBodyTypeLocation:
  900. latestMessageTitle = @"[位置]";
  901. break;
  902. case EMMessageBodyTypeVideo:
  903. latestMessageTitle = @"[视频]";
  904. break;
  905. case EMMessageBodyTypeFile:
  906. latestMessageTitle = @"[文件]";
  907. break;
  908. default:
  909. break;
  910. }
  911. NSDictionary *ext = aConversation.ext;
  912. if (ext && [ext[kConversation_IsRead] intValue] == kConversation_AtAll) {
  913. NSString *allMsg = @"[有全体消息]";
  914. latestMessageTitle = [NSString stringWithFormat:@"%@ %@", allMsg, latestMessageTitle];
  915. attributedStr = [[NSMutableAttributedString alloc] initWithString:latestMessageTitle];
  916. [attributedStr setAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:1.0 green:.0 blue:.0 alpha:0.5]} range:NSMakeRange(0, allMsg.length)];
  917. } else if (ext && [ext[kConversation_IsRead] intValue] == kConversation_AtYou) {
  918. NSString *atStr = @"[有人@我]";
  919. latestMessageTitle = [NSString stringWithFormat:@"%@ %@", atStr, latestMessageTitle];
  920. attributedStr = [[NSMutableAttributedString alloc] initWithString:latestMessageTitle];
  921. [attributedStr setAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:1.0 green:.0 blue:.0 alpha:0.5]} range:NSMakeRange(0, atStr.length)];
  922. } else {
  923. attributedStr = [[NSMutableAttributedString alloc] initWithString:latestMessageTitle];
  924. }
  925. return attributedStr;
  926. }
  927. - (BOOL)checkChatListArray
  928. {
  929. if (self.chatListIMArray.count == 0) {
  930. return NO;
  931. }
  932. for (ChatMsgListImModel * model in self.chatListIMArray) {
  933. if (!model.isSelected) {
  934. return NO;
  935. }
  936. }
  937. return YES;
  938. }
  939. - (void)enterChatView:(ChatMsgListImModel *)chatModel
  940. {
  941. EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:[NSString stringWithFormat:@"%ld",(long)chatModel.ImId] type: EMConversationTypeChat createIfNotExist:YES];
  942. EMConversationModel *model = [[EMConversationModel alloc] initWithEMModel:conversation];
  943. EMChatViewController *controller = [[EMChatViewController alloc] initWithCoversationModel:model];
  944. if (chatModel.ChatType == ChatType_SingleChat) {
  945. controller.toUserId = chatModel.ToUserId;
  946. controller.ReceiveIcon = chatModel.AvatarUrl;
  947. SelectModel * sModel = [[SelectModel alloc] init];
  948. sModel.UserId = chatModel.ToUserId;
  949. sModel.UserName = chatModel.Name;
  950. sModel.AvatarUrl = chatModel.AvatarUrl;
  951. controller.sModel = sModel;
  952. }
  953. model.name = chatModel.Name;
  954. controller.ImId = chatModel.ImId;
  955. controller.GroupId = chatModel.Id;
  956. controller.chatType = chatModel.ChatType;
  957. controller.listId = chatModel.Id;
  958. controller.isTop = chatModel.IsTop;
  959. controller.hidesBottomBarWhenPushed = YES;
  960. [self.navigationController pushViewController:controller animated:YES];
  961. }
  962. - (void)getGroupInfo:(ChatMsgListImModel *)chatModel
  963. {
  964. self.tableView.allowsSelection = NO;
  965. WS(weakSelf);
  966. [[HttpManager sharedHttpManager] POSTUrl:Host(Group_chat_info) parameters:@{@"GroupChatImId":@(chatModel.ImId)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  967. weakSelf.tableView.allowsSelection = YES;
  968. EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:[NSString stringWithFormat:@"%ld",(long)chatModel.ImId] type: EMConversationTypeGroupChat createIfNotExist:YES];
  969. EMConversationModel *model = [[EMConversationModel alloc] initWithEMModel:conversation];
  970. EMChatViewController *controller = [[EMChatViewController alloc] initWithCoversationModel:model];
  971. controller.toUserId = chatModel.ImId;
  972. controller.groupUserInfoArray = responseObject[@"Item"];
  973. model.name = chatModel.Name;
  974. controller.GroupId = chatModel.Id;
  975. controller.ImId = chatModel.ImId;
  976. controller.chatType = chatModel.ChatType;
  977. controller.isTop = chatModel.IsTop;
  978. controller.hidesBottomBarWhenPushed = YES;
  979. [weakSelf.navigationController pushViewController:controller animated:YES];
  980. } failure:^(NSError * _Nonnull error) {
  981. weakSelf.tableView.allowsSelection = YES;
  982. }];
  983. }
  984. #pragma mark UICollectionView
  985. - (NSInteger)numberOfSectionsInCollectionView:(GHRefreshCollectionView *)collectionView{
  986. if (self.operationStateEnum == OperationStateEnum1) {
  987. return 0;
  988. }
  989. return 1;
  990. }
  991. /**********************************************************************/
  992. #pragma mark -UICollectionViewDataSource
  993. /**********************************************************************/
  994. - (NSInteger)collectionView:(GHRefreshCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  995. return self.collectionDataSource.count;
  996. }
  997. - (UICollectionViewCell *)collectionView:(GHRefreshCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  998. {
  999. MoreAppInfoModel *bean = [self.collectionDataSource objectAtIndex:indexPath.item];
  1000. ChatMsgCollectionCell *cell = [ collectionView dequeueReusableCellWithReuseIdentifier:@"ChatMsgCollectionCell" forIndexPath:indexPath];
  1001. cell.cell0IconImg.image = [UIImage imageNamed:bean.imgName];
  1002. cell.cell0TitleLabel.text = bean.title;
  1003. switch (bean.type) {
  1004. case ChatMenuNoticeType:
  1005. {
  1006. cell.cell0ReadNumLabel.hidden = YES;
  1007. NSString * count = @"0";
  1008. cell.cell0ReadNumLabel.text = count;
  1009. UILabel * label = [UILabel new];
  1010. label.font = [UIFont systemFontOfSize:12];
  1011. label.text = count;
  1012. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  1013. if ((width + 5) < 16) {
  1014. cell.constant.constant = 16;
  1015. }else{
  1016. cell.constant.constant = width + 8;
  1017. }
  1018. }
  1019. break;
  1020. case ChatMenuZhanXinType:
  1021. {
  1022. cell.cell0ReadNumLabel.hidden = YES;
  1023. NSString * count = @"0";
  1024. cell.cell0ReadNumLabel.text = count;
  1025. UILabel * label = [UILabel new];
  1026. label.font = [UIFont systemFontOfSize:12];
  1027. label.text = count;
  1028. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  1029. if ((width + 5) < 16) {
  1030. cell.constant.constant = 16;
  1031. }else{
  1032. cell.constant.constant = width + 8;
  1033. }
  1034. }
  1035. break;
  1036. case ChatMenuWaitType:
  1037. {
  1038. cell.cell0ReadNumLabel.hidden = YES;
  1039. NSString * count = @"0";
  1040. cell.cell0ReadNumLabel.text = count;
  1041. UILabel * label = [UILabel new];
  1042. label.font = [UIFont systemFontOfSize:12];
  1043. label.text = count;
  1044. CGFloat width = [label sizeThatFits:CGSizeMake(SCREEN_WIDTH, 16)].width;
  1045. if ((width + 5) < 16) {
  1046. cell.constant.constant = 16;
  1047. }else{
  1048. cell.constant.constant = width + 8;
  1049. }
  1050. }
  1051. break;
  1052. default:
  1053. {
  1054. cell.cell0ReadNumLabel.hidden = YES ;
  1055. }
  1056. break;
  1057. }
  1058. if(self.operationStateEnum == OperationStateEnum0){
  1059. cell.cell0MengCengView.hidden = YES;
  1060. }else{
  1061. cell.cell0MengCengView.hidden = NO;
  1062. }
  1063. return cell;
  1064. }
  1065. /****************************************************/
  1066. #pragma mark --UICollectionViewDelegateFlowLayout
  1067. /****************************************************/
  1068. - (CGSize)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  1069. {
  1070. // CGFloat width = SCREEN_WIDTH / 4;
  1071. CGFloat width = (SCREEN_WIDTH - (15 + 7)) / 5;
  1072. CGFloat height = 90;
  1073. return CGSizeMake(width, height);
  1074. }
  1075. -(UIEdgeInsets)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  1076. {
  1077. return UIEdgeInsetsMake(0,0,0,0);
  1078. }
  1079. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  1080. return 0;
  1081. }
  1082. - (CGFloat)collectionView:(GHRefreshCollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  1083. return 0;
  1084. }
  1085. - (void)collectionView:(GHRefreshCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  1086. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  1087. if(self.operationStateEnum == OperationStateEnum0){
  1088. MoreAppInfoModel * model = [self.collectionDataSource objectAtIndex:indexPath.item];
  1089. switch (model.type) {
  1090. case ChatMenuNoticeType:{
  1091. // [self pushChatMsgNoticeVC];
  1092. }break;
  1093. case ChatMenuZhanXinType:{
  1094. TDInterLeterHomeViewController *vc = [TDInterLeterHomeViewController initChatMsgNoticeVC];
  1095. vc.hidesBottomBarWhenPushed = YES;
  1096. vc.interLeterFolderId = 0;
  1097. vc.isHome = YES;
  1098. [self.navigationController pushViewController:vc animated:YES];
  1099. }break;
  1100. case ChatMenuTeleListType:{
  1101. MailListVC *vc = [MailListVC initMailListVC];
  1102. vc.isChat = YES;
  1103. vc.hidesBottomBarWhenPushed = YES;
  1104. [self.navigationController pushViewController:vc animated:YES];
  1105. }break;
  1106. case ChatMenuGroupType:{
  1107. MyTDGroupViewController *vc = [[MyTDGroupViewController alloc] init];
  1108. vc.hidesBottomBarWhenPushed = YES;
  1109. [self.navigationController pushViewController:vc animated:YES];
  1110. }break;
  1111. case ChatMenuWaitType:{
  1112. WaitWorkVC *vc = [WaitWorkVC initWaitWorkVC];
  1113. vc.hidesBottomBarWhenPushed = YES;
  1114. [self.navigationController pushViewController:vc animated:YES];
  1115. }break;
  1116. case ChatMenutopicType:{
  1117. MyTDTopicViewController *vc = [MyTDTopicViewController initMyTDTopicViewController];
  1118. vc.hidesBottomBarWhenPushed = YES;
  1119. [self.navigationController pushViewController:vc animated:YES];
  1120. }break;
  1121. default:
  1122. break;
  1123. }
  1124. }
  1125. }
  1126. -(NSMutableArray *)collectionDataSource{
  1127. if(!_collectionDataSource){
  1128. _collectionDataSource = [[NSMutableArray alloc] init];
  1129. }
  1130. return _collectionDataSource;
  1131. }
  1132. - (GHRefreshCollectionView *)collectionView {
  1133. if (!_collectionView) {
  1134. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1135. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1136. CGFloat width = (SCREEN_WIDTH - (15 + 7)) / 5;
  1137. CGFloat height = 90;
  1138. layout.itemSize = CGSizeMake(width, height);
  1139. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  1140. _collectionView = [[GHRefreshCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1141. _collectionView.delegate = self;
  1142. _collectionView.dataSource = self;
  1143. _collectionView.showsHorizontalScrollIndicator = NO;
  1144. [_collectionView registerNib:[UINib nibWithNibName:@"ChatMsgCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"ChatMsgCollectionCell"];
  1145. _collectionView.backgroundColor = [UIColor whiteColor];
  1146. }
  1147. return _collectionView;
  1148. }
  1149. -(NSMutableArray *)getMenuDataSource:(NSMutableArray *)titleArray{
  1150. NSMutableArray *menuDataSourceArray = [[NSMutableArray alloc] init];
  1151. for(int i=0;i<titleArray.count;i++){
  1152. NSString *titleStr = [titleArray objectAtIndex:i];
  1153. WS(weakSelf);
  1154. YCMenuAction *actionMenu = [YCMenuAction actionWithTitle:titleStr image:nil handler:^(YCMenuAction *action) {
  1155. if([@"建文件夹" isEqualToString:action.title]){
  1156. [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"建文件夹" placeholder:@"请输入文件夹名称" confirm:^(NSString * _Nonnull groupName) {
  1157. NSLog(@"%@",groupName);
  1158. NSDictionary * paraDict = @{@"FolderName":groupName,
  1159. @"UserId":@([AppUserModel sharedAppUserModel].Id),
  1160. @"ParentId":@(0),
  1161. @"TypeId":@(10)
  1162. };
  1163. [[HttpManager sharedHttpManager] PUTUrl:Host(APP_Middle_Add_Folder) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  1164. [weakSelf initChatMsgIMData];
  1165. } failure:^(NSError * _Nonnull error) {
  1166. NSLog(@"%@",error);
  1167. SHOWERROR([ZYCTool handerResultData:error])
  1168. }];
  1169. } cancle:^{
  1170. }] show];
  1171. }
  1172. else if ([@"批量编辑" isEqualToString:action.title]){
  1173. [weakSelf changeToOperation:YES];
  1174. }
  1175. else if ([@"新建群聊" isEqualToString:action.title]){
  1176. ChatNewGroupVC *vc = [ChatNewGroupVC initChatNewGroupVC];
  1177. [self.navigationController pushViewController:vc animated:YES];
  1178. }else if ([@"扫一扫" isEqualToString:action.title]){
  1179. [weakSelf scanAction];
  1180. }
  1181. }];
  1182. [menuDataSourceArray addObject:actionMenu];
  1183. }
  1184. return menuDataSourceArray;
  1185. }
  1186. #pragma mark - buttonAction
  1187. - (void)scanAction{
  1188. SWQRCodeConfig *config = [[SWQRCodeConfig alloc]init];
  1189. config.scannerType = SWScannerTypeBoth;
  1190. SWQRCodeViewController *qrcodeVC = [[SWQRCodeViewController alloc]init];
  1191. qrcodeVC.codeConfig = config;
  1192. qrcodeVC.delegate = self;
  1193. [self.navigationController pushViewController:qrcodeVC animated:YES];
  1194. }
  1195. #pragma mark - 扫一扫结果
  1196. - (void)scanResult:(NSString *)scanStr{
  1197. ScanResultModel *model = [[ScanResultModel alloc]initWithString:scanStr error:nil];
  1198. NSLog(@"%@",model);
  1199. WEAKSELF
  1200. switch (model.key) {
  1201. case 1:// 用户
  1202. {
  1203. [self scanNetWork:model.value urlStrong:SaoYiSao_Post ScanKey:@"Guid" success:^(id responseObject) {
  1204. NSDictionary *dic = responseObject;
  1205. AddressUserModel *model = [[AddressUserModel alloc] initWithDictionary:dic error:nil];
  1206. dispatch_async(dispatch_get_main_queue(), ^{
  1207. MailListDetailVC *vc = [MailListDetailVC initMailListDetailVC];
  1208. vc.indexId = model.Id;
  1209. vc.isAdd = YES;
  1210. [weakSelf.navigationController pushViewController:vc animated:YES];
  1211. });
  1212. } failure:^(NSError *error) {
  1213. SHOWERROR([ZYCTool handerResultData:error]);
  1214. }];
  1215. }
  1216. break;
  1217. case 2:// 群聊
  1218. {
  1219. [self scanToNetWork:model.value urlStrong:SaoYiSao2_Post success:^(id responseObject) {
  1220. ChatJoinGroupVC * vc = [ChatJoinGroupVC initChatJoinGroupVC];
  1221. vc.dict = responseObject;
  1222. [weakSelf.navigationController pushViewController:vc animated:YES];
  1223. } failure:^(NSError *error) {
  1224. SHOWERROR([ZYCTool handerResultData:error]);
  1225. }];
  1226. }
  1227. break;
  1228. case 3://小组
  1229. {
  1230. [self scanToNetWork:model.value urlStrong:SaoYiSao3_Post success:^(id responseObject) {
  1231. if ([responseObject[@"IsUser"] boolValue]) {
  1232. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  1233. vc.GroupId = [responseObject[@"Id"] integerValue];
  1234. vc.titleStr = responseObject[@"Name"];
  1235. [weakSelf.navigationController pushViewController:vc animated:YES];
  1236. }else{
  1237. dispatch_async(dispatch_get_main_queue(), ^{
  1238. TDQrJoinVC * vc = [TDQrJoinVC initTDQrJoinVC];
  1239. vc.dict = responseObject;
  1240. [weakSelf.navigationController pushViewController:vc animated:YES];
  1241. });
  1242. }
  1243. } failure:^(NSError *error) {
  1244. SHOWERROR([ZYCTool handerResultData:error]);
  1245. }];
  1246. }
  1247. break;
  1248. default:
  1249. break;
  1250. }
  1251. }
  1252. - (void)scanNetWork:(NSString *)scanStr urlStrong:(NSString *)urlstring ScanKey:(NSString*)key success:(void (^) (id responseObject))successful failure:(void (^) (NSError *error))failure{
  1253. SHOWLOADING
  1254. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,urlstring] parameters:@{key:scanStr} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  1255. successful(responseObject);
  1256. REMOVESHOW
  1257. } failure:^(NSError * _Nonnull error) {
  1258. REMOVESHOW
  1259. failure(error);
  1260. }];
  1261. }
  1262. - (void)scanToNetWork:(NSString *)scanStr urlStrong:(NSString *)urlstring success:(void (^) (id responseObject))successful failure:(void (^) (NSError *error))failure{
  1263. SHOWLOADING
  1264. NSString * url = [NSString stringWithFormat:@"%@%@",Host(urlstring),scanStr];
  1265. [[HttpManager sharedHttpManager] GETUrl:url parameters:@{} success:^(id _Nonnull responseObject) {
  1266. REMOVESHOW
  1267. successful(responseObject);
  1268. } failure:^(NSError * _Nonnull error) {
  1269. REMOVESHOW
  1270. }];
  1271. }
  1272. -(NSMutableArray *)taskActionArray{
  1273. if(!_taskActionArray){
  1274. _taskActionArray = [[NSMutableArray alloc] initWithObjects:@"建文件夹",@"批量编辑",@"新建群聊",@"扫一扫", nil];
  1275. }
  1276. return _taskActionArray;
  1277. }
  1278. - (void)changeSelectStatus
  1279. {
  1280. for ( ChatMsgListImModel * model in self.chatListIMArray) {
  1281. model.isSelected = NO;
  1282. }
  1283. }
  1284. #pragma mark 批量操作与正常操作界面切换
  1285. -(void)changeToOperation:(BOOL)operation{
  1286. if(operation){
  1287. [self removeTableRefresh];
  1288. self.rightButton.hidden = YES;
  1289. self.titleL.text = @"批量编辑";
  1290. //默认操作状态为批量编辑状态
  1291. self.operationStateEnum = OperationStateEnum1;
  1292. self.operationAllSelectButton.hidden = NO;
  1293. self.menuBtn.hidden = YES;
  1294. self.HeadView.hidden = YES;
  1295. self.searchConstant.constant = 0.f;
  1296. WS(weakSelf);
  1297. [self.operationAllSelectButton setAction:^{
  1298. NSLog(@"全选");
  1299. for (ChatMsgListImModel *model in weakSelf.chatListIMArray) {
  1300. model.isSelected = !weakSelf.isAllselect;
  1301. }
  1302. [weakSelf.tableView reloadData];
  1303. }];
  1304. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  1305. make.left.right.mas_equalTo(self.view);
  1306. make.top.mas_equalTo(self.HeadView.mas_bottom);
  1307. make.bottom.equalTo(self.operationBottomBgView.mas_top);
  1308. }];
  1309. // self.tabBarController.tabBar.hidden = YES;
  1310. self.operationBottomBgView.hidden = NO;
  1311. }else{
  1312. [self addTableRefresh];
  1313. self.titleL.text = @"私信";
  1314. self.rightButton.hidden = NO;
  1315. self.HeadView.hidden = NO;
  1316. self.searchConstant.constant = 50.f;
  1317. //默认操作状态为无状态
  1318. self.operationStateEnum = OperationStateEnum0;
  1319. self.operationAllSelectButton.hidden = YES;
  1320. self.menuBtn.hidden = NO;
  1321. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  1322. make.left.right.mas_equalTo(self.view);
  1323. make.top.mas_equalTo(self.HeadView.mas_bottom);
  1324. if (@available(iOS 11.0, *)) {
  1325. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  1326. } else {
  1327. make.bottom.equalTo(self.view.mas_bottom);
  1328. }
  1329. }];
  1330. self.operationBottomBgView.hidden = YES;
  1331. }
  1332. [self.tableView reloadData];
  1333. }
  1334. #pragma mark 移动 isEdit:当前是否为编辑状态
  1335. -(void)userDidMove:(BOOL)move isEdit:(BOOL)isEdit{
  1336. //移动
  1337. if(move){
  1338. //默认操作状态为移动状态
  1339. self.operationStateEnum = OperationStateEnum2;
  1340. self.rightButton.hidden = NO;
  1341. [self resetRightBtnAction:NO];
  1342. //隐藏tabBar - 并将TableView至底端
  1343. self.tabBarController.tabBar.hidden = YES;
  1344. self.view.height += self.tabBarController.tabBar.height;
  1345. self.tableView.height += self.tabBarController.tabBar.height;
  1346. [self.view layoutIfNeeded];
  1347. [self.tableView layoutIfNeeded];
  1348. //隐藏operationBottomBgView
  1349. self.operationBottomBgView.hidden = YES;
  1350. }
  1351. else{
  1352. //隐藏tabBar - 并将TableView至底端有tabBar.height的高
  1353. self.tabBarController.tabBar.hidden = YES;
  1354. self.view.height -= self.tabBarController.tabBar.height;
  1355. self.tableView.height -= self.tabBarController.tabBar.height;
  1356. [self.view layoutIfNeeded];
  1357. [self.tableView layoutIfNeeded];
  1358. //显示operationBottomBgView
  1359. self.operationBottomBgView.hidden = NO;
  1360. if(isEdit){
  1361. self.operationStateEnum = OperationStateEnum1;
  1362. self.rightButton.hidden = YES;
  1363. [self resetRightBtnAction:YES];
  1364. }else{
  1365. [self changeToOperation:NO];
  1366. }
  1367. }
  1368. [self.tableView reloadData];
  1369. }
  1370. -(void)initBottomBgView{
  1371. UIButton *leftCloseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  1372. [leftCloseBtn setTitle:@"删除" forState:UIControlStateNormal];
  1373. [leftCloseBtn setTitleColor:RGB(255, 82, 82) forState:UIControlStateNormal];
  1374. leftCloseBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  1375. [self.operationBottomBgView addSubview:leftCloseBtn];
  1376. leftCloseBtn.frame = CGRectMake(0, 0, SCREEN_WIDTH/2, self.operationBottomBgView.height);
  1377. UIButton *rightMoveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  1378. [rightMoveBtn setTitle:@"移动" forState:UIControlStateNormal];
  1379. [rightMoveBtn setTitleColor:RGB(57, 121, 211) forState:UIControlStateNormal];
  1380. [rightMoveBtn setTitleColor:UIColorHex(#666666) forState:UIControlStateDisabled];
  1381. rightMoveBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  1382. self.operationBottomDeleteBtn = leftCloseBtn;
  1383. self.operationBottomMoveBtn = rightMoveBtn;
  1384. [self.operationBottomBgView addSubview:rightMoveBtn];
  1385. rightMoveBtn.frame = CGRectMake(SCREEN_WIDTH/2, 0, SCREEN_WIDTH/2, self.operationBottomBgView.height);
  1386. UIView *line = [[UIView alloc] init];
  1387. line.backgroundColor = RGB(240, 239, 244);
  1388. [self.operationBottomBgView addSubview:line];
  1389. line.frame = CGRectMake(SCREEN_WIDTH/2, 0, 0.5, self.operationBottomBgView.height);
  1390. WS(weakSelf);
  1391. [leftCloseBtn setAction:^{
  1392. [weakSelf.selectArray removeAllObjects];
  1393. for (ChatMsgListImModel * model in weakSelf.chatListIMArray) {
  1394. if (model.isSelected) {
  1395. [weakSelf.selectArray addObject:model];
  1396. }
  1397. }
  1398. if (weakSelf.selectArray.count > 0) {
  1399. [weakSelf isDel:weakSelf.selectArray];
  1400. }
  1401. }];
  1402. [rightMoveBtn setAction:^{
  1403. [weakSelf.selectArray removeAllObjects];
  1404. for (ChatMsgListImModel * model in weakSelf.chatListIMArray) {
  1405. if (model.isSelected) {
  1406. [weakSelf.selectArray addObject:@(model.Id)];
  1407. }
  1408. }
  1409. if (weakSelf.selectArray.count > 0) {
  1410. [weakSelf chatListMove:weakSelf.selectArray];
  1411. }
  1412. }];
  1413. [[UtilsTools getWindow] addSubview:self.operationBottomBgView];
  1414. }
  1415. -(UIView *)operationBottomBgView{
  1416. if(!_operationBottomBgView){
  1417. _operationBottomBgView = [[UIView alloc] init];
  1418. CGFloat bottomBgViewH = self.tabBarController.tabBar.height;
  1419. _operationBottomBgView.frame = CGRectMake(0, SCREEN_HEIGHT - bottomBgViewH, SCREEN_WIDTH, bottomBgViewH);
  1420. _operationBottomBgView.backgroundColor = RGB(255, 255, 255);
  1421. _operationBottomBgView.hidden = YES;
  1422. }
  1423. return _operationBottomBgView;
  1424. }
  1425. -(void)isDel:(NSMutableArray *)array
  1426. {
  1427. WS(weakSelf);
  1428. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"确认删除?" preferredStyle:UIAlertControllerStyleAlert];
  1429. UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1430. }];
  1431. UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1432. [weakSelf chatListDelete:array];
  1433. }];
  1434. [alertController addAction:cancel];
  1435. [alertController addAction:ok];
  1436. [self presentViewController:alertController animated:YES completion:nil];
  1437. }
  1438. -(NSMutableArray *)chatListIMArray{
  1439. if(!_chatListIMArray){
  1440. _chatListIMArray = [[NSMutableArray alloc] init];
  1441. }
  1442. return _chatListIMArray;
  1443. }
  1444. -(NSMutableArray *)selectArray{
  1445. if(!_selectArray){
  1446. _selectArray = [[NSMutableArray alloc] init];
  1447. }
  1448. return _selectArray;
  1449. }
  1450. -(NSMutableArray *)dataArray{
  1451. if(!_dataArray){
  1452. _dataArray = [[NSMutableArray alloc] init];
  1453. }
  1454. return _dataArray;
  1455. }
  1456. - (MyTDGroupView *)SearchView
  1457. {
  1458. if (!_SearchView) {
  1459. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  1460. }
  1461. return _SearchView;
  1462. }
  1463. - (void)getChatRecord{
  1464. }
  1465. #pragma mark - 接收通知跳转到群聊页面
  1466. - (void)pushEMChatViewController:(NSNotification *)notification
  1467. {
  1468. NSDictionary * groupDict = notification.userInfo;
  1469. NSString * groupId = [NSString stringWithFormat:@"%@",[groupDict objectForKey:@"GroupChatImId"]];
  1470. WS(weakSelf);
  1471. [[HttpManager sharedHttpManager] POSTUrl:Host(Group_chat_info) parameters:@{@"GroupChatImId":groupId} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  1472. EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:[NSString stringWithFormat:@"%@",groupId] type: EMConversationTypeGroupChat createIfNotExist:YES];
  1473. EMConversationModel *model = [[EMConversationModel alloc] initWithEMModel:conversation];
  1474. EMChatViewController *controller = [[EMChatViewController alloc] initWithCoversationModel:model];
  1475. controller.toUserId = [[groupDict objectForKey:@"GroupChatImId"] integerValue];
  1476. controller.groupUserInfoArray = responseObject[@"Item"];
  1477. model.name = [groupDict objectForKey:@"Name"];
  1478. controller.GroupId = [[groupDict objectForKey:@"Id"] integerValue];
  1479. controller.chatType = ChatType_GroupChat;
  1480. controller.hidesBottomBarWhenPushed = YES;
  1481. [weakSelf.navigationController pushViewController:controller animated:YES];
  1482. } failure:^(NSError * _Nonnull error) {
  1483. }];
  1484. }
  1485. - (void)pushTDGroupController:(NSNotification *)notification
  1486. {
  1487. MyTDGroupViewController *vc = [[MyTDGroupViewController alloc] init];
  1488. vc.isPush = YES;
  1489. vc.pushDict = notification.userInfo;
  1490. [self.navigationController pushViewController:vc animated:NO];
  1491. }
  1492. //#pragma mark - 接收Drawer通知跳转到对应的子页面
  1493. //- (void)pushSubViewController:(NSNotification *)notification
  1494. //{
  1495. // ///@"站内信", @"通知", @"收藏",@"笔记", @"设置"
  1496. // NSInteger index = [[notification.userInfo objectForKey:VCINDEX] integerValue];
  1497. // switch (index) {
  1498. // case 0:
  1499. // {
  1500. // [self pushInterLeterVC];
  1501. // }
  1502. // break;
  1503. // case 1:
  1504. // {
  1505. // [self pushChatMsgNoticeVC];
  1506. // }
  1507. // break;
  1508. // default:
  1509. // break;
  1510. // }
  1511. //}
  1512. //#pragma mark - 跳转到站内信、通知页面
  1513. //- (void)pushInterLeterVC
  1514. //{
  1515. // TDInterLeterHomeViewController *vc = [TDInterLeterHomeViewController initChatMsgNoticeVC];
  1516. // vc.interLeterFolderId = 0;
  1517. // vc.hidesBottomBarWhenPushed = YES;
  1518. // [self.navigationController pushViewController:vc animated:YES];
  1519. //}
  1520. //- (void)pushChatMsgNoticeVC
  1521. //{
  1522. // ChatMsgListVC *vc = [ChatMsgListVC initChatMsgListVC];
  1523. // vc.hidesBottomBarWhenPushed = YES;
  1524. // [self.navigationController pushViewController:vc animated:YES];
  1525. //}
  1526. - (void)viewWillDisappear:(BOOL)animated
  1527. {
  1528. [self changeToOperation:NO];
  1529. }
  1530. - (void)dealloc
  1531. {
  1532. [[EMClient sharedClient].chatManager removeDelegate:self];
  1533. [[EMClient sharedClient].groupManager removeDelegate:self];
  1534. [[EMConversationHelper shared] removeDelegate:self];
  1535. [[NSNotificationCenter defaultCenter] removeObserver:self];
  1536. }
  1537. @end