KSTXBaseChatViewController.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 "ShareMusicViewController.h"
  41. #import "MinePageViewController.h"
  42. #import "KSBaseWKWebViewController.h"
  43. #import "KSAccompanyWebViewController.h"
  44. #import "KSEnterLiveroomManager.h"
  45. #import "RecordCheckManager.h"
  46. #import "KSPremissionAlert.h"
  47. static UIView *gCustomTopView;
  48. @interface KSTXBaseChatViewController ()
  49. @end
  50. @implementation KSTXBaseChatViewController
  51. #pragma mark - Life Cycle
  52. - (void)messageController:(TUIBaseMessageController *)controller willDisplayCell:(TUIMessageCell *)cell withData:(TUIMessageCellData *)cellData {
  53. cell.avatarView.contentMode = UIViewContentModeScaleAspectFill;
  54. }
  55. - (void)messageController:(TUIBaseMessageController *)controller onSelectMessageAvatar:(TUIMessageCell *)cell {
  56. /*
  57. NSString *userID = nil;
  58. if (cell.messageData.innerMessage.groupID.length > 0) {
  59. userID = cell.messageData.innerMessage.sender;
  60. } else {
  61. if (cell.messageData.isUseMsgReceiverAvatar) {
  62. if (cell.messageData.innerMessage.isSelf) {
  63. userID = cell.messageData.innerMessage.userID;
  64. } else {
  65. userID = V2TIMManager.sharedInstance.getLoginUser;
  66. }
  67. } else {
  68. userID = cell.messageData.innerMessage.sender;
  69. }
  70. }
  71. if (userID == nil) {
  72. return;
  73. }
  74. // 跳转到用户详情
  75. if ([userID isEqualToString:UserDefault(IM_USERID)]) {
  76. [self displayMineInfo];
  77. }
  78. else { // 显示其他
  79. if ([userID containsString:@"STUDENT"]) {
  80. [self displayStudent:userID];
  81. }
  82. else {
  83. [self displayTeacherInfo:userID];
  84. }
  85. }
  86. */
  87. }
  88. - (void)displayMineInfo {
  89. MinePageViewController *pageCtrl = [[MinePageViewController alloc] init];
  90. [self.navigationController pushViewController:pageCtrl animated:YES];
  91. }
  92. - (void)displayTeacherInfo:(NSString *)teacherId {
  93. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  94. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/teacherHome?teacherId=", teacherId];
  95. [self.navigationController pushViewController:ctrl animated:YES];
  96. }
  97. - (void)displayStudent:(NSString *)stuentId {
  98. KSChatUserDetailViewController *ctrl = [[KSChatUserDetailViewController alloc] init];
  99. ctrl.rongCloudId = stuentId;
  100. [self.navigationController pushViewController:ctrl animated:YES];
  101. }
  102. - (void)onShareMusicMoreCellData { // 分享曲谱
  103. MJWeakSelf;
  104. ShareMusicViewController *ctrl = [[ShareMusicViewController alloc] init];
  105. [ctrl shareSongChooseCallback:^(MusicMessageModel * _Nonnull chooseModel) {
  106. [weakSelf shareSongAction:chooseModel];
  107. }];
  108. [self.navigationController pushViewController:ctrl animated:YES];
  109. }
  110. - (void)shareSongAction:(MusicMessageModel *)musicModel {
  111. NSMutableDictionary *parm = [NSMutableDictionary dictionary];
  112. [parm setValue:@"TC_CHATSHARE_MUSIC" forKey:BussinessID];
  113. [parm setValue:[NSString returnNoNullStringWithString:musicModel.musicSheetName] forKey:@"songName"];
  114. [parm setValue:musicModel.chargeType forKey:@"chargeType"];
  115. [parm setValue:musicModel.composer forKey:@"songAuth"];
  116. [parm setValue:[musicModel.addUserAvatar getUrlEndcodeString] forKey:@"teacherAvatar"];
  117. [parm setValue:[NSString returnNoNullStringWithString:musicModel.musicSheetName] forKey:@"songName"];
  118. NSString *owner = @"";
  119. if ([NSString isEmptyString:musicModel.addName]) {
  120. owner = [NSString stringWithFormat:@"游客%.0f",musicModel.userId];
  121. }
  122. else {
  123. owner = musicModel.addName;
  124. }
  125. [parm setValue:owner forKey:@"teacherName"];
  126. [parm setValue:musicModel.subjectNames forKey:@"musicTagNames"];
  127. [parm setValue:[NSString stringWithFormat:@"%.0f",musicModel.internalBaseClassIdentifier] forKey:@"songId"];
  128. NSData *data = [NSJSONSerialization dataWithJSONObject:parm options:0 error:nil];
  129. V2TIMMessage *message = [[V2TIMManager sharedInstance] createCustomMessage:data];
  130. [self sendMessage:message];
  131. }
  132. - (void)messageController:(TUIBaseMessageController *)controller onSelectMessageContent:(TUIMessageCell *)cell {
  133. cell.disableDefaultSelectAction = NO;
  134. if (cell.disableDefaultSelectAction) {
  135. return;
  136. }
  137. V2TIMMessage *message = cell.messageData.innerMessage;
  138. if (message.elemType == V2TIM_ELEM_TYPE_CUSTOM) {
  139. NSDictionary *param = [NSJSONSerialization JSONObjectWithData:message.customElem.data options:NSJSONReadingAllowFragments error:nil];
  140. if ([[param ks_stringValueForKey:@"businessID"] isEqualToString:@"TC_CHATSHARE_MUSIC"]) {
  141. NSString *musicSongId = [param ks_stringValueForKey:@"songId"];
  142. [self showMusic:musicSongId];
  143. }
  144. else if ([[param ks_stringValueForKey:@"businessID"] isEqualToString:@"TC_CHATSHARE_LIVE"]) {
  145. NSString *roomId = [param ks_stringValueForKey:@"roomUID"];
  146. NSString *liveDesc = [param ks_stringValueForKey:@"liveDescMessage"];
  147. [self enterLiveRoom:roomId desc:liveDesc];
  148. }
  149. }
  150. }
  151. - (void)enterLiveRoom:(NSString *)roomId desc:(NSString *)liveDesc {
  152. // 查询房间信息
  153. [KSEnterLiveroomManager queryLiveStatusConfig:roomId liveContent:liveDesc inController:(CustomNavViewController *)self.navigationController callback:^(ENTER_CALLTYPE type) {
  154. }];
  155. }
  156. - (void)showMusic:(NSString *)songId {
  157. PREMISSIONTYPE micEnable = [RecordCheckManager checkPermissionShowAlert:NO showInView:nil];
  158. PREMISSIONTYPE cameraEnable = [RecordCheckManager checkCameraPremissionAvaiable:NO showInView:nil];
  159. if (micEnable == PREMISSIONTYPE_YES && cameraEnable == PREMISSIONTYPE_YES) {
  160. KSAccompanyWebViewController *detailCtrl = [[KSAccompanyWebViewController alloc] init];
  161. detailCtrl.url = [NSString stringWithFormat:@"%@/accompany?id=%@",hostURL, songId];
  162. detailCtrl.parmDic = @{@"isOpenLight" : @(YES), @"orientation" : @(0),@"isHideTitle" : @(YES)};
  163. [self.navigationController pushViewController:detailCtrl animated:YES];
  164. }
  165. else {
  166. if (micEnable == PREMISSIONTYPE_NO && cameraEnable == PREMISSIONTYPE_NO) { // 如果麦克风权限和摄像头权限都没有
  167. [self showAlertWithMessage:@"请开启相机和麦克风访问权限" type:CHECKDEVICETYPE_BOTH];
  168. }
  169. else if (micEnable == PREMISSIONTYPE_NO) { // 如果没有麦克风权限
  170. [self showAlertWithMessage:@"请开启麦克风访问权限" type:CHECKDEVICETYPE_MIC];
  171. }
  172. else if (cameraEnable == PREMISSIONTYPE_NO) { // 如果没有摄像头权限
  173. [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
  174. }
  175. }
  176. }
  177. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  178. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  179. } confirm:^{
  180. [self openSettingView];
  181. }];
  182. }
  183. - (void)openSettingView {
  184. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  185. }
  186. /*
  187. #pragma mark - Navigation
  188. // In a storyboard-based application, you will often want to do a little preparation before navigation
  189. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  190. // Get the new view controller using [segue destinationViewController].
  191. // Pass the selected object to the new view controller.
  192. }
  193. */
  194. @end