WFCUVerifyRequestViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // WFCUVerifyRequestViewController.m
  3. // WFChatUIKit
  4. //
  5. // Created by WF Chat on 2018/11/4.
  6. // Copyright © 2018 WF Chat. All rights reserved.
  7. //
  8. #import "WFCUVerifyRequestViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "MBProgressHUD.h"
  11. #import "WFCUConfigManager.h"
  12. #import "WFCUUtilities.h"
  13. @interface WFCUVerifyRequestViewController ()
  14. @property(nonatomic, strong)UITextField *verifyField;
  15. @end
  16. @implementation WFCUVerifyRequestViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // Do any additional setup after loading the view.
  20. CGRect clientArea = self.view.bounds;
  21. UILabel *hintLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 8 + [WFCUUtilities wf_navigationFullHeight], clientArea.size.width - 16, 16)];
  22. hintLabel.text = WFCString(@"AddFriendReasonHint");
  23. hintLabel.font = [UIFont systemFontOfSize:12];
  24. hintLabel.textColor = [UIColor grayColor];
  25. [self.view addSubview:hintLabel];
  26. self.view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  27. self.verifyField = [[UITextField alloc] initWithFrame:CGRectMake(0, 32 + [WFCUUtilities wf_navigationFullHeight], clientArea.size.width, 32)];
  28. WFCCUserInfo *me = [[WFCCIMService sharedWFCIMService] getUserInfo:[WFCCNetworkService sharedInstance].userId refresh:NO];
  29. self.verifyField.font = [UIFont systemFontOfSize:16];
  30. if(me.displayName){
  31. self.verifyField.text = [NSString stringWithFormat:WFCString(@"DefaultAddFriendReason"), me.displayName];
  32. }else {
  33. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  34. if(!self.verifyField.text) {
  35. WFCCUserInfo *me = [[WFCCIMService sharedWFCIMService] getUserInfo:[WFCCNetworkService sharedInstance].userId refresh:NO];
  36. if (me.displayName) {
  37. self.verifyField.text = [NSString stringWithFormat:WFCString(@"DefaultAddFriendReason"), me.displayName];
  38. } else {
  39. self.verifyField.text = WFCString(@"DefaultAddFriendReason");
  40. }
  41. }
  42. });
  43. }
  44. self.verifyField.borderStyle = UITextBorderStyleRoundedRect;
  45. self.verifyField.clearButtonMode = UITextFieldViewModeAlways;
  46. [self.view addSubview:self.verifyField];
  47. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:WFCString(@"Send") style:UIBarButtonItemStyleDone target:self action:@selector(onSend:)];
  48. }
  49. - (void)onSend:(id)sender {
  50. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  51. hud.label.text = WFCString(@"Sending");
  52. [hud showAnimated:YES];
  53. NSString *extraStr = nil;
  54. // if(self.sourceType) {
  55. // NSMutableDictionary *sourceDict = [[NSMutableDictionary alloc] init];
  56. // [sourceDict setValue:@(self.sourceType) forKey:@"t"/*type*/];
  57. // [sourceDict setValue:self.sourceTargetId forKey:@"i"/*targetId*/];
  58. // NSDictionary *extraDict = @{@"s"/*source*/:sourceDict};
  59. //
  60. // NSData *extraData = [NSJSONSerialization dataWithJSONObject:extraDict
  61. // options:kNilOptions
  62. // error:nil];
  63. // extraStr = [[NSString alloc] initWithData:extraData encoding:NSUTF8StringEncoding];
  64. // }
  65. __weak typeof(self) ws = self;
  66. [[WFCCIMService sharedWFCIMService] sendFriendRequest:self.userId reason:self.verifyField.text extra:extraStr success:^{
  67. dispatch_async(dispatch_get_main_queue(), ^{
  68. [hud hideAnimated:YES];
  69. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  70. hud.mode = MBProgressHUDModeText;
  71. hud.label.text = WFCString(@"Sent");
  72. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  73. [hud hideAnimated:YES afterDelay:1.f];
  74. [ws.navigationController popViewControllerAnimated:YES];
  75. });
  76. } error:^(int error_code) {
  77. dispatch_async(dispatch_get_main_queue(), ^{
  78. [hud hideAnimated:YES];
  79. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  80. hud.mode = MBProgressHUDModeText;
  81. if(error_code == 16) {
  82. hud.label.text = WFCString(@"AlreadySentFriendRequest");
  83. } else if(error_code == 18) {
  84. hud.label.text = WFCString(@"FriendRequestRejected");
  85. } else {
  86. hud.label.text = WFCString(@"SendFailure");
  87. }
  88. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  89. [hud hideAnimated:YES afterDelay:1.f];
  90. });
  91. }];
  92. }
  93. /*
  94. #pragma mark - Navigation
  95. // In a storyboard-based application, you will often want to do a little preparation before navigation
  96. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  97. // Get the new view controller using [segue destinationViewController].
  98. // Pass the selected object to the new view controller.
  99. }
  100. */
  101. @end