// // QXMessageViewController.m // QXLive // // Created by 启星 on 2025/4/24. // #import "QXMessageViewController.h" #import #import #import "TUIConversationListController.h" #import "QXChatViewController.h" #import "QXSystemTopView.h" #import "QXSystemNoticeViewController.h" #import "QXMessageServices.h" #import "AppDelegate.h" @interface QXMessageViewController () @property (nonatomic,strong)QXSystemTopView *topView; @property (nonatomic,strong)QXMessageModel *model; @property (nonatomic,strong)TUIConversationListController *vc; @property (nonatomic,strong)NSString *service_user_id; @property (nonatomic,strong)NSString *service_user_name; @end @implementation QXMessageViewController -(instancetype)initWithIsFromRoom:(BOOL)isFromRoom{ if (self = [super init]) { self.isFromRoom = isFromRoom; if (self.isFromRoom) { self.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(429)); } } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadConversions) name:noticeTencentLogin object:nil]; // [self performSelector:@selector(chat) afterDelay:5]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:YES]; [self getHomeMessage]; } -(void)initSubViews{ if (QXConfig.shared.model) { [self updateBgImage:QXConfig.shared.model.bg_light]; } UILabel *tLabel = [[UILabel alloc] init]; tLabel.text = QXText(@"消息"); tLabel.font = [UIFont boldSystemFontOfSize:20]; [self.view addSubview:tLabel]; [tLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(16); make.top.mas_equalTo(kSafeAreaTop); make.height.mas_equalTo(40); }]; TUIConversationListController *vc = [[TUIConversationListController alloc] init]; vc.delegate = self; // 把 TUIConversationListController 添加到自己的 ViewController // vc.tableViewForAll.backgroundColor = [UIColor clearColor]; self.vc = vc; vc.view.backgroundColor = [UIColor clearColor]; vc.view.frame = CGRectMake(0, NavContentHeight, SCREEN_WIDTH, self.view.height-NavContentHeight); if (self.isFromRoom) { tLabel.font = [UIFont boldSystemFontOfSize:17]; [tLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.view); make.top.equalTo(self.view).offset(10); make.height.mas_equalTo(35); }]; vc.view.frame = CGRectMake(0, 40, SCREEN_WIDTH, self.view.height); }else{ vc.tableViewForAll.tableHeaderView = self.topView; } self.vc = vc; [self addChildViewController:vc]; [self.view addSubview:vc.view]; } -(void)reloadConversions{ // [self.vc.view removeFromSuperview]; // [self.vc removeFromParentViewController]; // self.vc = nil; // self.vc = [[TUIConversationListController alloc] init]; // self.vc.view.frame = CGRectMake(0, NavContentHeight, SCREEN_WIDTH, self.view.height-NavContentHeight); // self.vc.tableViewForAll.tableHeaderView = self.topView; // [self addChildViewController:self.vc]; // [self.view addSubview:self.vc.view]; [self.vc reloadConversationList]; self.vc.tableViewForAll.tableHeaderView = self.topView; } - (void)conversationListController:(UIViewController *)conversationController didSelectConversation:(TUIConversationCellData *)conversation { // 会话列表点击事件,通常是打开聊天界面 // if (conversation.groupID.length > 0) { // // }else{ QXChatViewController *vc = [[QXChatViewController alloc] init]; TUIChatConversationModel *data = [[TUIChatConversationModel alloc] init]; data.conversationID = conversation.conversationID; data.userID = conversation.userID; data.groupID = conversation.groupID; data.title = conversation.title; data.faceUrl = conversation.faceUrl; if ([conversation.userID isEqualToString:[NSString stringWithFormat:@"u%@",self.service_user_id]]) { vc.isServices = YES; }else{ vc.isServices = NO; } vc.data = data; [self.vc.dataProvider markConversationAsRead:conversation]; [self.navigationController pushViewController:vc animated:YES]; // } } //-(void)viewDidLayoutSubviews{ // [super viewDidLayoutSubviews]; // self.vc.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(429)); //} -(void)getHomeMessage{ MJWeakSelf [QXMessageServices getHomeMessageSuccessBlock:^(QXMessageModel * _Nonnull model) { weakSelf.model = model; weakSelf.topView.model = model; AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate; delegate.tabbarVC.systemUnreadNumber = model.system_no_read_count.integerValue + model.announcement_read_count.integerValue; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; [QXMessageServices getSerbviceUserSuccessBlock:^(NSString * _Nonnull user_id, NSString * _Nonnull user_name) { weakSelf.service_user_id = user_id; weakSelf.service_user_name = user_name; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } //-(void)chat{ // TUIChatConversationModel *data = [[TUIChatConversationModel alloc] init]; // data.userID = @"10086"; // QXChatViewController *vc = [[QXChatViewController alloc] init]; // vc.data = data; // [self.navigationController pushViewController:vc animated:YES]; //} -(void)didClickNoticeWithType:(NSInteger)type{ QXSystemNoticeViewController *vc = [[QXSystemNoticeViewController alloc] init]; vc.type = type; [self.navigationController pushViewController:vc animated:YES]; } -(QXSystemTopView *)topView{ if (!_topView) { _topView = [[QXSystemTopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 74*2+8)]; _topView.delegate = self; } return _topView; } @end