KSTXBaseChatViewController.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // KSTXBaseChatViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2023/8/10.
  6. //
  7. #import "KSTXBaseChatViewController.h"
  8. #import <AVFoundation/AVFoundation.h>
  9. #import <AssetsLibrary/AssetsLibrary.h>
  10. #import <MobileCoreServices/MobileCoreServices.h>
  11. #import <Photos/Photos.h>
  12. #import <TIMCommon/NSString+TUIEmoji.h>
  13. #import <TIMCommon/TIMDefine.h>
  14. #import <TUICore/NSDictionary+TUISafe.h>
  15. #import <TUICore/TUICore.h>
  16. #import <TUICore/TUILogin.h>
  17. #import <TUICore/TUIThemeManager.h>
  18. #import <TUICore/TUITool.h>
  19. #import "ReactiveObjC/ReactiveObjC.h"
  20. #import "TUIAIDenoiseSignatureManager.h"
  21. #import "TUIBaseMessageController.h"
  22. #import "TUICameraViewController.h"
  23. #import "TUIChatConfig.h"
  24. #import "TUIChatDataProvider.h"
  25. #import "TUIChatMediaDataProvider.h"
  26. #import "TUIChatModifyMessageHelper.h"
  27. #import "TUICloudCustomDataTypeCenter.h"
  28. #import "TUIFileMessageCellData.h"
  29. #import "TUIImageMessageCellData.h"
  30. #import "TUIJoinGroupMessageCell.h"
  31. #import "TUIMessageController.h"
  32. #import "TUIMessageDataProvider.h"
  33. #import "TUIMessageMultiChooseView.h"
  34. #import "TUIMessageReadViewController.h"
  35. #import "TUIReplyMessageCellData.h"
  36. #import "TUITextMessageCellData.h"
  37. #import "TUIVideoMessageCellData.h"
  38. #import "TUIVoiceMessageCellData.h"
  39. #import "KSChatUserDetailViewController.h"
  40. #import "KSBaseWKWebViewController.h"
  41. #import "KSEnterLiveroomManager.h"
  42. #import "KSAccompanyWebViewController.h"
  43. #import "RecordCheckManager.h"
  44. #import "KSPremissionAlert.h"
  45. static UIView *gCustomTopView;
  46. @interface KSTXBaseChatViewController ()
  47. @end
  48. @implementation KSTXBaseChatViewController
  49. #pragma mark - Life Cycle
  50. - (void)messageController:(TUIBaseMessageController *)controller willDisplayCell:(TUIMessageCell *)cell withData:(TUIMessageCellData *)cellData {
  51. cell.avatarView.contentMode = UIViewContentModeScaleAspectFill;
  52. }
  53. - (void)messageController:(TUIBaseMessageController *)controller onSelectMessageAvatar:(TUIMessageCell *)cell {
  54. /*
  55. NSString *userID = nil;
  56. if (cell.messageData.innerMessage.groupID.length > 0) {
  57. userID = cell.messageData.innerMessage.sender;
  58. } else {
  59. if (cell.messageData.isUseMsgReceiverAvatar) {
  60. if (cell.messageData.innerMessage.isSelf) {
  61. userID = cell.messageData.innerMessage.userID;
  62. } else {
  63. userID = V2TIMManager.sharedInstance.getLoginUser;
  64. }
  65. } else {
  66. userID = cell.messageData.innerMessage.sender;
  67. }
  68. }
  69. if (userID == nil) {
  70. return;
  71. }
  72. // 跳转到用户详情
  73. if ([userID isEqualToString:UserDefault(IM_USERID)]) {
  74. [self displayStudent:userID];
  75. }
  76. else { // 显示其他
  77. if ([userID containsString:@"STUDENT"]) {
  78. [self displayStudent:userID];
  79. }
  80. else {
  81. [self displayTeacherInfo:userID];
  82. }
  83. }
  84. */
  85. }
  86. - (void)messageController:(TUIBaseMessageController *)controller onSelectMessageContent:(TUIMessageCell *)cell {
  87. cell.disableDefaultSelectAction = NO;
  88. if (cell.disableDefaultSelectAction) {
  89. return;
  90. }
  91. V2TIMMessage *message = cell.messageData.innerMessage;
  92. if (message.elemType == V2TIM_ELEM_TYPE_CUSTOM) {
  93. NSDictionary *param = [NSJSONSerialization JSONObjectWithData:message.customElem.data options:NSJSONReadingAllowFragments error:nil];
  94. if ([[param ks_stringValueForKey:@"businessID"] isEqualToString:@"TC_CHATSHARE_MUSIC"]) {
  95. NSString *musicSongId = [param ks_stringValueForKey:@"songId"];
  96. [self showMusic:musicSongId];
  97. }
  98. else if ([[param ks_stringValueForKey:@"businessID"] isEqualToString:@"TC_CHATSHARE_LIVE"]) {
  99. NSString *roomId = [param ks_stringValueForKey:@"roomUID"];
  100. [self enterLiveRoom:roomId];
  101. }
  102. }
  103. }
  104. - (void)enterLiveRoom:(NSString *)roomId {
  105. [KSEnterLiveroomManager joinLiveWithRoomId:roomId inController:(CustomNavViewController *)self.navigationController callback:^{
  106. }];
  107. }
  108. - (void)showMusic:(NSString *)songId {
  109. PREMISSIONTYPE micEnable = [RecordCheckManager checkPermissionShowAlert:NO showInView:nil];
  110. PREMISSIONTYPE cameraEnable = [RecordCheckManager checkCameraPremissionAvaiable:NO showInView:nil];
  111. if (micEnable == PREMISSIONTYPE_YES && cameraEnable == PREMISSIONTYPE_YES) {
  112. KSAccompanyWebViewController *detailCtrl = [[KSAccompanyWebViewController alloc] init];
  113. detailCtrl.url = [NSString stringWithFormat:@"%@/accompany?id=%@",hostURL, songId];
  114. detailCtrl.parmDic = @{@"isOpenLight" : @(YES), @"orientation" : @(0),@"isHideTitle" : @(YES)};
  115. [self.navigationController pushViewController:detailCtrl animated:YES];
  116. }
  117. else {
  118. if (micEnable == PREMISSIONTYPE_NO && cameraEnable == PREMISSIONTYPE_NO) { // 如果麦克风权限和摄像头权限都没有
  119. [self showAlertWithMessage:@"请开启相机和麦克风访问权限" type:CHECKDEVICETYPE_BOTH];
  120. }
  121. else if (micEnable == PREMISSIONTYPE_NO) { // 如果没有麦克风权限
  122. [self showAlertWithMessage:@"请开启麦克风访问权限" type:CHECKDEVICETYPE_MIC];
  123. }
  124. else if (cameraEnable == PREMISSIONTYPE_NO) { // 如果没有摄像头权限
  125. [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
  126. }
  127. }
  128. }
  129. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  130. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  131. } confirm:^{
  132. [self openSettingView];
  133. }];
  134. }
  135. - (void)openSettingView {
  136. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  137. }
  138. - (void)displayTeacherInfo:(NSString *)teacherId {
  139. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  140. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/teacherHome?teacherId=",teacherId];
  141. [self.navigationController pushViewController:ctrl animated:YES];
  142. }
  143. - (void)displayStudent:(NSString *)stuentId {
  144. KSChatUserDetailViewController *ctrl = [[KSChatUserDetailViewController alloc] init];
  145. ctrl.rongCloudId = stuentId;
  146. [self.navigationController pushViewController:ctrl animated:YES];
  147. }
  148. /*
  149. #pragma mark - Navigation
  150. // In a storyboard-based application, you will often want to do a little preparation before navigation
  151. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  152. // Get the new view controller using [segue destinationViewController].
  153. // Pass the selected object to the new view controller.
  154. }
  155. */
  156. @end