ChatMsgListVC.m 69 KB

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