ChatMsgListVC.m 70 KB

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