MOChatViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. //
  2. // MOChatViewController.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/11/5.
  6. //
  7. #import "MOChatViewController.h"
  8. #import "MOWebViewController.h"
  9. #import "MOUserHomePageVC.h"
  10. #import "MODiaWinRoundDetailView.h"
  11. #import "MOUserSetDataModels.h"
  12. #import "MOChatLimitView.h"
  13. #import "MOChatSendLimitView.h"
  14. #import "MOReportSomeOneView.h"//举报他人View
  15. #import "MOChatFollowView.h"//关注View
  16. #import "MOChatTitleView.h"//顶部标题View
  17. #import "TUIChatConfig.h"
  18. #import "TUIChatConfig_Classic.h"
  19. #import "MOChatViewController+MoreMenu.h"
  20. @interface MOChatViewController ()<TUIChatEventListener,TUIBaseChatViewControllerDelegate_Two>
  21. @property (nonatomic, strong) UILabel *titleLab;//废弃
  22. @property (nonatomic, strong) UIButton *blackBtn;
  23. @property (nonatomic, strong) MOUserSetBaseData *userSetData;
  24. @property (nonatomic, strong) UIImageView *bgImgView;
  25. @property (nonatomic, assign) BOOL isGetUserBase;//是否获取用户信息(接口返回成功为止)
  26. @property (nonatomic, strong) MOReportSomeOneView *reportView;//举报他人View
  27. @property (nonatomic, assign) BOOL isShowReport;
  28. @property (nonatomic, strong) MOChatFollowView *followView;//关注View
  29. @property (nonatomic, assign) BOOL reportPrivateChat;//是否向服务器请求私聊成功的接口(防止重复调接口)
  30. @property (nonatomic, strong) MOChatTitleView *titleView;//标题
  31. @end
  32. @implementation MOChatViewController
  33. - (void)viewWillAppear:(BOOL)animated{
  34. [super viewWillAppear:animated];
  35. [[IQKeyboardManager sharedManager] setEnable:NO];
  36. if(self.isLiveRoom){
  37. // [self.navigationController setNavigationBarHidden:YES animated:animated];
  38. [self.navigationController setNavigationBarHidden:NO animated:animated];
  39. [self mo_v2_setNavLeftItemWithImage:[UIImage imageNamed:@"v_2_icon_new_back_black"] andBackgroundImg:nil AndBgColor:nil];
  40. }
  41. else if (self.isHalfShow){
  42. [self.navigationController setNavigationBarHidden:YES animated:animated];
  43. }
  44. else
  45. {
  46. [self.navigationController setNavigationBarHidden:NO animated:animated];
  47. [self mo_v2_setNavLeftItemWithImage:[UIImage imageNamed:@"v_2_icon_new_back_black"] andBackgroundImg:nil AndBgColor:nil];
  48. }
  49. [[MOChatNotificationManager sharedManager] enterScene:MOChatNotificationSceneChatDetail];//进入聊天详情
  50. }
  51. - (void)viewDidLoad {
  52. [super viewDidLoad];
  53. // Do any additional setup after loading the view.
  54. [self setupUI];
  55. [self toGetUserSetData];
  56. [self addNotification];
  57. [MOChatHttpManage shareManager].userId = self.otherUserId;
  58. [MOChatHttpManage shareManager].isFirstHttp = YES;
  59. NSString *theUserId = self.otherUserId;
  60. //腾讯
  61. self.t_chatController.externalRequestBlock = ^(void (^ _Nonnull httpBlock)(BOOL)) {
  62. [[MOChatHttpManage shareManager] toSendSingleChatAndBlock:^(BOOL result) {
  63. // 回调完成,返回数据给库内部
  64. dispatch_async(dispatch_get_main_queue(), ^{
  65. httpBlock(result);
  66. });
  67. }];
  68. };
  69. theUserId = self.t_conversationData.userID;
  70. [self getUserInfoWith:theUserId];//获取用户信息
  71. }
  72. - (void)addNotification{
  73. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHideOrShow:) name:UIKeyboardWillShowNotification object:nil];
  74. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHideOrShow:) name:UIKeyboardWillHideNotification object:nil];
  75. ReceiveNotification(@selector(toUpdataViewWithSendStatus:), @"MOCanOrNotSendMessage")//离开频道的通知
  76. ReceiveNotification(@selector(jumpLink:), @"MOChatJumpLink")//点击链接跳转
  77. ReceiveNotification(@selector(reportNewUserChat), @"kNotification_SendMessage")//新用户发送消息通知服务端
  78. }
  79. - (void)jumpLink:(NSNotification *)notification {
  80. NSString *link = notification.object;
  81. [self toShowUrlViewWith:link];
  82. }
  83. - (void)toUpdataViewWithSendStatus:(NSNotification *)notification{
  84. BOOL canSend = [notification.object boolValue];
  85. self.userSetData.canSend = canSend;
  86. [self updataTheSendStatus];
  87. }
  88. - (void)reportNewUserChat {
  89. MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
  90. NSTimeInterval timestamp = userInfoData.createAt / 1000.0;
  91. NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp];
  92. NSCalendar *calendar = [NSCalendar currentCalendar];
  93. BOOL isToday = [calendar isDateInToday:date];
  94. if (!isToday) {//不是注册首日就不需要请求服务器了
  95. return;
  96. }
  97. if (self.reportPrivateChat) {
  98. return;
  99. }
  100. NSDictionary *dict = @{@"id":self.otherUserId};
  101. WEAKSELF
  102. [kHttpManager reportPrivateChatWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  103. if(kCode_Success) {
  104. weakSelf.reportPrivateChat = YES;
  105. }
  106. }];
  107. }
  108. - (void)keyboardHideOrShow:(NSNotification *)notification{
  109. WEAKSELF
  110. CGFloat bottomStatusHeight = HOME_KEY_HEIGHT + 42.0;
  111. CGFloat bottomSpacing = -bottomStatusHeight - 10.0;
  112. NSString *notificationName = notification.name;
  113. if ([notificationName isEqualToString:UIKeyboardWillShowNotification] == YES) {
  114. //展示
  115. CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  116. bottomSpacing = bottomSpacing - keyboardFrame.size.height;
  117. [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:1 initialSpringVelocity:1 options:UIViewAnimationOptionCurveLinear animations:^
  118. {
  119. if(weakSelf.isShowReport){
  120. [weakSelf.reportView mas_updateConstraints:^(MASConstraintMaker *make)
  121. {
  122. make.bottom.equalTo(self.view).offset(-keyboardFrame.size.height);
  123. }];
  124. }
  125. [weakSelf.view layoutIfNeeded];
  126. } completion:^(BOOL finished)
  127. {
  128. }];
  129. }
  130. else{
  131. //隐藏
  132. [UIView animateWithDuration:0.2 animations:^
  133. {
  134. if(weakSelf.isShowReport){
  135. [weakSelf.reportView mas_updateConstraints:^(MASConstraintMaker *make)
  136. {
  137. make.bottom.equalTo(self.view).offset(0);
  138. }];
  139. }
  140. [weakSelf.view layoutIfNeeded];
  141. }];
  142. }
  143. }
  144. - (void)toGetUserSetData{
  145. WEAKSELF
  146. if(self.otherUserId.length == 0){
  147. return;
  148. }
  149. self.userData = [MODataManager searchMOUserBaseWith:self.otherUserId];
  150. [self updateViewUI];
  151. NSDictionary *dict = @{@"id":self.otherUserId};
  152. [kHttpManager toGetChatSingleInfoWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  153. if(kCode_Success){
  154. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  155. weakSelf.userSetData = [MOUserSetBaseData modelObjectWithDictionary:data[@"data"]];
  156. weakSelf.userData.blacklist = weakSelf.userSetData.userSetData.result;
  157. [weakSelf updateViewUI];
  158. [weakSelf updataTheSendStatus];
  159. }
  160. else{
  161. MOLogV(@"toGetChatSingleInfoWithParams 接口报错了");
  162. // kShowNetError(data)
  163. }
  164. }];
  165. }
  166. - (void)updateViewUI{
  167. WEAKSELF
  168. dispatch_async(dispatch_get_main_queue(), ^{
  169. if(weakSelf.userData.blacklist){
  170. weakSelf.blackBtn.hidden = NO;
  171. }
  172. else{
  173. weakSelf.blackBtn.hidden = YES;
  174. }
  175. });
  176. }
  177. - (void)updataTheSendStatus{
  178. WEAKSELF
  179. dispatch_async(dispatch_get_main_queue(), ^{
  180. [MOChatHttpManage shareManager].canSend = weakSelf.userSetData.canSend;
  181. //腾讯
  182. weakSelf.t_chatController.direction = weakSelf.userSetData.userSetData.direction;
  183. weakSelf.t_chatController.isBlackUser = weakSelf.userData.blacklist;
  184. weakSelf.t_chatController.canSend = !weakSelf.userData.blacklist;
  185. });
  186. }
  187. - (void)setupUI{
  188. self.titleView = [[MOChatTitleView alloc] initWithFrame:CGRectMake(0.0, 0.0, (SCREENWIDTH - 60.0 * 2.0), 44.0)];
  189. self.titleView.viewType = MOChatTitleViewNormalType;
  190. [self.titleView sizeToFit];
  191. self.navigationItem.titleView = self.titleView;
  192. [self setupTencentUI];
  193. }
  194. - (void)setupTencentUI {
  195. self.otherUserId = _t_conversationData.userID;
  196. //样式设置
  197. [TUIChatConfig defaultConfig].backgroudColor = [UIColor clearColor];
  198. [TUIChatConfig defaultConfig].enableWelcomeCustomMessage = NO;
  199. [TUIChatConfig defaultConfig].showFileButton = NO;//隐藏文件按钮
  200. //功能设置 - 先默认全屏蔽, 然后根据接口进行相应的调整
  201. [TUIChatConfig_Classic hideItemsWhenLongPressMessage:TUIChatItemWhenLongPressMessage_Classic_Forward |
  202. TUIChatItemWhenLongPressMessage_Classic_Select | TUIChatItemWhenLongPressMessage_Classic_Quote | TUIChatItemWhenLongPressMessage_Classic_Reply];
  203. WEAKSELF
  204. self.t_chatController = [[TUIC2CChatViewController alloc] init];
  205. self.t_chatController.delegate_Two = self;
  206. [self.t_chatController setConversationData:self.t_conversationData];
  207. self.t_chatController.theTypingBlock = ^(BOOL isTyping) {
  208. if(isTyping){
  209. weakSelf.titleView.viewType = MOChatTitleViewEntering;
  210. }
  211. else{
  212. [weakSelf toShowNavigationItemTitle];
  213. }
  214. };
  215. [self addChildViewController:self.t_chatController];
  216. if(self.isHalfShow){
  217. self.view.backgroundColor = [UIColor clearColor];
  218. UIView *bgView = [[UIView alloc] init];
  219. bgView.layer.cornerRadius = 16.0;
  220. bgView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
  221. bgView.layer.masksToBounds = YES;
  222. bgView.backgroundColor = [UIColor whiteColor];
  223. [self.view addSubview:bgView];
  224. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  225. make.bottom.equalTo(self.view);
  226. make.left.right.equalTo(self.view);
  227. make.height.equalTo(@553.0);
  228. }];
  229. [bgView addSubview:self.bgImgView];
  230. [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  231. make.edges.equalTo(bgView);
  232. }];
  233. NSArray *colorArr = @[[MOTools colorWithHexString:@"#F3F4FA" alpha:1.0],[MOTools colorWithHexString:@"#F3F4FA" alpha:1.0]];
  234. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, 553.0) Colors:colorArr GradientType:1];
  235. [self.bgImgView setImage:image];
  236. [bgView addSubview:self.titleLab];
  237. [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  238. make.height.equalTo(@30.0);
  239. make.left.right.top.equalTo(bgView);
  240. }];
  241. [bgView addSubview:self.t_chatController.view];
  242. if([self.t_conversationData.userID isEqualToString:OfficialID] || [self.t_conversationData.userID isEqualToString:ActivityID]){
  243. CGFloat bottomStatusHeight = HOME_KEY_HEIGHT + 52.0;
  244. [self.t_chatController.view mas_makeConstraints:^(MASConstraintMaker *make) {
  245. make.leading.trailing.equalTo(bgView);
  246. make.top.equalTo(self.titleLab.mas_bottom);
  247. make.bottom.equalTo(bgView).offset(bottomStatusHeight);
  248. }];
  249. }
  250. else{
  251. [self.t_chatController.view mas_makeConstraints:^(MASConstraintMaker *make) {
  252. make.leading.trailing.bottom.equalTo(bgView);
  253. make.top.equalTo(self.titleLab.mas_bottom);
  254. }];
  255. }
  256. self.titleLab.text = @"Chat";
  257. }
  258. else{
  259. self.titleView.title = @"Chat";
  260. [self.view addSubview:self.bgImgView];
  261. [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  262. make.edges.equalTo(self.view);
  263. }];
  264. NSArray *colorArr = @[[MOTools colorWithHexString:@"#F3F4FA" alpha:1.0],[MOTools colorWithHexString:@"#F3F4FA" alpha:1.0]];
  265. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, (SCREENHEIGHT - NAV_BAR_HEIGHT)) Colors:colorArr GradientType:1];
  266. [self.bgImgView setImage:image];
  267. [self.view addSubview:self.t_chatController.view];
  268. if([self.t_conversationData.userID isEqualToString:OfficialID] || [self.t_conversationData.userID isEqualToString:ActivityID]){
  269. CGFloat bottomStatusHeight = HOME_KEY_HEIGHT + 52.0;
  270. [self.t_chatController.view mas_makeConstraints:^(MASConstraintMaker *make) {
  271. make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(0);
  272. make.leading.trailing.equalTo(self.view);
  273. make.bottom.equalTo(self.view).offset(bottomStatusHeight);
  274. }];
  275. }
  276. else{
  277. [self.t_chatController.view mas_makeConstraints:^(MASConstraintMaker *make) {
  278. make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(0);
  279. make.leading.trailing.bottom.equalTo(self.view);
  280. }];
  281. }
  282. CGFloat followViewHeight = 40.0 + 10.0 * 2.0;
  283. [self.view addSubview:self.followView];
  284. [self.followView mas_makeConstraints:^(MASConstraintMaker *make) {
  285. make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
  286. make.height.equalTo(@(followViewHeight));
  287. make.left.right.equalTo(self.view);
  288. }];
  289. self.followView.hidden = YES;
  290. }
  291. self.t_chatController.view.backgroundColor = [UIColor clearColor];
  292. if([self.t_conversationData.userID isEqualToString:OfficialID] || [self.t_conversationData.userID isEqualToString:ActivityID]){
  293. //系统消息 不处理
  294. }
  295. else{
  296. CGFloat bottomStatusHeight = HOME_KEY_HEIGHT + 52.0;
  297. [self.view addSubview:self.blackBtn];
  298. [self.blackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  299. make.left.bottom.right.equalTo(self.view);
  300. make.height.equalTo(@(bottomStatusHeight));
  301. }];
  302. self.blackBtn.hidden = YES;
  303. CGFloat bottomSpacing = -bottomStatusHeight - 10.0;
  304. CGFloat rightSpacing = 16.0 + 30.0 + 6.0 + 30.0 + 10.0;
  305. CGFloat leftSpacing = 16.0;
  306. CGFloat viewHeight = 52 - 2 * 6.5;
  307. }
  308. if([self.t_conversationData.userID isEqualToString:OfficialID] || [self.t_conversationData.userID isEqualToString:ActivityID]){
  309. if(self.isHalfShow){
  310. if([self.t_conversationData.userID isEqualToString:OfficialID] ){
  311. self.titleLab.text = @"Official News";
  312. }
  313. else{
  314. self.titleLab.text = @"Activity Notice";
  315. }
  316. }
  317. else{
  318. if([self.t_conversationData.userID isEqualToString:OfficialID] ){
  319. self.titleView.title = @"Official News";
  320. }
  321. else{
  322. self.titleView.title = @"Activity Notice";
  323. }
  324. }
  325. }
  326. else{
  327. [self toShowNavigationItemTitle];
  328. }
  329. TUIChatEventConfig *chatEvent = [[TUIChatEventConfig alloc] init];
  330. chatEvent.chatEventListener = self;
  331. [[TUIChatConfig defaultConfig] setEventConfig:chatEvent];
  332. }
  333. - (void)toShowNavigationItemTitle{
  334. NSString *nickName = self.nickNameStr;
  335. if(self.userData.userProfile.nickname.length > 0){
  336. nickName = self.userData.userProfile.nickname;
  337. if(self.userData.remark.length > 0){
  338. nickName = self.userData.remark;
  339. }
  340. }
  341. if(self.isHalfShow){
  342. self.titleLab.text = nickName;
  343. }
  344. else{
  345. self.titleView.title = nickName;
  346. self.titleView.viewType = MOChatTitleViewNormalType;
  347. }
  348. }
  349. - (void)toUpdataTheFollowStatus{
  350. //没关注
  351. if(!(self.isHalfShow || self.isLiveRoom)){
  352. //全屏
  353. if([self.t_conversationData.userID isEqualToString:OfficialID] || [self.t_conversationData.userID isEqualToString:ActivityID]){
  354. }
  355. else{
  356. if(!self.userData.follow){
  357. self.followView.hidden = NO;
  358. }
  359. else{
  360. self.followView.hidden = YES;
  361. }
  362. }
  363. }
  364. }
  365. //MARK: 用户数据
  366. - (void)toShowUrlViewWith:(NSString *)url{
  367. if(url.length == 0){
  368. return;
  369. }
  370. BOOL isURL = [url hasPrefix:@"http://"] || [url hasPrefix:@"https://"];
  371. if(isURL){
  372. BOOL isShowTitle = YES;
  373. if([url containsString:@"FullScreen=1"]){
  374. isShowTitle = NO;
  375. }
  376. MOWebViewController *vc = [[MOWebViewController alloc] init];
  377. vc.isShowTitle = isShowTitle;
  378. NSString *urlStr = url;
  379. vc.webUrl = [NSURL URLWithString:urlStr];
  380. [self.navigationController pushViewController:vc animated:YES];
  381. }
  382. else{
  383. if([url containsString:@"diamondWinnerDetail?id="]){
  384. [self toShowDiamondWinnerDetailWith:url];
  385. return;
  386. }
  387. if([url containsString:@"mimo://"]){
  388. NSURL *urlUrl = [NSURL URLWithString:url];
  389. if ([[UIApplication sharedApplication]respondsToSelector:@selector(openURL:options:completionHandler:)])
  390. {
  391. [[UIApplication sharedApplication] openURL:urlUrl options:@{UIApplicationOpenURLOptionUniversalLinksOnly:@NO} completionHandler:^(BOOL success) {}];
  392. }
  393. }
  394. }
  395. }
  396. - (void)toShowDiamondWinnerDetailWith:(NSString *)url{
  397. NSArray *tempArr = [url componentsSeparatedByString:@"diamondWinnerDetail?id="];
  398. NSString *idStr = tempArr.lastObject;
  399. MODiaWinRoundDetailView *view = [MODiaWinRoundDetailView moDiaWinRoundDetailView];
  400. view.orderId = idStr;
  401. [self.view addSubview:view];
  402. [view showDiaWinRoundDetailView];
  403. [view getTheDetailData];
  404. }
  405. //MARK: 用户头像点击
  406. #pragma mark - 腾讯IM TUIChatEventListener
  407. - (BOOL)onUserIconClicked:(UIView *)view messageCellData:(TUIMessageCellData *)celldata{
  408. NSString *theUserId = celldata.innerMessage.sender;
  409. if([theUserId isEqualToString:OfficialID] || [theUserId isEqualToString:ActivityID]){
  410. return YES;
  411. }
  412. else{
  413. [self toPushUserHomePageWith:theUserId];
  414. }
  415. return YES;
  416. }
  417. - (void)toPushUserHomePageWith:(NSString *)userId{
  418. if([userId isEqualToString:OfficialID] || [userId isEqualToString:ActivityID]){
  419. return;
  420. }
  421. //收起键盘
  422. [self.t_chatController.inputController reset];
  423. WEAKSELF
  424. MOUserHomePageVC *vc = [[MOUserHomePageVC alloc] init];
  425. vc.userId = userId;
  426. vc.isLiveRoom = weakSelf.isLiveRoom;
  427. vc.goLivingRoomBlock = ^(NSString * _Nonnull liveRoomId) {
  428. if(weakSelf.isLiveRoom){
  429. weakSelf.goLivingRoomBlock ? weakSelf.goLivingRoomBlock(liveRoomId) : nil;
  430. }
  431. };
  432. [self.navigationController pushViewController:vc animated:YES];
  433. }
  434. - (V2TIMMessage *)baseChatViewController_Two:(TUIBaseMessageController *)controller onNewMessage:(V2TIMMessage *)message{
  435. if([message.sender isEqualToString:OfficialID] || [message.sender isEqualToString:ActivityID]){
  436. return nil;
  437. }
  438. NSString *showName;
  439. NSString *avatarURL;
  440. NSInteger headgearType = 0;
  441. NSString *headdress;
  442. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  443. if([message.sender isEqualToString:GetUserId]){
  444. showName = GetNickName;
  445. avatarURL = GetAvatar;
  446. MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
  447. headgearType = userInfoData.userProfile.adornment.headgearType;
  448. headdress = userInfoData.userProfile.adornment.headgearRes;
  449. }
  450. else{
  451. //普通用户
  452. if(self.userData){
  453. avatarURL = self.userData.userProfile.avatar;
  454. if(self.userData.remark.length > 0){
  455. showName = self.userData.remark;
  456. }
  457. else{
  458. showName = self.userData.userProfile.nickname;
  459. }
  460. headgearType = self.userData.userProfile.adornment.headgearType;
  461. headdress = self.userData.userProfile.adornment.headgearRes;
  462. }
  463. else{
  464. MOUserProfile *userModel = [MODataManager searchMOUserProfileWith:message.sender];
  465. if(userModel){
  466. avatarURL = userModel.avatar;
  467. showName = userModel.nickname;
  468. headgearType = userModel.adornment.headgearType;
  469. headdress = userModel.adornment.headgearRes;
  470. MOUserBase *userBase = [[MOUserBase alloc] init];
  471. userBase.userProfile = userModel;
  472. self.userData = userBase;
  473. }
  474. else{
  475. [self getUserInfoWith:message.sender];
  476. }
  477. }
  478. }
  479. if(avatarURL.length > 0){
  480. [dict setObject:avatarURL forKey:@"avatarURL"];
  481. }
  482. if(showName.length > 0 ){
  483. [dict setObject:showName forKey:@"showName"];
  484. }
  485. [dict setObject:@(headgearType) forKey:@"headgearType"];
  486. if(headdress.length > 0){
  487. [dict setObject:headdress forKey:@"headdress"];
  488. }
  489. NSError *error = nil;
  490. NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
  491. if(data){
  492. message.localCustomData = data;
  493. return message;
  494. }
  495. else{
  496. return nil;
  497. }
  498. }
  499. #pragma mark - Other Thing
  500. - (void)getUserInfoWith:(NSString *)userId{
  501. if([userId isEqualToString:OfficialID] || [userId isEqualToString:ActivityID]){
  502. return;
  503. }
  504. if(userId.length == 0){
  505. return;
  506. }
  507. if(self.isGetUserBase)return;
  508. self.isGetUserBase = YES;//已经调用了接口了
  509. WEAKSELF
  510. NSDictionary *dict = @{@"list":@[userId]};
  511. [kHttpManager getUserInfoListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  512. if(kCode_Success){
  513. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  514. MOUserListData *baseModel = [MOUserListData modelObjectWithDictionary:data[@"data"]];
  515. if(baseModel.userBase.count > 0){
  516. MOUserBase *userBaseInfo = baseModel.userBase.firstObject;
  517. self.userData = userBaseInfo;
  518. [MODataManager saveUserBaseWith:userBaseInfo];
  519. //腾讯
  520. [weakSelf.t_chatController.messageController.tableView reloadData];
  521. }
  522. [weakSelf updateRightBarItem];//更新右侧按钮
  523. [weakSelf toUpdataTheFollowStatus];//更新关注View
  524. }
  525. else{
  526. weakSelf.isGetUserBase = NO;//已经调用了接口了
  527. kShowNetError(data)
  528. }
  529. }];
  530. }
  531. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  532. }
  533. - (void)showReportView{
  534. WEAKSELF
  535. self.isShowReport = YES;
  536. [self.view addSubview:self.reportView];
  537. [self.reportView mas_makeConstraints:^(MASConstraintMaker *make) {
  538. make.left.equalTo(self.view).offset(0);
  539. make.width.equalTo(@(SCREENWIDTH));
  540. make.height.equalTo(@445.0);
  541. make.bottom.equalTo(self.view);
  542. }];
  543. self.reportView.userId = self.otherUserId;
  544. [self.reportView showReportSomeOneView];
  545. self.reportView.dismissReportViewBlock = ^{
  546. weakSelf.isShowReport = NO;
  547. };
  548. }
  549. #pragma mark - Lazy
  550. - (UILabel *)titleLab{
  551. if (!_titleLab)
  552. {
  553. _titleLab = [[UILabel alloc] init];
  554. _titleLab.text = @"";
  555. _titleLab.font = [UIFont systemFontOfSize:15.0];
  556. _titleLab.textColor = [MOTools colorWithHexString:@"#333333" alpha:1.0];
  557. _titleLab.textAlignment = NSTextAlignmentCenter;
  558. _titleLab.numberOfLines = 1;
  559. _titleLab.backgroundColor = [UIColor whiteColor];
  560. }
  561. return _titleLab;
  562. }
  563. - (UIButton *)blackBtn{
  564. if(!_blackBtn){
  565. _blackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  566. _blackBtn.backgroundColor = [UIColor clearColor];
  567. [_blackBtn addTarget:self action:@selector(blackBtnClick) forControlEvents:UIControlEventTouchUpInside];
  568. }
  569. return _blackBtn;
  570. }
  571. - (void)blackBtnClick{
  572. return;
  573. }
  574. - (void)dealloc{
  575. [[NSNotificationCenter defaultCenter] removeObserver:self];
  576. [[MOChatNotificationManager sharedManager] leaveScene:MOChatNotificationSceneChatDetail];//离开聊天详情
  577. }
  578. - (UIImageView *)bgImgView{
  579. if(!_bgImgView){
  580. _bgImgView = [[UIImageView alloc] init];
  581. _bgImgView.contentMode = UIViewContentModeScaleToFill;
  582. }
  583. return _bgImgView;
  584. }
  585. - (MORightBarItemView *)rightBarItemView{
  586. if(!_rightBarItemView){
  587. _rightBarItemView = [[MORightBarItemView alloc] initWithFrame:CGRectMake(0, 0, 92, 44)];
  588. }
  589. return _rightBarItemView;
  590. }
  591. - (MOReportSomeOneView *)reportView{
  592. if(!_reportView){
  593. _reportView = [MOReportSomeOneView moReportSomeOneView];
  594. _reportView.isAnimationTwo = YES;
  595. }
  596. return _reportView;
  597. }
  598. - (MOChatFollowView *)followView{
  599. if(!_followView){
  600. CGFloat viewHeight = 40.0 + 10.0 * 2.0;
  601. _followView = [[MOChatFollowView alloc] initWithFrame:CGRectMake(0, 0, (SCREENWIDTH - 12.0 * 2.0), viewHeight)];
  602. _followView.hidden = YES;
  603. WEAKSELF
  604. _followView.closeClickBlock = ^{
  605. weakSelf.followView.hidden = YES;
  606. };
  607. _followView.followClickBlock = ^{
  608. [weakSelf followSomeOneWith:weakSelf.otherUserId];
  609. };
  610. }
  611. return _followView;
  612. }
  613. - (void)followSomeOneWith:(NSString *)targetId{
  614. if(targetId.length == 0){
  615. return;
  616. }
  617. if([targetId isEqualToString:GetUserId]){
  618. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_common_cannot_to_yourself")];
  619. return;
  620. }
  621. NSArray *targetArr = @[targetId];
  622. NSDictionary *dict;
  623. if(self.userData.follow){
  624. dict = @{@"type":@"2",
  625. @"target":targetArr};
  626. }
  627. else{
  628. dict = @{@"type":@"1",
  629. @"target":targetArr};
  630. }
  631. WEAKSELF
  632. [kHttpManager toSubmitForFollowWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  633. if(kCode_Success){
  634. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_common_success")];
  635. weakSelf.userData.follow = YES;
  636. weakSelf.followView.hidden = YES;
  637. }
  638. else{
  639. kShowNetError(data)
  640. }
  641. }];
  642. }
  643. @end