ChatMsgListVC.m 69 KB

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