123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793 |
- //
- // ChatMsgListVC.m
- // smartRhino
- //
- // Created by armin on 2019/11/2.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "ChatMsgListVC.h"
- #import "ChatMsgListCell.h"
- #import "GHRefreshCollectionView.h"
- #import "ChatMsgCollectionCell.h"
- #import "YCMenuView.h"
- #import "ChatMsgTopSearchVC.h"
- #import "WorkingGroupMainVC.h"
- #import "ShowNewGroupAlert.h"
- #import "ChatMsgNoticeVC.h"
- #import "MoreAppVC.h"
- #import "ChatNewGroupVC.h"
- #import "NoticeUnreadVC.h"
- #import "MailListVC.h"
- #import "EMChatViewController.h"
- #import "TDInterLeterHomeViewController.h"
- #import "EMRealtimeSearch.h"
- #import "EMConversationHelper.h"
- #import "MoreAppModel.h"
- #import "NavigationController.h"
- #import "TabBarController.h"
- #import "MyTDGroupViewController.h"
- #import "WaitWorkVC.h"
- #import "ChatMsgWorkModel.h"
- #import "MyTDTopicViewController.h"
- #import "TDInterLeterHomeViewController.h"
- #import "ChatListMoveVC.h"
- #import "NSDate+Extension.h"
- #import "SWQRCodeConfig.h"
- #import "SWQRCodeViewController.h"
- #import "MailListDetailVC.h"
- #import "ChatJoinGroupVC.h"
- #import "TDQrJoinVC.h"
- #import "MyTDGroupView.h"
- #import "ChatTestingVC.h"
- #import "ReplayMeVC.h"
- #import "TDGroupInfoListVC.h"
- #import "ChatMsgEditVC.h"
- static NSString *kConversation_IsRead = @"kHaveAtMessage";
- static int kConversation_AtYou = 1;
- static int kConversation_AtAll = 2;
- @interface ChatMsgListVC ()<UITableViewDelegate,UITableViewDataSource,EMChatManagerDelegate, EMGroupManagerDelegate, EMConversationsDelegate>
- @property (strong,nonatomic) UITableView *tableView;
- //菜单列表数据源
- @property (strong,nonatomic) NSMutableArray *taskActionArray;
- @property (strong, nonatomic) MyTDGroupView *SearchView;
- @property (strong,nonatomic) NSMutableArray *dataArray;
- @property (strong,nonatomic) NSMutableArray *chatListIMArray;
- @property (strong,nonatomic) NSMutableArray *selectArray;
- @property (assign,nonatomic) BOOL isAllselect;
- @property (copy,nonatomic) NSString *ConfirmationDate;
- @property (copy,nonatomic) NSString *ReplyDate;
- @property (assign,nonatomic) NSInteger ReplyCount;
- @property (assign,nonatomic) NSInteger UReadVerifyCount;
- @end
- @implementation ChatMsgListVC
- - (void)addTableRefresh
- {
- WS(weakSelf);
- self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [weakSelf headRefresh];
- }];
- }
- - (void)removeTableRefresh
- {
- [self.tableView.mj_header removeFromSuperview];
- }
- - (void)headRefresh{
- [self.chatListIMArray removeAllObjects];
- [self initChatMsgIMData];
- }
- - (UITableView *)tableView
- {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- }
- return _tableView;
- }
- - (void)conversationListDidUpdate:(NSArray *)aConversationList
- {
- [self _loadAllConversationsFromDBWithIsShowHud:NO];
- }
- - (void)messagesDidReceive:(NSArray *)aMessages
- {
- [self headRefresh];
- }
- - (void)_reSortedConversationModelsAndReloadView
- {
- NSArray *sorted = [self.dataArray sortedArrayUsingComparator:^(EMConversationModel *obj1, EMConversationModel *obj2) {
- EMMessage *message1 = [obj1.emModel latestMessage];
- EMMessage *message2 = [obj2.emModel latestMessage];
- if(message1.timestamp > message2.timestamp) {
- return(NSComparisonResult)NSOrderedAscending;
- } else {
- return(NSComparisonResult)NSOrderedDescending;
- }}];
-
- NSMutableArray *conversationModels = [NSMutableArray array];
- for (EMConversationModel *model in sorted) {
- if (!model.emModel.latestMessage) {
- [EMClient.sharedClient.chatManager deleteConversation:model.emModel.conversationId
- isDeleteMessages:NO
- completion:nil];
- continue;
- }
- [conversationModels addObject:model];
- }
- [self.dataArray removeAllObjects];
- [self.dataArray addObjectsFromArray:conversationModels];
- [self replaceChatData];
- }
- - (void)_loadAllConversationsFromDBWithIsShowHud:(BOOL)aIsShowHUD
- {
- __weak typeof(self) weakself = self;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSArray *conversations = [[EMClient sharedClient].chatManager getAllConversations];
- NSArray *sorted = [conversations sortedArrayUsingComparator:^(EMConversation *obj1, EMConversation *obj2) {
- EMMessage *message1 = [obj1 latestMessage];
- EMMessage *message2 = [obj2 latestMessage];
- if(message1.timestamp > message2.timestamp) {
- return(NSComparisonResult)NSOrderedAscending;
- } else {
- return(NSComparisonResult)NSOrderedDescending;
- }}];
-
- [weakself.dataArray removeAllObjects];
-
- NSArray *models = [EMConversationHelper modelsFromEMConversations:sorted];
- [weakself.dataArray addObjectsFromArray:models];
- [weakself replaceChatData];
- });
- }
- #pragma mark - EMConversationsDelegate
- - (void)didConversationUnreadCountToZero:(EMConversationModel *)aConversation
- {
- [self replaceChatData];
- }
- - (void)didResortConversationsLatestMessage
- {
- [self _reSortedConversationModelsAndReloadView];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.fd_prefersNavigationBarHidden = YES;
- self.view.backgroundColor = RGB(240, 239, 244);
- [[EMClient sharedClient].chatManager addDelegate:self delegateQueue:nil];
- [[EMClient sharedClient].groupManager addDelegate:self delegateQueue:nil];
- [[EMConversationHelper shared] addDelegate:self];
-
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_offset(UIEdgeInsetsZero);
- }];
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.backgroundColor = [UIColor clearColor];
-
- [self headRefresh];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushTDGroupController:) name:PUSHTDGROUPCOTROLLER object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushEMChatViewController:) name:PUSHEMCHATVIEWCOTROLLER object:nil];
- // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushSubViewController:) name:DRAWERPUSHVC object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(JPushToVC:) name:JPUSHSUCCESS object:nil];
- }
- - (void)pushEditVC
- {
- WS(weakSelf);
- ChatMsgEditVC * vc = [ChatMsgEditVC initChatMsgEditVC];
- vc.dataArray = self.chatListIMArray.mutableCopy;
- vc.upDataBlock = ^{
- [weakSelf headRefresh];
- };
- vc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:vc animated:NO];
- }
- #pragma mark - JPush
- - (void)JPushToVC:(NSNotification *)noti
- {
- PushModel * model = [PushModel modelWithDictionary:noti.userInfo];
- for (ChatMsgListImModel * cmodel in self.chatListIMArray) {
- if (cmodel.ImId == [model.ImId integerValue] && model.chatType == ChatType_SingleChat) {
- [self enterChatView:cmodel];
- }else{
- [self getGroupInfo:cmodel];
- }
- }
- }
- -(void)initChatMsgIMData{
- WS(weakSelf);
- NSString * url = [NSString stringWithFormat:@"%@0",Host(Often_Contact_List)];
- [[HttpManager sharedHttpManager] GETUrl:url parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
- NSLog(@"%@",responseObject);
- [weakSelf.chatListIMArray removeAllObjects];
- [weakSelf.tableView.mj_header endRefreshing];
- if ([responseObject[@"OftenContactInfos"] isKindOfClass:[NSArray class]]) {
- for (NSDictionary * dict in responseObject[@"OftenContactInfos"]) {
- ChatMsgListImModel * model = [ChatMsgListImModel modelWithDictionary:dict];
- [weakSelf.chatListIMArray addObject:model];
- }
- }
- weakSelf.ConfirmationDate = responseObject[@"ConfirmationDate"];
- weakSelf.ReplyDate = responseObject[@"ReplyDate"];
- weakSelf.ReplyCount = [responseObject[@"ReplyCount"] integerValue];
- weakSelf.UReadVerifyCount = [responseObject[@"UReadVerifyCount"] integerValue];
- [weakSelf _loadAllConversationsFromDBWithIsShowHud:NO];
- } failure:^(NSError * _Nonnull error) {
- NSLog(@"%@",error);
- }];
- }
- - (NSString *)isNullWithString:(id)value
- {
- if ([value isKindOfClass:[NSNull class]]) {
- return @"";
- }else{
- if ([value isKindOfClass:[NSString class]]) {
- return value;
- }else{
- return [value stringValue];
- }
- }
- }
- //- (BOOL)hidesBottomBarWhenPushed{
- // return NO;
- //}
- //- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(nonnull NSIndexPath *)indexPath
- //{
- // return YES;
- //}
- //#pragma mark - 左滑按钮 iOS8以上
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
- - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){// delete action
- WS(weakSelf);
- ChatMsgListImModel * model = weakSelf.chatListIMArray[indexPath.row];
- switch (model.AttributeValue) {
- case 2:
- {
- UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
- completionHandler (YES);
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
- UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf chatListDelete:@[model].copy];
- }];
- UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alert addAction:sureAction];
- [alert addAction:cancelAction];
- [weakSelf presentViewController:alert animated:YES completion:^{
-
- }];
-
- }];
- action1.backgroundColor = RGB(255, 59, 47);
- UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"重命名" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
- completionHandler (NO);
- [weakSelf workGroupReName:model];
-
- }];
- action2.backgroundColor = RGB(255, 149, 3);
- UIContextualAction *action3 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:model.IsTop ? @"取消置顶" : @"置顶" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
- completionHandler (YES);
- [weakSelf chatListIsTop:model];
- }];
- action3.backgroundColor = RGB(197, 201, 204);
- UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1, action2, action3]];
- actions.performsFirstActionWithFullSwipe = NO;
- return actions;
- }
- break;
- default:
- {
- UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
- completionHandler (YES);
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
- UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf chatListDelete:[NSMutableArray arrayWithArray:@[model]]];
- }];
- UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alert addAction:sureAction];
- [alert addAction:cancelAction];
- [weakSelf presentViewController:alert animated:YES completion:^{
-
- }];
- }];
- action1.backgroundColor = RGB(255, 59, 47);
- UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"移动" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
- completionHandler (YES);
- [weakSelf chatListMove:@[@(model.Id)]];
-
- }];
- action2.backgroundColor = RGB(61, 156, 248);
- UIContextualAction *action3 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:model.IsTop ? @"取消置顶" : @"置顶" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
- completionHandler (YES);
- [weakSelf chatListIsTop:model];
- }];
- action3.backgroundColor = RGB(197, 201, 204);
- UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1, action2, action3]];
- actions.performsFirstActionWithFullSwipe = NO;
- return actions;
- }
- break;
- }
- }
- #else
- - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
- WS(weakSelf);
- ChatMsgListImModel * model = weakSelf.chatListIMArray[indexPath.row];
- switch (model.AttributeValue) {
- case 2:
- {
- UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
- UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf chatListDelete:@[model].copy];
- }];
- UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alert addAction:sureAction];
- [alert addAction:cancelAction];
- [weakSelf presentViewController:alert animated:YES completion:^{
-
- }];
- }];
- action1.backgroundColor = RGB(255, 59, 47);
- UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"重命名" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- [weakSelf workGroupReName:model];
- }];
- action2.backgroundColor = RGB(255, 149, 3);
- UITableViewRowAction *action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:model.IsTop ? @"取消置顶" : @"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- [weakSelf chatListIsTop:model];
- }];
- action3.backgroundColor = RGB(197, 201, 204);
- return @[action1, action2, action3];
- }
- break;
- default:
- {
- UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
- UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf chatListDelete:[NSMutableArray arrayWithArray:@[model]]];
- }];
- UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alert addAction:sureAction];
- [alert addAction:cancelAction];
- [weakSelf presentViewController:alert animated:YES completion:^{
-
- }];
- }];
- action1.backgroundColor = RGB(255, 59, 47);
- UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"移动" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- [weakSelf chatListMove:@[@(model.Id)]];
- }];
- action2.backgroundColor = RGB(61, 156, 248);
- UITableViewRowAction *action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:model.IsTop ? @"取消置顶" : @"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- [weakSelf chatListIsTop:model];
- }];
- action3.backgroundColor = RGB(197, 201, 204);
- return @[action1, action2, action3];
- }
- break;
- }
- }
- #endif
- - (void)workGroupReName:(ChatMsgListImModel *)model
- {
- WS(weakSelf);
- [[ShowNewGroupAlert initShowNewGroupAlertWithTitle:@"重命名" changeStr:model.FolderName confirm:^(NSString * _Nonnull groupName) {
- NSLog(@"%@",groupName);
- [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_ReName) parameters:@{@"FolderName":groupName,@"Id":@(model.Id)} responseStyle:DATA success:^(id _Nonnull responseObject) {
- [weakSelf initChatMsgIMData];
- } failure:^(NSError * _Nonnull error) {
- NSLog(@"%@",error);
- SHOWERROR([ZYCTool handerResultData:error])
- }];
- } cancle:^{
- }] show];
- }
- - (void)getUserInfoInDocument:(NSString *)ImId{
- NSMutableArray * array = [[NSMutableArray alloc] initWithArray:USERDEFAULTSGET(@"ChatList")];
- for (NSMutableDictionary * dict in array) {
- if ([[dict objectForKey:@"ImId"] isEqualToString:ImId]) {
- [array removeObject:dict];
- }
- }
- USERDEFAULTSSET(array,@"ChatList");
- }
- - (void)chatListDelete:(NSMutableArray *)array
- {
- NSMutableArray * addArray = [NSMutableArray array];
- for (ChatMsgListImModel * model in array) {
- [addArray addObject:@(model.Id)];
- [self getUserInfoInDocument:[NSString stringWithFormat:@"%ld",(long)model.ImId]];
- }
- SHOWLOADING
- WS(weakSelf);
- NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
- [dic setValue:addArray forKey:@"MiddleIds"];
- [dic setValue:@(10) forKey:@"FolderType"];
-
- [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_DeleteRecord) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) {
- REMOVESHOW
- [weakSelf initChatMsgIMData];
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- NSLog(@"%@",error);
- SHOWERROR([ZYCTool handerResultData:error])
- }];
- }
- - (void)chatListMove:(NSArray *)array
- {
- ChatListMoveVC * vc = [ChatListMoveVC initChatListMoveVC];
- vc.Id = 0;
- vc.titleStr = @"移动到";
- vc.listArray = [NSMutableArray arrayWithArray:array];
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)chatListIsTop:(ChatMsgListImModel *)model
- {
- WS(weakSelf);
- SHOWLOADING
- [[HttpManager sharedHttpManager] PUTUrl:[NSString stringWithFormat:@"%@%ld",Host(API_Find_Top),(long)model.Id] parameters:@{} responseStyle:DATA success:^(id _Nonnull responseObject) {
- REMOVESHOW
- [weakSelf reCreateTable];
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error])
- }];
- }
- - (void)reCreateTable
- {
- [self.chatListIMArray removeAllObjects];
- // ChatMsgListImModel * amodel = [[ChatMsgListImModel alloc] init];
- // amodel.AttributeValue = 3;
- // amodel.Name = @"通讯录";
- // amodel.AvatarUrl = @"chat_phone_list";
- // [self.chatListIMArray addObject:amodel];
- // ChatMsgListImModel * bmodel = [[ChatMsgListImModel alloc] init];
- // bmodel.AttributeValue = 4;
- // bmodel.Name = @"验证信息";
- // bmodel.AvatarUrl = @"chat_yan_message";
- // [self.chatListIMArray addObject:bmodel];
- // ChatMsgListImModel * cmodel = [[ChatMsgListImModel alloc] init];
- // cmodel.AttributeValue = 5;
- // cmodel.Name = @"回复我的";
- // cmodel.AvatarUrl = @"chat_replay_me";
- // [self.chatListIMArray addObject:cmodel];
- WS(weakSelf);
- NSString * url = [NSString stringWithFormat:@"%@0",Host(Often_Contact_List)];
- [[HttpManager sharedHttpManager] GETUrl:url parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
- NSLog(@"%@",responseObject);
- [weakSelf.tableView.mj_header endRefreshing];
- if ([responseObject[@"OftenContactInfos"] isKindOfClass:[NSArray class]]) {
- for (NSDictionary * dict in responseObject[@"OftenContactInfos"]) {
- ChatMsgListImModel * model = [ChatMsgListImModel modelWithDictionary:dict];
- [weakSelf.chatListIMArray addObject:model];
- }
- }
- weakSelf.ConfirmationDate = responseObject[@"ConfirmationDate"];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView removeFromSuperview];
- weakSelf.tableView = nil;
- [weakSelf.view addSubview:weakSelf.tableView];
- weakSelf.tableView.delegate = weakSelf;
- weakSelf.tableView.dataSource = weakSelf;
- weakSelf.tableView.backgroundColor = [UIColor clearColor];
- [weakSelf.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_offset(UIEdgeInsetsZero);
- }];
- });
- [weakSelf _loadAllConversationsFromDBWithIsShowHud:NO];
- } failure:^(NSError * _Nonnull error) {
- NSLog(@"%@",error);
- }];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.chatListIMArray.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- ChatMsgListImModel * model = self.chatListIMArray[indexPath.row];
- switch (model.AttributeValue) {
- case 2:
- {
- return [ChatMsgListCell configCell2Height];
- }
- break;
- default:
- {
- return [ChatMsgListCell configCell3Height];
- }
- break;
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- ChatMsgListImModel * model = [self.chatListIMArray objectAtIndex:indexPath.row];
- switch (model.AttributeValue) {
- case 2:
- {
- ChatMsgListCell *cell = [ChatMsgListCell configCell2:tableView indexPath:indexPath];
- cell.cell2IconImgView.image = IMG(@"find_1");
- cell.cell2TitleLabel.text = model.FolderName;
- cell.cell2isTop.hidden = !model.IsTop;
- cell.cell2TimeLabel.hidden = NO;
- cell.cell2TimeLabel.text = [NSDate getTimeStringAutoShort2:model.LastModifiedDate];
- cell.cell2TimeLabel.textColor = RGB(153, 153, 153);
- cell.enterBtn.hidden = YES;
- return cell;
- }
- break;
- default:
- {
- ChatMsgListCell *cell = [ChatMsgListCell configCell3:tableView indexPath:indexPath];
- cell.IsTopView.hidden = YES;
- [cell setCell3DataWithModel:model];
- return cell;
- }
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- ChatMsgListImModel *model = [self.chatListIMArray objectAtIndex:indexPath.row];
- switch (model.AttributeValue) {
- case 2:
- {
- WorkingGroupMainVC *vc = [WorkingGroupMainVC initWorkingGroupMainVC];
- vc.GroupId = [NSString stringWithFormat:@"%ld",(long)model.Id];
- vc.GroupTitle = model.FolderName;
- vc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- default:
- {
- //进入聊天界面
- if (model.ChatType == ChatType_SingleChat) {
- [self enterChatView:model];
- }else{
- [self getGroupInfo:model];
- }
- }
- break;
- }
- }
- #pragma mark -当环信收到新消息时,更新数据
- - (void)replaceChatData
- {
- WS(weakSelf);
- [self.chatListIMArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- ChatMsgListImModel * chatModel = (ChatMsgListImModel *)obj;
- [weakSelf.dataArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- EMConversationModel * model = (EMConversationModel *)obj;
- if (chatModel.ImId == [model.emModel.conversationId integerValue]) {
- EMConversation *conversation = model.emModel;
- if (!chatModel.IsDisturb) {
- chatModel.redNum = model.emModel.unreadMessagesCount;
- }
- chatModel.ChatText = [weakSelf _getDetailWithModel:conversation];
- }
- }];
- }];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- });
- }
- - (NSAttributedString *)_getDetailWithModel:(EMConversation *)aConversation
- {
- NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:@""];
-
- EMMessage *lastMessage = [aConversation latestMessage];
- if (!lastMessage) {
- return attributedStr;
- }
-
- NSString *latestMessageTitle = @"";
- EMMessageBody *messageBody = lastMessage.body;
- switch (messageBody.type) {
- case EMMessageBodyTypeText:
- {
- NSString *str = [EMEmojiHelper convertEmoji:((EMTextMessageBody *)messageBody).text];
- latestMessageTitle = str;
- }
- break;
- case EMMessageBodyTypeImage:
- latestMessageTitle = @"[图片]";
- break;
- case EMMessageBodyTypeVoice:
- latestMessageTitle = @"[音频]";
- break;
- case EMMessageBodyTypeLocation:
- latestMessageTitle = @"[位置]";
- break;
- case EMMessageBodyTypeVideo:
- latestMessageTitle = @"[视频]";
- break;
- case EMMessageBodyTypeFile:
- latestMessageTitle = @"[文件]";
- break;
- default:
- break;
- }
-
- NSDictionary *ext = aConversation.ext;
- if (ext && [ext[kConversation_IsRead] intValue] == kConversation_AtAll) {
- NSString *allMsg = @"[有全体消息]";
- latestMessageTitle = [NSString stringWithFormat:@"%@ %@", allMsg, latestMessageTitle];
- attributedStr = [[NSMutableAttributedString alloc] initWithString:latestMessageTitle];
- [attributedStr setAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:1.0 green:.0 blue:.0 alpha:0.5]} range:NSMakeRange(0, allMsg.length)];
-
- } else if (ext && [ext[kConversation_IsRead] intValue] == kConversation_AtYou) {
- NSString *atStr = @"[有人@我]";
- latestMessageTitle = [NSString stringWithFormat:@"%@ %@", atStr, latestMessageTitle];
- attributedStr = [[NSMutableAttributedString alloc] initWithString:latestMessageTitle];
- [attributedStr setAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:1.0 green:.0 blue:.0 alpha:0.5]} range:NSMakeRange(0, atStr.length)];
- } else {
- attributedStr = [[NSMutableAttributedString alloc] initWithString:latestMessageTitle];
- }
-
- return attributedStr;
- }
- - (BOOL)checkChatListArray
- {
- if (self.chatListIMArray.count == 0) {
- return NO;
- }
- for (ChatMsgListImModel * model in self.chatListIMArray) {
- if (!model.isSelected) {
- return NO;
- }
- }
- return YES;
- }
- - (void)enterChatView:(ChatMsgListImModel *)chatModel
- {
- EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:[NSString stringWithFormat:@"%ld",(long)chatModel.ImId] type: EMConversationTypeChat createIfNotExist:YES];
- EMConversationModel *model = [[EMConversationModel alloc] initWithEMModel:conversation];
- EMChatViewController *controller = [[EMChatViewController alloc] initWithCoversationModel:model];
-
- if (chatModel.ChatType == ChatType_SingleChat) {
- controller.toUserId = chatModel.ToUserId;
- controller.ReceiveIcon = chatModel.AvatarUrl;
- SelectModel * sModel = [[SelectModel alloc] init];
- sModel.UserId = chatModel.ToUserId;
- sModel.UserName = chatModel.Name;
- sModel.AvatarUrl = chatModel.AvatarUrl;
- controller.sModel = sModel;
- }
- model.name = chatModel.Name;
- controller.ImId = chatModel.ImId;
- controller.GroupId = chatModel.Id;
- controller.chatType = chatModel.ChatType;
- controller.listId = chatModel.Id;
- controller.isTop = chatModel.IsTop;
- controller.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:controller animated:YES];
- }
- - (void)getGroupInfo:(ChatMsgListImModel *)chatModel
- {
- self.tableView.allowsSelection = NO;
- WS(weakSelf);
- [[HttpManager sharedHttpManager] POSTUrl:Host(Group_chat_info) parameters:@{@"GroupChatImId":@(chatModel.ImId)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
- weakSelf.tableView.allowsSelection = YES;
- dispatch_async(dispatch_get_main_queue(), ^{
- EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:[NSString stringWithFormat:@"%ld",(long)chatModel.ImId] type: EMConversationTypeGroupChat createIfNotExist:YES];
- EMConversationModel *model = [[EMConversationModel alloc] initWithEMModel:conversation];
- EMChatViewController *controller = [[EMChatViewController alloc] initWithCoversationModel:model];
- controller.toUserId = chatModel.ImId;
- controller.groupUserInfoArray = responseObject[@"Item"];
- model.name = chatModel.Name;
- controller.GroupId = chatModel.Id;
- controller.ImId = chatModel.ImId;
- controller.chatType = chatModel.ChatType;
- controller.isTop = chatModel.IsTop;
- controller.hidesBottomBarWhenPushed = YES;
- [weakSelf.navigationController pushViewController:controller animated:YES];
- });
- } failure:^(NSError * _Nonnull error) {
- weakSelf.tableView.allowsSelection = YES;
- }];
- }
- -(void)isDel:(NSMutableArray *)array
- {
- WS(weakSelf);
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"确认删除?" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- }];
- UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- [weakSelf chatListDelete:array];
- }];
- [alertController addAction:cancel];
- [alertController addAction:ok];
- [self presentViewController:alertController animated:YES completion:nil];
- }
- -(NSMutableArray *)chatListIMArray{
- if(!_chatListIMArray){
- _chatListIMArray = [[NSMutableArray alloc] init];
- }
- return _chatListIMArray;
- }
- -(NSMutableArray *)selectArray{
- if(!_selectArray){
- _selectArray = [[NSMutableArray alloc] init];
- }
- return _selectArray;
- }
- -(NSMutableArray *)dataArray{
- if(!_dataArray){
- _dataArray = [[NSMutableArray alloc] init];
- }
- return _dataArray;
- }
- - (MyTDGroupView *)SearchView
- {
- if (!_SearchView) {
- _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
- }
- return _SearchView;
- }
- - (void)getChatRecord{
-
- }
- #pragma mark - 接收通知跳转到群聊页面
- - (void)pushEMChatViewController:(NSNotification *)notification
- {
- NSDictionary * groupDict = notification.userInfo;
- NSString * groupId = [NSString stringWithFormat:@"%@",[groupDict objectForKey:@"GroupChatImId"]];
- WS(weakSelf);
- [[HttpManager sharedHttpManager] POSTUrl:Host(Group_chat_info) parameters:@{@"GroupChatImId":groupId} responseStyle:JOSN success:^(id _Nonnull responseObject) {
- EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:[NSString stringWithFormat:@"%@",groupId] type: EMConversationTypeGroupChat createIfNotExist:YES];
- EMConversationModel *model = [[EMConversationModel alloc] initWithEMModel:conversation];
- EMChatViewController *controller = [[EMChatViewController alloc] initWithCoversationModel:model];
- controller.toUserId = [[groupDict objectForKey:@"GroupChatImId"] integerValue];
- controller.groupUserInfoArray = responseObject[@"Item"];
- model.name = [groupDict objectForKey:@"Name"];
- controller.GroupId = [[groupDict objectForKey:@"Id"] integerValue];
- controller.chatType = ChatType_GroupChat;
- controller.hidesBottomBarWhenPushed = YES;
- [weakSelf.navigationController pushViewController:controller animated:YES];
- } failure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)pushTDGroupController:(NSNotification *)notification
- {
- MyTDGroupViewController *vc = [[MyTDGroupViewController alloc] init];
- vc.isPush = YES;
- vc.pushDict = notification.userInfo;
- [self.navigationController pushViewController:vc animated:NO];
- }
- - (void)dealloc
- {
- [[EMClient sharedClient].chatManager removeDelegate:self];
- [[EMClient sharedClient].groupManager removeDelegate:self];
- [[EMConversationHelper shared] removeDelegate:self];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- @end
|