Browse Source

添加修改用户名的功能

heavyrain2012 4 years ago
parent
commit
e3a8cb8bca

+ 18 - 0
wfchat/WildFireChat/AppService/AppService.m

@@ -263,6 +263,24 @@ static AppService *sharedSingleton = nil;
     
 }
 
+- (void)changeName:(NSString *)newName success:(void(^)(void))successBlock error:(void(^)(int errorCode, NSString *message))errorBlock {
+    [self post:@"/change_name" data:@{@"newName":newName} success:^(NSDictionary *dict) {
+        if([dict[@"code"] intValue] == 0) {
+            successBlock();
+        } else {
+            NSString *errmsg;
+            if ([dict[@"code"] intValue] == 17) {
+                errmsg = @"用户名已经存在";
+            } else {
+                errmsg = @"网络错误";
+            }
+            errorBlock([dict[@"code"] intValue], errmsg);
+        }
+    } error:^(NSError * _Nonnull error) {
+        errorBlock(-1, error.localizedDescription);
+    }];
+}
+
 - (void)showPCSessionViewController:(UIViewController *)baseController pcClient:(WFCCPCOnlineInfo *)clientInfo {
     PCSessionViewController *vc = [[PCSessionViewController alloc] init];
     vc.pcClientInfo = clientInfo;

+ 22 - 2
wfclient/WFChatClient/Client/WFCCIMService.h

@@ -291,6 +291,12 @@ typedef NS_ENUM(NSInteger, WFCCPlatformType) {
  */
 - (void)clearUnreadStatus:(WFCCConversation *)conversation;
 
+/**
+清空会话未读数
+
+@param conversationTypes 会话类型
+@param lines 线路
+*/
 - (void)clearUnreadStatus:(NSArray<NSNumber *> *)conversationTypes
                               lines:(NSArray<NSNumber *> *)lines;
 
@@ -301,12 +307,26 @@ typedef NS_ENUM(NSInteger, WFCCPlatformType) {
 
 /**
  设置媒体消息已播放(已经放开限制,所有消息都可以设置为已读状态)
+ 
+ @param messageId 消息ID
  */
 - (void)setMediaMessagePlayed:(long)messageId;
 
+/**
+获取会话内已读状态
+
+@param conversation 会话
+@return 会话的每个用户的已读时间
+*/
 - (NSMutableDictionary<NSString *, NSNumber *> *)getConversationRead:(WFCCConversation *)conversation;
+
+/**
+获取会话内已送达状态
+
+@param conversation 会话
+@return 会话的每个用户的已送达时间
+*/
 - (NSMutableDictionary<NSString *, NSNumber *> *)getMessageDelivery:(WFCCConversation *)conversation;
-- (long long)getMessageDeliveryByUser:(NSString *)userId;
 
 #pragma mark - 消息相关
 /**
@@ -568,7 +588,7 @@ typedef NS_ENUM(NSInteger, WFCCPlatformType) {
  @param messageId 消息ID
  @return 是否删除成功
  */
-- (void)deleteMessage:(long)messageId;
+- (BOOL)deleteMessage:(long)messageId;
 
 /**
  删除会话中的消息

+ 40 - 36
wfuikit/WFChatUIKit/Me/WFCUModifyMyProfileViewController.m

@@ -11,7 +11,7 @@
 #import <WFChatClient/WFCChatClient.h>
 #import "WFCUConfigManager.h"
 
-@interface WFCUModifyMyProfileViewController () <UITextFieldDelegate, UITextInputDelegate>
+@interface WFCUModifyMyProfileViewController () <UITextFieldDelegate>
 @property(nonatomic, strong)UITextField *textField;
 @end
 
@@ -55,6 +55,10 @@
             title = WFCString(@"ModifyNickname");
             defaultValue = userInfo.displayName;
             break;
+        case 100:
+            title = @"修改账户名";
+            defaultValue = userInfo.name;
+            break;
         default:
             break;
     }
@@ -77,19 +81,36 @@
     hud.label.text = WFCString(@"Updating");
     [hud showAnimated:YES];
     
-    [[WFCCIMService sharedWFCIMService] modifyMyInfo:@{@(self.modifyType):self.textField.text} success:^{
-        [hud hideAnimated:NO];
-        self.onModified(self.modifyType, self.textField.text);
-        [ws.navigationController popViewControllerAnimated:YES];
-    } error:^(int error_code) {
-        [hud hideAnimated:NO];
-        
-        hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
-        hud.mode = MBProgressHUDModeText;
-        hud.label.text = WFCString(@"UpdateFailure");
-        hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
-        [hud hideAnimated:YES afterDelay:1.f];
-    }];
+    if (self.modifyType == 100) {
+        [[WFCUConfigManager globalManager].appServiceProvider changeName:self.textField.text success:^{
+            [hud hideAnimated:NO];
+            self.onModified(self.modifyType, self.textField.text);
+            [ws.navigationController popViewControllerAnimated:YES];
+        } error:^(int errorCode, NSString * _Nonnull message) {
+            [hud hideAnimated:NO];
+            
+            hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
+            hud.mode = MBProgressHUDModeText;
+            hud.label.text = message;
+            hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
+            [hud hideAnimated:YES afterDelay:1.f];
+        }];
+    } else {
+        [[WFCCIMService sharedWFCIMService] modifyMyInfo:@{@(self.modifyType):self.textField.text} success:^{
+            [hud hideAnimated:NO];
+            self.onModified(self.modifyType, self.textField.text);
+            [ws.navigationController popViewControllerAnimated:YES];
+        } error:^(int error_code) {
+            [hud hideAnimated:NO];
+            
+            hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
+            hud.mode = MBProgressHUDModeText;
+            hud.label.text = WFCString(@"UpdateFailure");
+            hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
+            [hud hideAnimated:YES afterDelay:1.f];
+        }];
+    }
+    
 }
 
 - (void)didReceiveMemoryWarning {
@@ -103,20 +124,13 @@
         _textField.borderStyle = UITextBorderStyleRoundedRect;
         _textField.clearButtonMode = UITextFieldViewModeAlways;
         _textField.delegate = self;
-        _textField.inputDelegate = self;
+        [_textField addTarget:self action:@selector(textFieldChange:) forControlEvents:UIControlEventEditingChanged];
         [self.view addSubview:_textField];
     }
     return _textField;
 }
 
-
-- (BOOL)textFieldShouldReturn:(UITextField *)textField {
-    [self onDone:textField];
-    return YES;
-}
-
-#pragma mark - UITextInputDelegate
-- (void)textDidChange:(nullable id <UITextInput>)textInput {
+- (void)textFieldChange:(UITextField *)field {
     if (self.textField.text.length) {
         self.navigationItem.rightBarButtonItem.enabled = YES;
     } else {
@@ -124,19 +138,9 @@
     }
 }
 
-- (void)selectionDidChange:(nullable id<UITextInput>)textInput {
-    
-}
-
-
-- (void)selectionWillChange:(nullable id<UITextInput>)textInput {
-    
-}
-
-
-- (void)textWillChange:(nullable id<UITextInput>)textInput {
-
+- (BOOL)textFieldShouldReturn:(UITextField *)textField {
+    [self onDone:textField];
+    return YES;
 }
 
-
 @end

+ 2 - 1
wfuikit/WFChatUIKit/Me/WFCUMyProfileTableViewController.m

@@ -102,7 +102,8 @@
     qrview.image = qrcode;
     [cell addSubview:qrview];
 
-    cell = [self getAttrCell:@"账号" rightText:self.userInfo.name mutable:NO];
+    cell = [self getAttrCell:@"账号" rightText:self.userInfo.name mutable:YES];
+    cell.tag = 100;
     [self.cells1 addObject:cell];
 
     cell = [self getAttrCell:WFCString(@"Mobile") rightText:self.userInfo.mobile mutable:YES];

+ 2 - 0
wfuikit/WFChatUIKit/Utilities/WFCUAppServiceProvider.h

@@ -24,6 +24,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (void)showPCSessionViewController:(UIViewController *)baseController
                           pcClient:(WFCCPCOnlineInfo *)clientInfo;
+
+- (void)changeName:(NSString *)newName success:(void(^)(void))successBlock error:(void(^)(int errorCode, NSString *message))errorBlock;
 @end
 
 NS_ASSUME_NONNULL_END