TChatC2CController.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. //
  2. // TChatC2CController.m
  3. // UIKit
  4. //
  5. // Created by kennethmiao on 2018/9/18.
  6. // Copyright © 2018年 kennethmiao. All rights reserved.
  7. //
  8. #import "TChatC2CController.h"
  9. #import "THeader.h"
  10. #import "TZImagePickerController.h"
  11. #import "TImageMessageCell.h"
  12. #import "TLocationCell.h"
  13. #import "TGoodsCell.h"
  14. #import <MobileCoreServices/MobileCoreServices.h>
  15. #import "YBScrollImageView.h"
  16. #import "YBGiftPage.h"
  17. #import "TTextMessageCell.h"
  18. #import "TencentLocationVC.h"
  19. #import "ASRView.h"
  20. @interface TChatC2CController () <TMessageControllerDelegate, TInputControllerDelegate,TZImagePickerControllerDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>{
  21. ASRView *_asrView;
  22. BOOL _asrMoveUp;
  23. }
  24. @property(nonatomic,strong)UIButton *hqs_voiceBtn;
  25. @property(nonatomic,strong)UIButton *hqs_videoBtn;
  26. @property(nonatomic,strong)UIView *topAttentView;
  27. @end
  28. @implementation TChatC2CController
  29. - (UIStatusBarStyle)preferredStatusBarStyle {
  30. if (@available(iOS 13.0,*)) {
  31. return UIStatusBarStyleDarkContent;
  32. }
  33. return UIStatusBarStyleDefault;
  34. }
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. /*
  38. id target = self.navigationController.interactivePopGestureRecognizer.delegate;
  39. UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:nil];
  40. [self.view addGestureRecognizer:pan];
  41. */
  42. self.subNavi.backgroundColor = UIColor.whiteColor;
  43. self.titleL.textColor = UIColor.blackColor;
  44. [self.leftBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:0];
  45. self.naviLine.hidden = NO;
  46. self.naviLine.backgroundColor = RGB(245, 245, 245);
  47. self.view.backgroundColor = UIColor.whiteColor;
  48. [[NSUserDefaults standardUserDefaults] setObject:_conversation.convId forKey:ybImChatingUid];
  49. self.titleL.text = _conversation.userName;
  50. self.rightBtn.hidden = NO;
  51. [self.rightBtn setImage:[UIImage imageNamed:@"center_more"] forState:UIControlStateNormal];
  52. [self setupViews];
  53. if (_conversation) {
  54. [_messageController setConversation:_conversation];
  55. _topAttentView.hidden = [_conversation.isAtt intValue];
  56. }
  57. [self.view layoutIfNeeded];
  58. if(_topAttentView.hidden){
  59. // _messageController.tableView.contentOffset = CGPointMake(0, 0);
  60. _messageController.view.frame = CGRectMake(0, 64+statusbarHeight, _window_width, _window_height - TTextView_Height - Bottom_SafeHeight-(64+statusbarHeight));//naviHight
  61. }else{
  62. // _messageController.tableView.contentOffset = CGPointMake(0, 80);
  63. _messageController.view.frame = CGRectMake(0, 64+statusbarHeight+50, _window_width, _window_height - TTextView_Height - Bottom_SafeHeight-(64+statusbarHeight+50));//naviHight
  64. }
  65. }
  66. - (void)setupViews {
  67. //message
  68. _messageController = [[TMessageController alloc] init];
  69. _messageController.uiFrom = _uiFrom;
  70. _messageController.view.frame = CGRectMake(0, 64+statusbarHeight, _window_width, _window_height - TTextView_Height - Bottom_SafeHeight-(64+statusbarHeight));//naviHight
  71. _messageController.delegate = self;
  72. _messageController.tableView.backgroundColor =UIColor.whiteColor;// TMessageController_Background_Color;
  73. [self addChildViewController:_messageController];
  74. [self.view addSubview:_messageController.view];
  75. //[_messageController setConversation:_conversation];
  76. //input
  77. _inputController = [[TInputController alloc] init];
  78. _inputController.uiFrom = _uiFrom;
  79. _inputController.view.frame = CGRectMake(0, _window_height - TTextView_Height - Bottom_SafeHeight, _window_width, TTextView_Height + Bottom_SafeHeight);
  80. _inputController.delegate = self;
  81. [self addChildViewController:_inputController];
  82. [self.view addSubview:_inputController.view];
  83. [self.view addSubview:self.topAttentView];
  84. _topAttentView.hidden = YES;
  85. [_topAttentView mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.width.centerX.equalTo(self.view);
  87. if (_uiFrom == UiFrom_Samll) {
  88. make.top.equalTo(self.view.mas_top).offset(0);
  89. }else{
  90. make.top.equalTo(self.naviView.mas_bottom).offset(0);
  91. }
  92. make.height.mas_equalTo(50);
  93. }];
  94. if (_uiFrom == UiFrom_Samll) {
  95. _messageController.tableView.backgroundColor = UIColor.whiteColor;//RGB_COLOR(@"#f4f5f6", 1);
  96. _topAttentView.backgroundColor = UIColor.whiteColor;
  97. }
  98. }
  99. - (void)doFollow{
  100. YBWeakSelf;
  101. NSDictionary *dic = @{
  102. @"uid":[Config getOwnID],
  103. @"touid":_conversation.convId,
  104. };
  105. [YBNetworking postWithUrl:@"User.isFirstAttent" Dic:dic Suc:^(int code, id info, NSString *msg) {
  106. if (code == 0) {
  107. NSDictionary *infos = [info firstObject];
  108. //is_first 1 第一次关注 0 不是第一次关注
  109. BOOL isfirstAttent = [minstr([infos valueForKey:@"is_first"]) boolValue];;
  110. [weakSelf setAttentFirst:isfirstAttent];
  111. }
  112. } Fail:^(id fail) {
  113. }];
  114. }
  115. -(void)setAttentFirst:(BOOL)isFirst {
  116. NSString *postUrl = @"User.setAttent";
  117. NSDictionary *postDic = @{
  118. @"touid":_conversation.convId,
  119. };
  120. YBWeakSelf;
  121. [YBNetworking postWithUrl:postUrl Dic:postDic Suc:^(int code, id info, NSString *msg) {
  122. if (code == 0) {
  123. [weakSelf clickFollowClose];
  124. [MBProgressHUD showError:YZMsg(@"关注对方成功")];
  125. [[NSNotificationCenter defaultCenter] postNotificationName:ybImC2CFollow object:@(1)];
  126. if (isFirst) {
  127. //发送自定义消息
  128. NSDictionary *infoDic = @{@"uid":[Config getOwnID],@"touid":_conversation.convId,@"method":@"follow"};
  129. NSData *data = [NSJSONSerialization dataWithJSONObject:infoDic options:NSJSONWritingPrettyPrinted error:nil];
  130. V2TIMCustomElem * custom_elem = [[V2TIMCustomElem alloc] init];
  131. [custom_elem setData:data];
  132. [[YBImManager shareInstance]sendV2CustomMsg:custom_elem andReceiver:_conversation.convId complete:^(BOOL isSuccess, V2TIMMessage *sendMsg, NSString *desc) {
  133. }];
  134. }
  135. }else{
  136. [MBProgressHUD showError:msg];
  137. }
  138. } Fail:^(id fail) {
  139. }];
  140. }
  141. - (void)doSetBlack{
  142. NSString *url = [NSString stringWithFormat:@"User.setBlack&uid=%@&token=%@&touid=%@",[Config getOwnID],[Config getOwnToken],_conversation.convId];
  143. [YBNetworking postWithUrl:url Dic:nil Suc:^(int code, id info, NSString *msg) {
  144. if (code == 0) {
  145. NSString *infoDic = [info firstObject];
  146. NSString *isBlakc = [NSString stringWithFormat:@"%@",[infoDic valueForKey:@"isblack"]];
  147. if ([isBlakc isEqual:@"1"]) {
  148. [MBProgressHUD showPop:YZMsg(@"拉黑成功")];
  149. }else {
  150. [MBProgressHUD showPop:YZMsg(@"解除拉黑成功")];
  151. }
  152. }else {
  153. [MBProgressHUD showPop:msg];
  154. }
  155. } Fail:^(id fail) {
  156. }];
  157. }
  158. - (void)clickNaviRightBtn{
  159. YBWeakSelf;
  160. NSString *url = [NSString stringWithFormat:@"User.checkBlack&uid=%@&token=%@&touid=%@",[Config getOwnID],[Config getOwnToken],_conversation.convId];
  161. [YBNetworking postWithUrl:url Dic:nil Suc:^(int code, id info, NSString *msg) {
  162. if (code == 0) {
  163. NSDictionary *infoDic = [info firstObject];
  164. NSString *u2t = [NSString stringWithFormat:@"%@",[infoDic valueForKey:@"u2t"]];
  165. //u2t 0-未拉黑 1-已拉黑
  166. NSString *blackTitle = YZMsg(@"拉黑");
  167. if ([u2t isEqual:@"1"]) {
  168. blackTitle = YZMsg(@"解除拉黑");
  169. }
  170. [weakSelf showSheetView:blackTitle];
  171. }else {
  172. [MBProgressHUD showPop:msg];
  173. }
  174. } Fail:^(id fail) {
  175. }];
  176. }
  177. -(void)showSheetView:(NSString *)blackTitle {
  178. YBWeakSelf;
  179. RKActionSheet *sheet = [[RKActionSheet alloc]initWithTitle:@""];
  180. [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"举报") complete:^{
  181. [weakSelf doReport];
  182. }];
  183. [sheet addActionWithType:RKSheet_Default andTitle:blackTitle complete:^{
  184. [weakSelf doSetBlack];
  185. }];
  186. [sheet addActionWithType:RKSheet_Cancle andTitle:YZMsg(@"取消") complete:^{
  187. }];
  188. [sheet showSheet];
  189. }
  190. //举报
  191. -(void)doReport{
  192. PubH5 *h5vc = [[PubH5 alloc]init];
  193. h5vc.url =[h5url stringByAppendingString:[NSString stringWithFormat:@"/appapi/userreport/index?uid=%@&token=%@&touid=%@",[Config getOwnID],[Config getOwnToken],_conversation.convId]];
  194. [self.navigationController pushViewController:h5vc animated:YES];
  195. }
  196. - (void)doReturn{
  197. [[YBImManager shareInstance]clearUnreadConvId:_conversation.convId sendNot:YES];
  198. [self.navigationController popViewControllerAnimated:YES];
  199. }
  200. - (void)inputControllerDidClickHqsGiftBtn{
  201. }
  202. - (void)inputController:(TInputController *)inputController didChangeHeight:(CGFloat)height {
  203. CGFloat navSpace = naviHight;
  204. if (_uiFrom == UiFrom_Samll) {
  205. navSpace = 0;
  206. }
  207. // __weak typeof(self) ws = self;
  208. if (height<50) {
  209. [self showVioceAndVideoBtn];
  210. }else{
  211. [self inputControllerHiddenVoiceVideo];
  212. }
  213. //NSLog(@"rk=========================22222====:%f====sm:%f",height,navSpace);
  214. [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
  215. CGRect msgFrame = _messageController.view.frame;
  216. msgFrame.size.height = self.view.frame.size.height - height-navSpace;
  217. //未知原因-19.6,这里重置一下起始位置
  218. msgFrame.origin.y = navSpace;
  219. _messageController.view.frame = msgFrame;
  220. CGRect inputFrame = _inputController.view.frame;
  221. inputFrame.origin.y = msgFrame.origin.y + msgFrame.size.height;
  222. inputFrame.size.height = height;
  223. _inputController.view.frame = inputFrame;
  224. [_messageController scrollToBottom:NO];
  225. //NSLog(@"rk=========================ani:%@",_messageController.view);
  226. } completion:^(BOOL finished) {
  227. //NSLog(@"rk=========================finishi\n===:%@\n===%@",_messageController.view,_inputController.view);
  228. }];
  229. }
  230. -(void)inputResetHeight {
  231. [_inputController reset];
  232. [self showVioceAndVideoBtn];
  233. }
  234. - (void)inputController:(TInputController *)inputController didSendMessage:(TMessageCellData *)msg {
  235. BOOL isText = NO;
  236. if ([msg isKindOfClass:[TTextMessageCellData class]]) {
  237. isText = YES;
  238. }
  239. [self checkBlack:msg imgIdx:0 isTextMsg:isText];
  240. }
  241. - (void)inputController:(TInputController *)inputController didSelectMoreAtIndex:(NSInteger)index{
  242. NSLog(@"----------%ld",index);
  243. [_inputController reset];
  244. [self showVioceAndVideoBtn];
  245. if (index == 0) {
  246. TZImagePickerController *imagePC = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self];
  247. imagePC.allowCameraLocation = YES;
  248. imagePC.allowTakeVideo = NO;
  249. imagePC.allowPickingVideo = NO;
  250. imagePC.doneBtnTitleStr = YZMsg(@"发送");
  251. imagePC.modalPresentationStyle = UIModalPresentationFullScreen;
  252. [self presentViewController:imagePC animated:YES completion:nil];
  253. }else if (index == 1){
  254. //相机
  255. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  256. picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  257. picker.cameraCaptureMode =UIImagePickerControllerCameraCaptureModePhoto;
  258. picker.delegate = self;
  259. picker.modalPresentationStyle = UIModalPresentationFullScreen;
  260. [self presentViewController:picker animated:YES completion:nil];
  261. }else if (index == 2){
  262. //语音
  263. [self voiceInputClick];
  264. }else if (index == 3){
  265. //位置
  266. [self locationClick];
  267. }
  268. }
  269. #pragma mark - 语音输入
  270. -(void)voiceInputClick {
  271. NSLog(@"语音输入");
  272. YBWeakSelf;
  273. if (!_asrView) {
  274. _asrView = [[ASRView alloc]initWithFrame:CGRectMake(0, _window_height, _window_width, _window_height) callBack:^(NSString *type, NSString *content) {
  275. if ([type isEqual:@"返回"]) {
  276. NSLog(@"返回");
  277. [weakSelf asrBack];
  278. }else if ([type isEqual:@"发送"]){
  279. NSLog(@"发送");
  280. [weakSelf asrSend:content];
  281. }
  282. }];
  283. [self.view addSubview:_asrView];
  284. }
  285. [UIView animateWithDuration:0.25 animations:^{
  286. _asrView.frame = CGRectMake(0, 0, _window_width, _window_height);
  287. }];
  288. }
  289. -(void)asrBack {
  290. [_asrView.textView resignFirstResponder];
  291. [UIView animateWithDuration:0.25 animations:^{
  292. _asrView.frame = CGRectMake(0, _window_height, _window_width, _window_height);
  293. }];
  294. }
  295. -(void)asrSend:(NSString *)content {
  296. TTextMessageCellData *data = [[TTextMessageCellData alloc] init];
  297. data.head = TUIKitResource(@"default_head");
  298. data.content = content;
  299. data.isSelf = YES;
  300. [self checkBlack:data imgIdx:0 isTextMsg:YES];
  301. }
  302. #pragma mark - 位置信息
  303. -(void)locationClick {
  304. TencentLocationVC *locationVC = [[TencentLocationVC alloc]init];
  305. YBWeakSelf;
  306. locationVC.locationEvent = ^(NSDictionary *locDic) {
  307. [weakSelf prepareLocation:locDic];
  308. };
  309. [self.navigationController pushViewController:locationVC animated:YES];
  310. }
  311. -(void)prepareLocation:(NSDictionary *)dic{
  312. double latitude = [strFormat([dic valueForKey:@"latitude"]) doubleValue];
  313. double longitude = [strFormat([dic valueForKey:@"longitude"]) doubleValue];
  314. NSString *address = [dic valueForKey:@"address"];
  315. TLocationCellData *locData = [[TLocationCellData alloc] init];
  316. locData.head = TUIKitResource(@"default_head");
  317. locData.isSelf = YES;
  318. locData.locDes = address;
  319. locData.lat = latitude;
  320. locData.lng = longitude;
  321. [self checkBlack:locData imgIdx:0 isTextMsg:NO];
  322. }
  323. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto{
  324. for (int i = 0;i < photos.count;i++) {
  325. UIImage *img = photos[i];
  326. [self sendImageMessage:img andIndex:i];
  327. }
  328. }
  329. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
  330. NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
  331. if([mediaType isEqualToString:(NSString *)kUTTypeImage]){
  332. UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
  333. UIImageOrientation imageOrientation= image.imageOrientation;
  334. if(imageOrientation != UIImageOrientationUp) {
  335. UIGraphicsBeginImageContext(image.size);
  336. [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
  337. image = UIGraphicsGetImageFromCurrentImageContext();
  338. UIGraphicsEndImageContext();
  339. }
  340. [self sendImageMessage:image andIndex:0];
  341. }
  342. [picker dismissViewControllerAnimated:YES completion:nil];
  343. }
  344. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
  345. [picker dismissViewControllerAnimated:YES completion:nil];
  346. }
  347. #pragma mark - TMessageControllerDelegate
  348. - (void)didTapInMessageController:(TMessageController *)controller {
  349. [_inputController reset];
  350. [self showVioceAndVideoBtn];
  351. }
  352. -(void)showVioceAndVideoBtn {
  353. _hqs_voiceBtn.hidden = _hqs_videoBtn.hidden = NO;
  354. }
  355. -(void)inputControllerHiddenVoiceVideo {
  356. _hqs_voiceBtn.hidden = _hqs_videoBtn.hidden = YES;
  357. }
  358. - (void)didHideMenuInMessageController:(TMessageController *)controller {
  359. _inputController.textView.inputTextView.overrideNextResponder = nil;
  360. }
  361. - (BOOL)messageController:(TMessageController *)controller willShowMenuInCell:(TMessageCell *)cell {
  362. if([_inputController.textView.inputTextView isFirstResponder]){
  363. _inputController.textView.inputTextView.overrideNextResponder = cell;
  364. return YES;
  365. }
  366. return NO;
  367. }
  368. - (void)messageController:(TMessageController *)controller didSelectMessages:(NSMutableArray *)msgs atIndex:(NSInteger)index {
  369. TMessageCellData *currentdata = msgs[index];
  370. NSMutableArray *imgarr = [NSMutableArray array];
  371. NSInteger currentIndex = 0;
  372. for (int i = 0; i < msgs.count; i ++) {
  373. TMessageCellData *data = msgs[i];
  374. if([data isKindOfClass:[TImageMessageCellData class]]){
  375. TImageMessageCellData *imgData = (TImageMessageCellData *)data;
  376. [imgarr addObject:imgData.thumbImage];
  377. }
  378. }
  379. for (int k = 0; k < imgarr.count; k ++) {
  380. TImageMessageCellData *imgDatass = (TImageMessageCellData *)currentdata;
  381. UIImage *currentimg = imgarr[k];
  382. if (imgDatass.thumbImage == currentimg) {
  383. currentIndex = k;
  384. break;
  385. }
  386. }
  387. NSLog(@"==-=-=-=-=-=-=-=-=-=:::%@", imgarr);
  388. YBScrollImageView *imgView = [[YBScrollImageView alloc] initWithImageArray:imgarr andIndex:currentIndex andMine:NO andBlock:^(NSArray * _Nonnull array) {
  389. }];
  390. [imgView hideDelete];
  391. [[UIApplication sharedApplication].keyWindow addSubview:imgView];
  392. }
  393. /// 收到礼物IM
  394. - (void)reciveGiftMessage:(NSDictionary *)giftRes{
  395. }
  396. #pragma mark - 发送消息
  397. - (void)sendImageMessage:(UIImage *)image andIndex:(int)index; {
  398. [self checkBlack:image imgIdx:index isTextMsg:NO];
  399. }
  400. - (void)sendVideoMessage:(NSURL *)url {
  401. [_messageController sendVideoMessage:url];
  402. }
  403. - (void)sendFileMessage:(NSURL *)url {
  404. [_messageController sendFileMessage:url];
  405. }
  406. - (void)checkBlack:(id)datamsg imgIdx:(int)imgIdx isTextMsg:(BOOL)isText{
  407. __block id blockDatamsg = datamsg;
  408. NSString *oldContent = @"";
  409. if (isText) {
  410. TTextMessageCellData *cellData = (TTextMessageCellData*)datamsg;
  411. oldContent = cellData.content;
  412. }
  413. NSDictionary *postDic = @{
  414. @"touid":_conversation.convId,
  415. @"content":oldContent,
  416. };
  417. YBWeakSelf;
  418. [YBNetworking postWithUrl:@"User.checkBlack" Dic:postDic Suc:^(int code, id info, NSString *msg) {
  419. if (code == 0) {
  420. NSDictionary *infoDic = [info firstObject];
  421. // 字段无特殊意义
  422. int isletter = 1;//[minstr([infoDic valueForKey:@"isletter"])intValue];
  423. NSString *isattent = [NSString stringWithFormat:@"%@",[infoDic valueForKey:@"isattent"]];
  424. NSString *t2u = [NSString stringWithFormat:@"%@",[infoDic valueForKey:@"t2u"]];
  425. NSString *sendConten = minstr([infoDic valueForKey:@"content"]);
  426. if (isText) {
  427. // 过滤后的字符重新赋值
  428. TTextMessageCellData *cellData = (TTextMessageCellData*)blockDatamsg;
  429. cellData.content = sendConten;
  430. blockDatamsg = cellData;
  431. }
  432. NSString *p_switch = [NSString stringWithFormat:@"%@",[common private_letter_switch]];
  433. int p_nums = [[NSString stringWithFormat:@"%@",[common private_letter_nums]] intValue];
  434. //我发送的条数
  435. int frends_cont = [_messageController sendMsgNums];
  436. if ([t2u isEqual:@"0"]) {
  437. if ([isattent isEqual:@"0"] && [p_switch isEqual:@"1"] && frends_cont >= p_nums) {
  438. [MBProgressHUD showPop:[NSString stringWithFormat:@"%@%d%@",YZMsg(@"对方未关注你,最多只能发送"),p_nums,YZMsg(@"条信息")]];
  439. }else {
  440. if (isletter == 0) {
  441. NSString *letterAlert = minstr([infoDic valueForKey:@"isletter_msg"]);
  442. [weakSelf gdyChatPayAlert:letterAlert dataMsg:blockDatamsg imgIdx:imgIdx];
  443. }else{
  444. [weakSelf canSendWithMsg:blockDatamsg imgIdx:imgIdx];
  445. }
  446. }
  447. }else {
  448. [_inputController.textView clearInput];
  449. [_inputController.inputView resignFirstResponder];
  450. [MBProgressHUD showPop:YZMsg(@"对方暂时拒绝接收您的消息")];
  451. }
  452. }else {
  453. [_inputController.textView clearInput];
  454. [_inputController.inputView resignFirstResponder];
  455. [MBProgressHUD showPop:msg];
  456. }
  457. } Fail:^(id fail) {
  458. }];
  459. }
  460. -(void)gdyChatPayAlert:(NSString *)alertMsg dataMsg:(id)datamsg imgIdx:(int)imgIdx{
  461. [self.view endEditing:YES];
  462. NSDictionary *contentDic = @{
  463. @"title":YZMsg(@"提示"),
  464. @"msg":alertMsg,
  465. @"left":YZMsg(@"取消"),
  466. @"right":YZMsg(@"去打赏")
  467. };
  468. YBWeakSelf;
  469. [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  470. if (eventType == 1) {
  471. [weakSelf goReqServiceWithdataMsg:datamsg imgIdx:imgIdx];
  472. }
  473. }];
  474. }
  475. -(void)goReqServiceWithdataMsg:(id)datamsg imgIdx:(int)imgIdx {
  476. YBWeakSelf;
  477. [YBNetworking postWithUrl:@"User.addLetterCoin" Dic:@{@"touid":_conversation.convId} Suc:^(int code, id info, NSString *msg) {
  478. [MBProgressHUD showError:msg];
  479. if (code == 0) {
  480. [weakSelf canSendWithMsg:datamsg imgIdx:imgIdx];
  481. }
  482. } Fail:^(id fail) {
  483. }];
  484. }
  485. // 发送消息/扣费费送出
  486. -(void)canSendWithMsg:(id)datamsg imgIdx:(int)imgIdx {
  487. [_inputController.textView clearInput];
  488. if ([datamsg isKindOfClass:[UIImage class]]) {
  489. [_messageController sendImageMessage:datamsg andIndex:imgIdx];
  490. }else{
  491. [_messageController sendMessage:datamsg];
  492. }
  493. }
  494. - (void)dealloc{
  495. [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:ybImChatingUid];
  496. }
  497. #pragma mark -
  498. - (UIView *)topAttentView {
  499. if (!_topAttentView) {
  500. _topAttentView = [[UIView alloc]init];
  501. _topAttentView.backgroundColor = UIColor.whiteColor;
  502. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  503. [closeBtn setImage:[UIImage imageNamed:@"提示关闭"] forState:0];
  504. [closeBtn addTarget:self action:@selector(clickFollowClose) forControlEvents:UIControlEventTouchUpInside];
  505. [_topAttentView addSubview:closeBtn];
  506. [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  507. make.width.height.mas_equalTo(40);
  508. make.centerY.equalTo(_topAttentView.mas_centerY);
  509. make.left.equalTo(_topAttentView.mas_left).offset(5);
  510. }];
  511. UILabel *desL = [[UILabel alloc]init];
  512. desL.text = YZMsg(@"点击关注,可及时看到对方动态");
  513. desL.font = SYS_Font(12);
  514. desL.textColor = RGB_COLOR(@"#828282", 1);
  515. desL.numberOfLines = 2;
  516. [_topAttentView addSubview:desL];
  517. [desL mas_makeConstraints:^(MASConstraintMaker *make) {
  518. make.left.equalTo(closeBtn.mas_right).offset(5);
  519. make.centerY.equalTo(_topAttentView);
  520. }];
  521. UIButton *followBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  522. //YZMsg(@"关注-chattop")
  523. [followBtn setTitle:YZMsg(@"关注") forState:0];
  524. followBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
  525. followBtn.layer.cornerRadius = 10;
  526. followBtn.layer.masksToBounds = YES;
  527. followBtn.titleLabel.font = SYS_Font(12);
  528. followBtn.layer.borderColor = Pink_Cor.CGColor;
  529. followBtn.layer.borderWidth = 1;
  530. [followBtn setTitleColor:Pink_Cor forState:0];
  531. [followBtn addTarget:self action:@selector(doFollow) forControlEvents:UIControlEventTouchUpInside];
  532. [_topAttentView addSubview:followBtn];
  533. [followBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  534. make.centerY.equalTo(_topAttentView.mas_centerY);
  535. make.right.equalTo(_topAttentView.mas_right).offset(-15);
  536. make.left.greaterThanOrEqualTo(desL.mas_right).offset(10);
  537. make.height.mas_equalTo(20);
  538. }];
  539. [desL setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
  540. [followBtn setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  541. }
  542. return _topAttentView;;
  543. }
  544. -(void)clickFollowClose {
  545. _topAttentView.hidden = YES;
  546. }
  547. #pragma mark - 小窗
  548. -(void)imSmallViewReload {
  549. if (_conversation) {
  550. [_messageController setConversation:_conversation];
  551. _topAttentView.hidden = [_conversation.isAtt intValue];
  552. }
  553. self.naviView.hidden = YES;
  554. [self changeSmallHeight];
  555. _topAttentView.top = 0;
  556. //NSLog(@"rk=========================follow:%@",_topAttentView);
  557. }
  558. -(void)changeSmallHeight {
  559. _messageController.view.frame = CGRectMake(0, 0, _window_width, self.view.height - TTextView_Height - Bottom_SafeHeight);
  560. _inputController.view.frame = CGRectMake(0, _messageController.view.bottom, _window_width, TTextView_Height + Bottom_SafeHeight);
  561. // NSLog(@"rk=========================111111\n===:%@\n===%@",_messageController.view,_inputController.view);
  562. }
  563. @end