tencent cloud

Feedback

JavaScript

Last updated: 2024-11-13 18:11:10

    Feature Description

    In some cases, you may need to mark a conversation, for example, as "favorite", "collapsed", "hidden", or "unread", which can be implemented through the following API.
    Note:
    To use this feature, you need to purchase the Premium edition.

    Display Effect

    

    Setting conversation custom data

    After successfully calling the API, the SDK will dispatch the event TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED.
    API
    chat.setConversationCustomData(options);
    Parameters
    The options parameter is of the Object type. It contains the following attribute values:
    Name
    Type
    Description
    conversationIDList
    String
    List of conversation IDs
    customData
    String
    Custom data, with a maximum length support of 256 bytes.
    Setting it to '' will clear the conversation custom data.
    Returned value
    Promise
    Sample
    let promise = chat.setConversationCustomData({
    conversationIDList: ['GROUPtest', 'C2Cexample'],
    customData: 'your custom data'
    });
    promise.then(function(imResponse) {
    const { successConversationIDList, failureConversationIDList } = imResponse.data;
    const conversationList = chat.getConversationList(successConversationIDList);
    failureConversationIDList.forEach((item) => {
    const { conversationID, code, message } = item;
    });
    }).catch(function(imError) {
    console.warn('setConversationCustomData error:', imError);
    });
    // clear the conversation custom data. let promise = chat.setConversationCustomData({
    conversationIDList: ['GROUPtest', 'C2Cexample'],
    customData: ''
    });
    promise.then(function(imResponse) {
    const { successConversationIDList, failureConversationIDList } = imResponse.data;
    const conversationList = chat.getConversationList(successConversationIDList);
    failureConversationIDList.forEach((item) => {
    const { conversationID, code, message } = item;
    });
    }).catch(function(imError) {
    console.warn('setConversationCustomData error:', imError);
    });

    Conversation Mark

    Call the markConversation API to mark or unmark a conversation.
    Note:
    1. When a user marks a conversation, the SDK simply records the mark value and does not change the underlying logic of the conversation. For example, marking a conversation as TencentCloud.TYPES.CONV_MARK_TYPE_UNREAD does not alter the unread count at the underlying layer.
    2. The SDK provides four default marks ("favorite", "collapsed", "hidden", and "unread"). If they cannot meet your requirements, you can customize extended marks, which must meet the following conditions:
    The value of an extended mark cannot be the same as that of an existing one.
    Custom mark values must be Math.power(2, n) (32 <= n < 64, meaning n must be greater than or equal to 32 and less than 64), for instance, a custom Math.power(2, 32) mark value represents "iPhone Online".
    API
    chat.markConversation(options);
    Parameters
    The options parameter is of the Object type. It contains the following attribute values:
    Name
    Type
    Description
    conversationIDList
    String
    List of conversation IDs
    markType
    Number
    Conversation mark type
    enableMark
    Boolean
    true: Mark.
    false: Unmark
    Returned value
    Promise
    Sample
    // Mark a conversation as "favorite"
    let promise = chat.markConversation({
    conversationIDList: ['GROUPtest', 'C2Cexample'],
    markType: TencentCloudChat.TYPES.CONV_MARK_TYPE_STAR,
    enableMark: true
    });
    promise.then(function(imResponse) {
    // Marked the conversation as "favorite" successfully
    const { successConversationIDList, failureConversationIDList } = imResponse.data;
    // successConversationIDList - List of conversations that were marked successfully
    // Get the conversation list
    const conversationList = chat.getConversationList(successConversationIDList);
    
    // failureConversationIDList - List of conversations that failed to be marked as "favorite"
    failureConversationIDList.forEach((item) => {
    const { conversationID, code, message } = item;
    });
    }).catch(function(imError){
    console.warn('markConversation error:', imError);
    });

    Listening for the notification of a conversation mark change

    After a conversation is marked or unmarked, the markList field in Conversation will change. You can listen for such a change notification through the TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED event.
    Sample
    let onConversationListUpdated = function(event) {
    console.log(event.data); // Array that stores Conversation instances
    };
    chat.on(TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED, onConversationListUpdated);

    Pulling a specified marked conversation

    Call the getConversationList API to pull a specified marked conversation.
    Sample
    // Obtain all conversations that are marked as "favorite"
    let promise = chat.getConversationList({ markType: TencentCloudChat.TYPES.CONV_MARK_TYPE_STAR });
    promise.then(function(imResponse) {
    const conversationList = imResponse.data.conversationList; // Conversation list
    });
    // Obtain all one-to-one conversations that are marked as "collapsed"
    let promise = chat.getConversationList({
    markType: TencentCloudChat.TYPES.CONV_MARK_TYPE_FOLD,
    type: TencentCloudChat.TYPES.CONV_C2C
    });
    promise.then(function(imResponse) {
    const conversationList = imResponse.data.conversationList; // Conversation list
    });
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support