ChatMsgListVC.m 72 KB

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