// // 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" @interface QXMessageViewController () @property (nonatomic,strong)QXSystemTopView *topView; @property (nonatomic,strong)QXMessageModel *model; @property (nonatomic,strong)TUIConversationListController *vc; @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{ 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]; } - (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; vc.data = data; [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; } 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