ChatMsgListVC.m 69 KB

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