Users
This section contains the User operations that can be performed using JavaScript SDKs i.e Add/remove friends or following, block user, unblock user, update a user profile, get a list of friends/followers, etc.
Get User
You can retrieve information of a user using this method.
channelize.User.get(userId, function (err, user) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
userId | string | The unique ID of the user. |
Callback Params
err
Indicates if there is any error. It will be null if there is no error.user
Indicates user's object.
Create User
You can create a new user using this method.
channelize.User.createUser(data, function (err, user) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Required | Description |
---|---|---|---|
data | object | yes | Basic data of the user |
Data Object Keys
Below table lists all possible keys of above data param.
Name | Type | Required | Description |
---|---|---|---|
id | string | no | Unique id of the user. |
displayName | string | yes | Unique name of the user. |
string | no | Unique email of the user. | |
password | string | no | The login password of the user. |
language | string | no | Specifies the code of language to translate the text phrases used in User Interface. |
profileImageUrl | string | no | The URL of user's profile image. |
profileUrl | string | no | The unique URL of user's profile. |
createdAt | string | no | The timestamp when the user was created. |
Callback Params
err
Indicates if there is any error. It will be null if there is no error.user
Indicates user's object.
Get Current User
You can get login/current user object using this method.
const user = channelize.getCurrentUser(); // returns user's model.
console.log(user.toJSON()) // this will log all the properties of login user.
Add a Friend
Channelize.io allows a user to maintain two types of relationships with another user i.e Friendship and Following. This method allows a user to add another user as a friend or start following him. Type of relationships supported:
- One-way friendship i.e. Follow
- Two-way friendship
channelize.User.addFriend(userId, type, function (err, res) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Required | Default | Description |
---|---|---|---|---|
userId | string | yes | - | The unique ID of the user to whom logged-in user wants to send friendship or follow request. |
type | number | no | 2 | Specifies the type of relationship request to send. Acceptable values are 1 and 2. If set to 1, the follow request will send. If set to 2, friendship request will send. |
Callback Params
err
Indicates if there is any error. It will be null if there is no error.res
Indicates the response. It will be a null value in this case.
Remove Friend
This method allows a user to remove another user from his friends list or following list.
channelize.User.removeFriend(userId, type, function (err, res) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Required | Default | Description |
---|---|---|---|---|
userId | string | yes | - | The unique ID of the user to be removed from logged-in user's friends list or following list. |
type | number | no | 2 | Specifies the type of relationship request to send. Acceptable values are 1 and 2. If set to 1, the follow request will send. If set to 2, friendship request will send. |
Callback Params
err
Indicates if there is any error. It will be null if there is no error.res
Indicates the response. It will be a null value in this case.
Block a User
This method let a user to block another user. Blocked users can send messages to the blocker, however, the blocker will not recieve any message from the blocked user. Also, blocking someone doesn't alert them that they have been blocked.
channelize.User.block(userId, function (err, res) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
userId | string | The unique ID of the user to block. |
Callback Params
err
Indicates if there is any error. It will be null if there is no error.res
Indicates the response. It will be a null value in this case.
Unblock a User
This method allows a user to remove another user from his blocked list.
channelize.User.unblock(userId, function (err, res) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
userId | string | The unique ID of the user to unblock. |
Callback Params
err
Indicates if there is any error. It will be null if there is no error.res
Indicates the response. It will be a null value in this case.
Check Relationship Status
This method allows a user to get the relationship status with another user.
channelize.User.checkRelationshipStatus(userId, function (err, res) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
userId | string | The unique ID of the user with whom we want to get relationship status. |
Callback Params
err
Indicates if there is any error. It will be null if there is no error.res
Indicates the response. It will be a null value in this case.
Get Friends
Retrieves a list of all friends of the logged-in user. You can get friends using the UserListQuery instance. You can also set various parameters in the UserListQuery instance. None of the parameters in the UserListQuery instance is mandatory.
let userListQuery = channelize.User.createUserListQuery();
// boolean - Restricts the search scope to only retrieve online or offline users. If set to false, offline users are returned. If set to true, online users are returned in the response. (Default: null)
userListQuery.online = true;
// string - Searches for users whose display name matches the specified value. (Default: null)
userListQuery.search = 'Demo User';
// string - Specifies the sorting criteria for the returned results. Allowed values are displayName ASC and displayName DESC. (Default: displayName ASC).
userListQuery.sort = 'displayName ASC';
// number - Specifies the number of results to return. (Default: 50)
userListQuery.limit = 50;
// number - Specifies the number of results you want to skip from the beginning. (Default: 0)
userListQuery.skip = 0;
// boolean - Determines whether to include blocked users in the response list. (Default: true)
userListQuery.includeBlocked = true;
// string ( comma separated user IDs ) - Specifies the user IDs you want to skip.
userListQuery.skipUserIds = "10245,20141";
userListQuery.friendsList(function (err, users) {
});
Callback Params
err
Indicates if there is any error. It will be null if there is no error.users
Indicates the response which will be an array of user's object.
Get Friends Count
Retrieves the total number of users in friends or followings list.
let userListQuery = channelize.User.createUserListQuery();
// boolean - Restricts the search scope to only retrieve online OR offline users. If set to false, offline users are returned. If set to true, online users are returned in the response. (Default: null)
userListQuery.online = true;
// string - Add the count of the users whose display name matches the specified value. (Default: null)
userListQuery.search = 'Channelize Demo User';
// boolean - Restricts the search scope to include the count of blocked users on the list.
userListQuery.includeBlocked = true;
// string ( comma separated user IDs ) - Specifies the user IDs you want to skip.
userListQuery.skipUserIds = "10245,20141";
userListQuery.friendsCount(function (err, res) {
});
Callback Params
err
Indicates if there is any error. It will be null if there is no error.res
Indicates response object having count as property.{ "count": 15 }
Get Blocked Users
Retrieves the list of all blocked users.
let userListQuery = channelize.User.createUserListQuery();
// boolean - Restricts the search scope to only retrieve online OR offline users. If set to false, offline users are returned. If set to true, online users are returned in the response. (Default: null)
userListQuery.online = true;
// string - Searches for users whose display name matches the specified value. (Default: null)
userListQuery.search = 'Channelize Demo User';
// number - Specifies the number of results to return.
userListQuery.limit = 25;
// number - Specifies the number of results you want to skip from the beginning.
userListQuery.skip = 0;
userListQuery.blocksList(function (err, users) {
});
Callback Params
err
Indicates if there is any error. It will be null if there is no error.users
Indicates the response which will be an array of user's object.
Get Blocked Users Count
Retrieves the total number of users in the blocked list.
let userListQuery = channelize.User.createUserListQuery();
// boolean - Restricts the search scope to only retrieve online or offline users count. If set to false, offline users count is returned. If set to true, online users count is returned in the response.
userListQuery.online = true;
// string - Returns the count of users whose display name matches the specified value.
userListQuery.search = 'Demo User';
userListQuery.blocksCount(function (err, res) {
});
Callback Params
err
Indicates if there is any error. It will be null if there is no error.res
Indicates response object having count as property.{ "count": 6 }
User Model Object
A user's object can be retrieved either using the get user method or through various services methods. The user's object has below properties.
{
"createdAt":"2018-05-25T11:52:40.000Z",
"displayName":"Channelize Demo User",
"email":"demo99@channelize.io",
"id":"20697",
"isOnline": true,
"language":"en",
"lastActivity":"2019-05-23T05:00:03.572Z",
"lastLogin":"2019-05-23T05:00:03.570Z",
"lastSeen":"2019-05-23T04:59:20.753Z",
"notification" : true,
"profileImageUrl":"http://mobiledemodevelopment.s3.amazonaws.com/public/user/33/19/02/b5ceb45b2d6c74e4fc89673a5675c09c.jpg",
"profileUrl":"http://xyz.com/profile/demo99",
"updatedAt":"2018-05-25T11:52:40.000Z",
"visibility" : true
}
You can call various functions through this user model object directly. These functions are mentioned below:
Update User
Updates information of a user.
channelize.User.get(userId, function (err, user) {
if (err) return console.error(err);
user.updateInfo(data, function (err, updatedUser) {
});
});
Function Params
data will be the JavaScript object which will have the below properties. None of these properties are mandatory.
Name | Type | Description |
---|---|---|
displayName | string | The user's name. |
isOnline | string | Indicates if user is online or offline. |
language | string | Specifies the code of language to translate the text phrases used in user interface. |
notification | string | Indicates if notifications are enabled for user. |
profileImageUrl | string | The URL of user's profile image. |
profileUrl | string | The unique URL of user's profile. |
visibility | string | Indicates if user is visible. |
Callback Params
err
Indicates if there is any error. It will be null if there is no error.updatedUser
Indicates updated user's object.
Update Profile Photo
Updates profile photo of a user using its object.
<input type="file" id="profile">
channelize.User.get(userId, function (err, user) {
if (err) return console.error(err);
let file = document.getElementById('profile').files[0];
user.updateProfilePhoto(file, function (err, updatedUser) {
});
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
file | fileobject | Specifies the file object. |
Callback Params
err
Indicates if there is any error. It will be null if there is no error.updatedUser
Indicates updated user's object.
Get All Users List
This method provides a list of all users.
let userListQuery = channelize.User.createUserListQuery();
// boolean - Restricts the search scope to only retrieve online or offline users. If set to false, offline users are returned. If set to true, online users are returned in the response. (Default: null)
userListQuery.online = true;
// string - Searches for users whose display name matches the specified value. (Default: null)
userListQuery.search = 'Demo User';
// string - Specifies the sorting criteria for the returned results. Allowed values are displayName ASC and displayName DESC. (Default: displayName ASC).
userListQuery.sort = 'displayName ASC';
// number - Specifies the number of results to return. (Default: 50)
userListQuery.limit = 50;
// number - Specifies the number of results you want to skip from the beginning. (Default: 0)
userListQuery.skip = 0;
userListQuery.usersList(function (err, users) {
});
Callback Params
err
Indicates if there is any error. It will be null if there is no error.users
Indicates array of all users.