User Management

To add User Management support in your application,
Include the class <MessageSDKFramework/CometChatCloud.h> in the .h file of your class.
All the method calls will invoke their respective callback blocks as defined below.

1. Initialize the CometChatCloud object

CometChatCloud *cometchatCloud =  [[CometChatCloud alloc] init];

2. Create user
Create a user with given userName and password. (Ensure that userName and password cannot be nil or empty)

- (void)createUser:(NSString *)userName 
       displayName:(NSString *)displayName 
          password:(NSString *)password 
              link:(NSString *)link 
            avatar:(NSString *)avatar 
           success:(void(^)(NSDictionary *response))success 
           failure:(void(^)(NSError *error))failure;

Parameters:
(i). userName: Name of the user
(ii). displayName: Explicit name of the user to be displayed
(iii). password: Password to login to CometChat
(iv). link: Link associated with the user
(v). avatar: Avatar of the user

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: After the user is created successfully.
Response: NSDictionary containing the status and the message
Eg:

{
   "status" = "1000";
   "message" = "User created successfully!";
   "data" = {
             "userid" = 28;
            }
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while creating user.
Response: NSError containing error code and message
Eg:

Error Domain=COMETCHAT CLOUD ERROR Code=1001 
      "Username already exists." UserInfo=0x7feeb26e0d90 
      {NSLocalizedDescription=Username already exists.} 

Usage:

[cometchatCloud createUser:@"Ruby Doe" 
           displayName:@"ruby" 
              password:@"123" 
                  link:@"" 
                avatar:@"" 
               success:^(NSDictionary *response) {
             } failure:^(NSError *error) {
}];

3. Update user details
Update any of the following user details. originalPassword is required to change any detail.(Ensure that originalPassword cannot be nil or empty)

- (void)updateDisplayName:(NSString *)displayName
                 password:(NSString *)newPassword
                    link:(NSString *)link
                  avatar:(NSString *)avatar
                  status:(NSInteger)status
           statusMessage:(NSString *)statusMessage
                   ofUser:(NSString *)userID
           withPassword:(NSString *)originalPassword
         setNULLValues:(BOOL)flag
                success:(void(^)(NSDictionary *response))success
                failure:(void(^)(NSError *error))failure;

Parameters:
(i). displayName: Display name of the user to be updated
(ii). newPassword: Password of the user to be updated
(iii). link: Link of the user to be updated
(iv). avatar: Avatar of the user to be updated
(v). status: Status of the user to be updated. Refer to enum STATUS_OPTIONS in for status options
(vi). statusMessage: Status message of the user to be updated.
(vii). userID: userID of the user whose details have to be updated. If userID is NULL then details of the logged-in user will be updated.
(viii). originalPassword: Current password of the user whose details have to be updated.
If userID is NULL then pass the logged-in user’s current password
(ix). flag: If flag = YES, NULL OR empty values i.e @”” passed will be updated to default/empty values
If flag = NO, NULL OR empty values i.e @”” passed will not be updated

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: After the user’s details have been updated successfully.
Response: NSDictionary containing the status and the message
Eg:

{
     "status" = "1000";
     "message" = "Details updated successfully!";
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while updating user’s details.
Response: NSError containing error code and message
Eg:

 Error Domain=COMETCHAT CLOUD ERROR Code=1003 "User not found." 
           UserInfo=0x7feeb26e0d90 {NSLocalizedDescription=User not found.}

Usage:
a) If you want to set only the status and status message

[cometchatCloud updateDisplayName:NULL 
                 password:NULL 
                    link:NULL 
                   avatar:NULL 
                   status:STATUS_AVAILABLE 
            statusMessage:@"Hi! I'm using CometChat." 
                   ofUser:NULL   
              withPassword:@"123" 
             setNULLValues:NO 
                   success:^(NSDictionary *response) {
                 } failure:^(NSError *error) {
}];

b) If you want to set the status and reset other values to default

[cometchatCloud updateDisplayName:NULL 
                 password:NULL 
                    link:NULL 
                   avatar:NULL 
                   status:STATUS_AVAILABLE 
            statusMessage:NULL 
                   ofUser:NULL   
              withPassword:@"123" 
             setNULLValues:YES 
                   success:^(NSDictionary *response) { 
                 } failure:^(NSError *error) {
}];

4. Remove user
a) Remove/Delete a user from CometChat by providing userID. (Ensure that userID cannot be nil or empty)

- (void)removeUserByID:(NSString *)userID
             success:(void(^)(NSDictionary *response))success
             failure:(void(^)(NSError *error))failure;

Parameters:
(i). userID: userID of the user to be removed/deleted
Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: After the user is removed successfully.
Response: NSDictionary containing the status and the message
Eg:

{
       "status" = "1000";
       "message" = "User deleted successfully!";
       "data" = {
                 "userid" = "28"
                }
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while removing user.
Response: NSError containing error code and message
Eg:

Error Domain=COMETCHAT CLOUD ERROR Code=1003 "User not found." 
          UserInfo=0x7feeb26e0d90 {NSLocalizedDescription=User not found.}

Usage:

[cometchatCloud removeUserByID:@"28" 
              success:^(NSDictionary *response) {
            } failure:^(NSError *error) {
}];

b) Remove/Delete a user from CometChat by providing userName. (Ensure that userName cannot be nil or empty)

- (void)removeUserByUserName:(NSString *)userName
        success:(void(^)(NSDictionary *response))success
        failure:(void(^)(NSError *error))failure;

Parameters:
(i). userName: userName of the user to be removed/deleted

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: After the user is removed successfully.
Response: NSDictionary containing the status and the message
Eg:

{
       "status" = "1000";
       "message" = "User deleted successfully!";
       "data" = {
                "userid" = "28"
                }
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while removing user.
Response: NSError containing error code and message
Eg:

Error Domain=COMETCHAT CLOUD ERROR Code=1003 "User not found." 
          UserInfo=0x7feeb26e0d90 {NSLocalizedDescription=User not found.}

Usage:

[cometchatCloud removeUserByName:@"28" 
             success:^(NSDictionary *response) {
           } failure:^(NSError *error) {
}];

5. Add friends
Add friends to logged-in user by providing array of user’s ID. (Ensure that userIDArray cannot be nil or empty)

- (void)addFriends:(NSArray *)userIDArray
         success:(void(^)(NSDictionary *response))success
         failure:(void(^)(NSError *error))failure;

Parameters:
(i). userIDArray : An array containing user’s ID who have to be added as friends

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: After the user/users have been added successfully.
Response: NSDictionary containing the status and the message
Eg:

{
      "status" = "1000";
      "message" = "Friends added successfully!";
      "data" = {
                "userid":"4"
               }
}

Here, data will contain the userID of only those users who have been added successfully

(ii) (void(^)(NSError *error))failure
Invocation: If there’s error while adding all user’s as friends
Response: NSError containing error code and message
Eg:

Error Domain=COMETCHAT CLOUD ERROR Code=1006 "Failed to add friends!" 
                 UserInfo=0x7fc561e3c8b0 {NSLocalizedDescription=Failed to add friends!, 
                data={type = immutable dict, count = 1, entries =>0 : {contents = "userid"} = {contents = "2,3,45"} } }

Usage:

[cometchatCloud addFriends:@[@"2",@"3",@"45"] 
               success:^(NSDictionary *response) {
             } failure:^(NSError *error) {
}];

6. Remove friends
Remove friends of logged-in user by providing array of user’s ID.(Ensure that userIDArray should not be nil or empty)

- (void)removeFriends:(NSArray *)userIDArray
           success:(void(^)(NSDictionary *response))success
           failure:(void(^)(NSError *error))failure;

Parameters:
(i). userIDArray: An array containing user’s ID who have to be removed as friends

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: After the user/users have been removed successfully.
Response: NSDictionary containing the status and the message
Eg:

{
       "status" = "1000";
       "message" = "Friends removed successfully!";
       "data" = {
                 "userid":"4"
               }
}

Here, data will contain the userid of only those users who have been removed successfully

(ii) (void(^)(NSError *error))failure
Invocation: If there’s error while removing all user’s as friends
Response: NSError containing error code and message
Eg:

Error Domain=COMETCHAT CLOUD ERROR Code=1006 "Failed to remove friends!" 
         UserInfo=0x7fc561e3c8b0 {NSLocalizedDescription=Failed to remove  friends!, 
         data={type = immutable dict, count = 1, entries =>0 : {contents = "userid"} = {contents = "2,3,45"} } }

Usage:

[cometchatCloud removeFriends:@[@"2",@"3",@"45"] 
       success:^(NSDictionary *response) {
     } failure:^(NSError *error) {
}];

Please refer ‎error codes for failure responses.

Not finding what you need?

The CometChat team is here to help!