You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
375 lines
14 KiB
375 lines
14 KiB
// |
|
// HomeMessageViewController.m |
|
// tongxin |
|
// |
|
// Created by ecell on 2023/4/24. |
|
// Copyright © 2023 xTT. All rights reserved. |
|
// |
|
|
|
#import "HomeMessageViewController.h" |
|
#import "MyTabBarViewController.h" |
|
#import "HomeMsgHeaderView.h" |
|
#import "HomeMsgTableViewCell.h" |
|
#import "CommonTableView.h" |
|
#import "MessageViewController.h" |
|
#import "MyMQTT.h" |
|
#import "JCManager.h" |
|
#import "BRManager.h" |
|
#import "TihuManager.h" |
|
#import "NoWatchView.h" |
|
#import "ChatViewController.h" |
|
#import "HomeChatListModel.h" |
|
|
|
@interface HomeMessageViewController () |
|
|
|
@property (nonatomic ,strong) HomeMsgHeaderView *headerView; |
|
@property (nonatomic ,strong) CommonTableView *homeTable; |
|
@property (nonatomic ,strong) NoWatchView *noView; |
|
|
|
@end |
|
|
|
@implementation HomeMessageViewController |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
// Do any additional setup after loading the view. |
|
self.zx_navBarBackgroundColor = KKClearColor; |
|
self.zx_navTitle = @"首页"; |
|
//清除预加载的图片 |
|
MyTabBarViewController *mytabVC = (MyTabBarViewController*)self.tabBarController; |
|
[mytabVC removeTransitionImageView]; |
|
self.view.backgroundColor = KKBackgroundGrey; |
|
|
|
UIColor *color = [UIColor blackColor]; |
|
NSDictionary *dict = [NSDictionary dictionaryWithObject:color forKey:UITextAttributeTextColor]; |
|
self.navigationController.navigationBar.titleTextAttributes = dict; |
|
|
|
UIImageView *topImg = [[UIImageView alloc] init]; |
|
topImg.image = ImageName_(@"comm_bg_img_"); |
|
[self.view addSubview:topImg]; |
|
[topImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.top.equalTo(self.view); |
|
make.left.right.equalTo(self.view); |
|
make.height.mas_equalTo(Adapted(topImg.image.size.height)); |
|
}]; |
|
|
|
[self.view addSubview:self.homeTable]; |
|
[self.homeTable mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.top.equalTo(self.view).offset(iPhoneX_NavHeight); |
|
make.left.right.equalTo(self.view).inset(15); |
|
make.bottom.equalTo(self.view.mas_bottom); |
|
}]; |
|
self.noView = [[NoWatchView alloc] init]; |
|
self.noView.hidden = YES; |
|
[self.view addSubview:self.noView]; |
|
|
|
WEAKSELF |
|
[[NSNotificationCenter defaultCenter] addObserverForName:@"device_add" |
|
object:nil |
|
queue:[NSOperationQueue mainQueue] |
|
usingBlock:^(NSNotification * _Nonnull note) |
|
{ |
|
NSLog(@"===添加设备成功通知==="); |
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
|
if (cUser.myDevices && cUser.myDevices.count ==0) { |
|
[weakSelf viewWillAppear:YES]; |
|
} |
|
|
|
}); |
|
|
|
}]; |
|
|
|
} |
|
|
|
- (CommonTableView *)homeTable |
|
{ |
|
if (!_homeTable) |
|
{ |
|
_homeTable = [[CommonTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain cellHeight:87 cellRow:0 isAdaptive:NO isLine:YES commonCell:HomeMsgTableViewCell.class createCell:^(ZZTableViewCell * _Nonnull cells, NSIndexPath * _Nonnull indexPath) { |
|
|
|
HomeMsgTableViewCell *cell = (HomeMsgTableViewCell *)cells; |
|
[UICommon tableView:self->_homeTable willDisplayCell:cell forRowAtIndexPath:indexPath cellCoutn:self.myDataSource.count sizeH:0]; |
|
cell.listModel = self.myDataSource[indexPath.row]; |
|
// if (indexPath.row == 0) |
|
// [UICommon setExtraCellLineHidden:cell]; |
|
|
|
|
|
} selectedCell:^(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) { |
|
|
|
HomeChatListModel *model = self.myDataSource[indexPath.row]; |
|
|
|
ChatViewController *vc = [[ChatViewController alloc] init]; |
|
vc.zx_navTitle = model.groupid ? @"家庭群聊" : model.name; |
|
vc.chatType = model.groupid ? 222: 111; |
|
if (model.groupid) |
|
{ |
|
Circle *infoCircle = [[Circle alloc] init]; |
|
infoCircle.groupid = model.groupid; |
|
infoCircle.creator = model.creator; |
|
infoCircle.members = model.members; |
|
infoCircle.devices = model.devices; |
|
infoCircle.msgNum = model.msgNum; |
|
vc.infoCircle = infoCircle; |
|
} |
|
else |
|
{ |
|
Circle *infoCircle = [[Circle alloc] init]; |
|
vc.imei = model.imei; |
|
vc.infoCircle = infoCircle; |
|
} |
|
[self.navigationController pushViewController:vc animated:YES]; |
|
|
|
} DidscrollView:^(UIScrollView * _Nonnull scrollView) { |
|
|
|
}]; |
|
_homeTable.tableHeaderView = self.headerView; |
|
_homeTable.tableHeaderView.height = 118; |
|
_homeTable.backgroundColor = KKClearColor; |
|
[UICommon setTavleViewlink:_homeTable distance:30]; |
|
|
|
|
|
|
|
} |
|
return _homeTable; |
|
} |
|
|
|
- (HomeMsgHeaderView *)headerView |
|
{ |
|
WEAKSELF |
|
if (!_headerView) |
|
{ |
|
_headerView = [[HomeMsgHeaderView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth-30, 118)]; |
|
UIButton *btn = [UICommon ui_buttonSimple:_headerView.frame font:Font_(0) normalColor:KKClearColor normalText:@"" click:^(id x) { |
|
|
|
MessageViewController *vc = [[MessageViewController alloc] init]; |
|
vc.hidesBottomBarWhenPushed = YES; |
|
vc.title = @"消息中心"; |
|
[weakSelf.navigationController pushViewController:vc animated:YES]; |
|
}]; |
|
[_headerView addSubview:btn]; |
|
} |
|
return _headerView; |
|
} |
|
- (void)viewWillDisappear:(BOOL)animated |
|
{ |
|
[super viewWillDisappear:animated]; |
|
|
|
} |
|
|
|
-(void)viewWillAppear:(BOOL)animated |
|
{ |
|
[super viewWillAppear:animated]; |
|
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; |
|
|
|
NSLog(@"======HomeVC viewWillAppear=========="); |
|
|
|
WEAKSELF |
|
|
|
//刷新 关联数据 |
|
if(!cUser){ |
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"outLogin" |
|
object:nil]; |
|
return; |
|
} |
|
|
|
// 查找默认imei add by lsz 2020-12-28 |
|
Device *defaultDev = nil; |
|
NSString *defaultImei = [User getDefaultImei]; |
|
if (defaultImei && cUser.myDevices) { |
|
for (Device *dev in cUser.myDevices) { |
|
if ([defaultImei isEqualToString:dev.imei]) { |
|
defaultDev = dev; |
|
break; |
|
} |
|
} |
|
} |
|
|
|
if (defaultDev) { |
|
cUser.cDevice = defaultDev; |
|
NSLog(@"===default:%@",defaultImei); |
|
} else if (![cUser.myDevices containsObject:cUser.cDevice] && cUser.myDevices.count > 0) { |
|
cUser.cDevice = [cUser.myDevices firstObject]; |
|
} |
|
|
|
[cUser getRelatedDeviceSuccess:^(id responseObject) { |
|
[cUser getUserInfoSuccess:^(id responseObject) { |
|
[self updataViews]; |
|
BOOL haveJuphoonDevice = NO; |
|
for (Device* item in cUser.myDevices) { |
|
if (item.support_video.integerValue == 4) { |
|
haveJuphoonDevice = YES; |
|
} |
|
} |
|
|
|
if(haveJuphoonDevice){ |
|
//MARK:拥有菊风的设备,需要登录 账号 (调试时期暂时停止) |
|
// if(![JCManager shared].client) |
|
// { |
|
// [[JCManager shared] initializeWithAPPKey:cUser.juphoonKey]; |
|
// [[JCManager shared].client setConfig:JCClientConfigServer value:@"http:cn.router.justalkcloud.com:8080"]; |
|
// [[JCManager shared].client setServerAddress:@"http:cn.router.justalkcloud.com:8080"]; |
|
// [[JCManager shared].client login:cUser.openid password:@"test" loginParam:nil];//免鉴权密码随意但是不能为空 |
|
// [JCManager shared].gMianVC = self; |
|
// xLog(@"菊风账号是:%@", cUser.openid); |
|
// } |
|
if(![JCManager shared].client) |
|
{ |
|
[[JCManager shared] initializeWithAPPKey:cUser.juphoonKey]; |
|
JCClientLoginParam* loginParam = [[JCClientLoginParam alloc] init]; |
|
loginParam.directConnectEnable = YES; |
|
[[JCManager shared].client setServerAddress:@"http:cn.router.justalkcloud.com:8080"]; |
|
[[JCManager shared].client login:cUser.openid password:@"test" loginParam:loginParam]; |
|
[[JCManager shared].mediaDevice enableSpeaker:YES]; |
|
[JCManager shared].gMianVC = self; |
|
} |
|
} |
|
|
|
BOOL haveBairuiDevice = NO; |
|
for (Device* item in cUser.myDevices) { |
|
if (item.support_video.integerValue == 5) { |
|
haveBairuiDevice = YES; |
|
} |
|
} |
|
|
|
if(haveBairuiDevice){ |
|
//MARK:拥有佰锐的设备,需要登录 账号 |
|
if (![[BRManager shared] isUserLogin]) { |
|
[[BRManager shared] initialize]; |
|
[BRManager shared].gMianVC = self; |
|
[[BRManager shared] login:cUser.bairui_id nick:cUser.name]; |
|
} else { |
|
xLog(@"====================>佰锐视频账号已经登录"); |
|
} |
|
xLog(@"佰锐账号是:%d", [cUser.bairui_id intValue]); |
|
} |
|
|
|
|
|
BOOL haveTihuDevice = NO; |
|
for (Device* item in cUser.myDevices) { |
|
if (item.support_video.integerValue == 6) { |
|
haveTihuDevice = YES; |
|
} |
|
} |
|
|
|
if(haveTihuDevice){ |
|
//MARK:拥有鹈鹕的设备,需要登录账号 |
|
if (![[TihuManager shared] isUserLogin]) { |
|
[[TihuManager shared] initialize]; |
|
[TihuManager shared].gMianVC = self; |
|
[[TihuManager shared] login:cUser.openid pwd:@"123456"]; |
|
|
|
xLog(@"鹈鹕账号是:%@", cUser.openid); |
|
} else { |
|
xLog(@"====>鹈鹕视频账号已经登录"); |
|
} |
|
} |
|
|
|
//MARK:拥有声网的设备,需要调用查询接口,判断是否有用户在正在通话中的 |
|
for (Device *item in cUser.myDevices) { |
|
if (item.support_video.integerValue == 1) |
|
{ |
|
[cUser getVideoInfoWithDeviceImei:item.imei CallType:0 Success:^(NSDictionary *responseObject) { |
|
if ([responseObject valueForKey:@"video_id"]){ |
|
NSLog(@"===%@",responseObject); |
|
[weakSelf showCallViewWithDic:responseObject]; |
|
|
|
// [[NSNotificationCenter defaultCenter] postNotificationName:@"VideoCall" object:responseObject userInfo:responseObject]; |
|
} |
|
} failure:^{ |
|
|
|
}]; |
|
} |
|
} |
|
|
|
|
|
} failure:nil]; |
|
|
|
if (cUser.myDevices.count > 0) |
|
{ |
|
[cUser getRelatedChatGroupSuccess:^(id responseObject) { |
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // TODO 0.5-->0.1 |
|
|
|
}); |
|
} failure:nil]; |
|
|
|
} |
|
else |
|
{ |
|
|
|
} |
|
|
|
// MARK 切换到同意的绑定设备 ===================================== add by lsz 2021-6-22 |
|
NSString *agreeImei = [User agreeImei]; |
|
Device *agreeDevice; |
|
if (agreeImei && cUser.myDevices) { |
|
for (Device *dev in cUser.myDevices) { |
|
if ([agreeImei isEqualToString:dev.imei]) { |
|
agreeDevice = dev; |
|
break; |
|
} |
|
} |
|
} |
|
|
|
} failure:nil]; |
|
|
|
// [self updataViews]; |
|
} |
|
|
|
|
|
- (void)updataViews |
|
{ |
|
self.homeTable.hidden = cUser.myDevices.count > 0 ? NO : YES; |
|
self.noView.hidden = cUser.myDevices.count > 0 ? YES : NO; |
|
[self getModelList]; |
|
[self getNotification]; |
|
} |
|
|
|
/// 获取用户所有单聊和群聊信息 |
|
- (void)getModelList |
|
{ |
|
WEAKSELF |
|
[cUser.cDevice GetChatGroupsWithSuccess:^(id responseObject) { |
|
weakSelf.myDataSource = [NSMutableArray new]; |
|
NSArray *groupArr = responseObject[@"groupDataList"]; |
|
NSArray *singleArr = responseObject[@"singleDataList"]; |
|
for (NSDictionary *dic in singleArr) |
|
{ |
|
HomeChatListModel *model = [HomeChatListModel yy_modelWithJSON:dic]; |
|
[weakSelf.myDataSource addObject:model]; |
|
} |
|
for (NSDictionary *dic in groupArr) |
|
{ |
|
HomeChatListModel *model = [HomeChatListModel yy_modelWithJSON:dic]; |
|
[weakSelf.myDataSource addObject:model]; |
|
} |
|
weakSelf.homeTable.cellRow = weakSelf.myDataSource.count; |
|
[weakSelf.homeTable reloadData]; |
|
|
|
} failure:^(NSError *error) { |
|
|
|
}]; |
|
} |
|
|
|
/// 获取未读消息(最后一条) |
|
- (void)getNotification |
|
{ |
|
WEAKSELF |
|
[cUser GetNotificationCountWithSuccess:^(id responseObject) { |
|
weakSelf.headerView.modelDic = responseObject; |
|
[weakSelf.homeTable reloadData]; |
|
} failure:^(NSError *error) { |
|
|
|
}]; |
|
} |
|
|
|
/* |
|
#pragma mark - Navigation |
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation |
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { |
|
// Get the new view controller using [segue destinationViewController]. |
|
// Pass the selected object to the new view controller. |
|
} |
|
*/ |
|
|
|
@end
|
|
|