TencentCloudChat.TYPES.USER_STATUS_ONLINE
): The current user has logged in and is online, can send and receive messages normally.TencentCloudChat.TYPES.USER_STATUS_OFFLINE
): Web login/logout will not trigger offline status. In apps integrating Native IMSDK, offline status will be triggered.TencentCloudCha
t.TYPES.USER_STATUS_UNLOGINED): The user has never logged in after registering an account, or the user proactively called logout
to log out.setSelfStatus
to set the customStatus
field for your custom status. Once set successfully, you will receive a notification of your status change through the TencentCloudChat.EVENT.USER_STATUS_UPDATED
event. setSelfStatus
does not require upgrading to the Premium edition, nor does it need the Console Switch to be turned on.customStatus
field to an empty string when calling the setSelfStatus
interface.chat.setSelfStatus(options);
options
parameter is of the Object
type, and contains the following attribute values:Name | Type | Description |
customStatus | String | User Custom Status |
Promise
// Set customStatus to an empty string '', this will clear your custom statuslet promise = chat.setSelfStatus({customStatus: 'xxx'});promise.then(function(imResponse) {console.log(imResponse.data);const { userID, statusType, customStatus } = imResponse.data;// userID - User ID// statusType - User status. The enumerated values and descriptions are as follows:// TencentCloudChat.TYPES.USER_STATUS_UNKNOWN - Unknown// TencentCloudChat.TYPES.USER_STATUS_ONLINE - Online// TencentCloudChat.TYPES.USER_STATUS_OFFLINE - Offline// TencentCloudChat.TYPES.USER_STATUS_UNLOGINED - Not Logged In// customStatus - User Custom Status}).catch(function(imError) {console.warn('setSelfStatus error:', imError); // Failed to set user's custom status});
getUserStatus
will result in an error.chat.getUserStatus(options);
options
parameter is of the Object
type, and contains the following attribute values:Name | Type | Description |
userIDList | Array | List of userIDs to be queried. When querying yourself, you only need to pass your own userID. |
Promise
// Check your own user status// userIDList includes only your own userID to query your own statuslet promise = chat.getUserStatus({userIDList: [`${myUserID}`]});promise.then(function(imResponse) {const { successUserList } = imResponse.data;successUserList.forEach((item) => {const { userID, statusType, customStatus } = item;// userID - User ID// statusType - User status, the enumerated values and descriptions are as follows:// TencentCloudChat.TYPES.USER_STATUS_UNKNOWN - Unknown// TencentCloudChat.TYPES.USER_STATUS_ONLINE - Online// TencentCloudChat.TYPES.USER_STATUS_OFFLINE - Offline// TencentCloudChat.TYPES.USER_STATUS_UNLOGINED - Not Logged In// customStatus - User Definition Status});}).catch(function(imError) {console.warn('getUserStatus error:', imError); // Failed to obtain user status});
userIDList
to the userID list of others to check their status.// Query the status of otherslet promise = chat.getUserStatus({userIDList: ['user0', 'user1']});promise.then(function(imResponse) {const { successUserList, failureUserList } = imResponse.data;// List of users with successful queriessuccessUserList.forEach((item) => {const { userID, statusType, customStatus } = item;// userID - User ID// statusType - User status, the enumerated values and descriptions are as follows:// TencentCloudChat.TYPES.USER_STATUS_UNKNOWN - Unknown// TencentCloudChat.TYPES.USER_STATUS_ONLINE - Online// TencentCloudChat.TYPES.USER_STATUS_OFFLINE - Offline// TencentCloudChat.TYPES.USER_STATUS_UNLOGINED - Not Logged In// customStatus - User Definition Status});// List of users with failed queriesfailureUserList.forEach((item) => {const { userID, code, message } = item;// userID - User ID of the failed query// code - Error code of the failed query// message - Error message of the failed query});}).catch(function(imError) {console.warn('getUserStatus error:', imError); // Failed to obtain user status});
TencentCloudChat.EVENT.USER_STATUS_UPDATED
event.chat.subscribeUserStatus(options);
options
parameter is of the Object
type, and contains the following attribute values:Name | Type | Description |
userIDList | Array | List of user userID, up to 100 per request. |
Promise
let promise = chat.subscribeUserStatus({userIDList: ['user0', 'user1']});promise.then(function(imResponse) {const { failureUserList } = imResponse.data;// List of users with failed subscriptionsfailureUserList.forEach((item) => {const { userID, code, message } = item;// userID - User ID of the failed query// code - Error code of the failed query// message - Error message of the failed query});}).catch(function(imError) {// Error information regarding the failure to subscribe to user statusconsole.warn('subscribeUserStatus error:', imError);});
TencentCloudChat.EVENT.USER_STATUS_UPDATED
event.chat.unsubscribeUserStatus(options);
Name | Type | Description |
userIDList | Array | undefined | List of user IDs, with a maximum of 100 per single request. When userIDList is an empty array or undefined , it cancels all current subscriptions. |
Promise
// Unsubscribe current partial userslet promise = chat.unsubscribeUserStatus({userIDList: ['user0', 'user1']});promise.then(function(imResponse) {const { failureUserList } = imResponse.data;// List of users with failed unsubscriptionsfailureUserList.forEach((item) => {const { userID, code, message } = item;// userID - User ID of the failed query// code - Error code of the failed query// message - Error message of the failed query});}).catch(function(imError) {console.warn('unsubscribeUserStatus error:', imError); // Information related to the unsubscription failure});
// Unsubscribe from all current subscriptionslet promise = chat.unsubscribeUserStatus();promise.then(function(imResponse) {const { failureUserList } = imResponse.data;// List of users with failed unsubscriptionsfailureUserList.forEach((item) => {const { userID, code, message } = item;// userID - User ID of the failed query// code - Error code of the failed query// message - Error message of the failed query});}).catch(function(imError) {console.warn('unsubscribeUserStatus error:', imError); // Information related to the unsubscription failure});
TencentCloudChat.EVENT.USER_STATUS_UPDATED
event listener, when your own status changes, the SDK will dispatch the TencentCloudChat.EVENT.USER_STATUS_UPDATED
event, and you can get your latest status there.TencentCloudChat.EVENT.USER_STATUS_UPDATED
event, and you can get your friend's latest status there.subscribeUserStatus
to actively subscribe to the friend's status. When the friend's status changes, the SDK will dispatch the TencentCloudChat.EVENT.USER_STATUS_UPDATED
callback.subscribeUserStatus
to actively subscribe to friend status, then when a friend's status changes, you will not be able to perceive it.subscribeUserStatus
to actively subscribe. When that user's status changes, the TencentCloudChat.EVENT.USER_STATUS_UPDATED
callback will be triggered, and you can get their latest status there./*** Scenarios for receiving notifications:* 1. When a subscribed user's status changes (including online status and user-defined status), this event will be triggered* 2. If the Friend Status Notification Switch is enabled in the console, even if you haven't actively subscribed, this event will be triggered when a friend's status changes* 3. When the same account logs in to multiple devices, if one device modifies the user-defined status, all devices will receive this event*/let onUserStatusUpdated = function(event) {console.log(event.data);const userStatusList = event.data;userStatusList.forEach((item) => {const { userID, statusType, customStatus } = item;// userID - User ID// statusType - User status, the enumerated values and descriptions are as follows:// TencentCloudChat.TYPES.USER_STATUS_UNKNOWN - Unknown// TencentCloudChat.TYPES.USER_STATUS_ONLINE - Online// TencentCloudChat.TYPES.USER_STATUS_OFFLINE - Offline// TencentCloudChat.TYPES.USER_STATUS_UNLOGINED - Not Logged In// customStatus - User Definition Status})};chat.on(TencentCloudChat.EVENT.USER_STATUS_UPDATED, onUserStatusUpdated);
Was this page helpful?