logout
to log out.customStatus
field for your custom status. Once set successfully, you will receive a notification of your status change through the TIM.EVENT.USER_STATUS_UPDATED event. For more details, please refer to the status change notification below.customStatus
field to an empty string when calling the setSelfStatus
interface.setSelfStatus
does not require upgrading to the Advanced Edition, nor does it need the Console Switch to be turned on.chat.setSelfStatus(options);
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});
chat.getUserStatus(options);
Name | Type | Description |
userIDList | Array | List of userIDs to be queried. When querying yourself, you only need to pass your own userID. |
Promise
userIDList
to include only your own userID to query your own status.// 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.getUserStatus
will result in an error.// Query the status of other userslet 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});
subscribeUserStatus
will result in an error.chat.subscribeUserStatus(options);
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) {console.warn('subscribeUserStatus error:', imError); // Error information regarding the failure to subscribe to user status});
unsubscribeUserStatus
will result in an error.chat.unsubscribeUserStatus(options);
Name | Type | Description |
userIDList | Array | 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});
TIM.EVENT.USER_STATUS_UPDATED
, different types of users trigger this notification differently.TIM.EVENT.USER_STATUS_UPDATED
event, and you can get your latest status there.TIM.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 TIM.EVENT.USER_STATUS_UPDATED
callback.subscribeUserStatus
is supported only for advanced customers and requires the console switch to be enabled. For details, please refer to the Subscribe user status mentioned above.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 TIM.EVENT.USER_STATUS_UPDATED
callback will be triggered, and you can get their latest status there.subscribeUserStatus
is supported only for advanced customers and requires the console switch to be enabled. For details, please refer to the Subscribe user status mentioned above./*** 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);
TIM.EVENT.USER_STATUS_UPDATED
mentioned above, you can also proactively check the user's status. For more details, please refer to the previous section Check User Status.setSelfStatus
interface is not limited to the Advanced Edition.getUserStatus
to check your status is not limited to the Advanced Edition.getUserStatus
requires an upgrade to the Advanced Edition for queries other than checking your own status.subscribeUserStatus
/ unsubscribeUserStatus
interface require upgrading to the Advanced Edition.setSelfStatus
interface is not subject to rate limiting.getUserStatus
querying your status is not rate-limited.getUserStatus
, apart from querying your own status, is by default limited to 20 requests every 5 seconds, with a maximum of 500 users per query.subscribeUserStatus
interface, by default limited to 20 requests every 5 seconds, with a maximum of 100 users per subscription.unsubscribeUserStatus
interface, by default limited to 20 requests every 5 seconds, with a maximum of 100 users per single subscription cancellation.
Was this page helpful?