chat.setConversationCustomData(options);
options
为 Object
类型,包含的属性值如下:参数 | 类型 | 说明 |
conversationIDList | String | 会话 ID 列表 |
customData | String | 自定义数据,长度最大支持256字节 |
Promise
// 给 C2C 会话和群会话设置会话自定义数据let promise = chat.setConversationCustomData({conversationIDList: ['GROUPtest', 'C2Cexample'],customData: 'your custom data'});promise.then(function(imResponse) {// 设置会话自定义数据成功const { successConversationIDList, failureConversationIDList } = imResponse.data;// successConversationIDList - 设置成功的会话 ID 列表// 获取会话列表const conversationList = chat.getConversationList(successConversationIDList);// failureConversationIDList - 设置失败的会话 ID 列表failureConversationIDList.forEach((item) => {const { conversationID, code, message } = item;});}).catch(function(imError) {console.warn('setConversationCustomData error:', imError);});
// customData 传入空字符串,表示清空会话自定义数据let promise = chat.setConversationCustomData({conversationIDList: ['GROUPtest', 'C2Cexample'],customData: ''});promise.then(function(imResponse) {// 清空会话自定义数据成功const { successConversationIDList, failureConversationIDList } = imResponse.data;// successConversationIDList - 清空成功的会话 ID 列表// 获取会话列表const conversationList = chat.getConversationList(successConversationIDList);// failureConversationIDList - 清空失败的会话 ID 列表failureConversationIDList.forEach((item) => {const { conversationID, code, message } = item;});}).catch(function(imError) {console.warn('setConversationCustomData error:', imError);});
chat.markConversation(options);
options
为 Object
类型,包含的属性值如下:参数 | 类型 | 说明 |
conversationIDList | String | 会话 ID 列表 |
markType | String | 会话标记类型 |
enableMark | Boolean | true 设置标记 false 取消标记 |
Promise
// 会话标星let promise = chat.markConversation({conversationIDList: ['GROUPtest', 'C2Cexample'],markType: TencentCloudChat.TYPES.CONV_MARK_TYPE_STAR,enableMark: true});promise.then(function(imResponse) {// 会话标星成功const { successConversationIDList, failureConversationIDList } = imResponse.data;// successConversationIDList - 标星成功的会话 ID 列表// 获取会话列表const conversationList = TencentCloudChat.getConversationList(successConversationIDList);// failureConversationIDList - 标星失败的会话 ID 列表failureConversationIDList.forEach((item) => {const { conversationID, code, message } = item;});}).catch(function(imError) {console.warn('markConversation error:', imError);});
markList
字段会发生变更,您可以通过事件 TencentCloud.EVENT.CONVERSATION_LIST_UPDATED 监听会话变更通知。let onConversationListUpdated = function(event) {console.log(event.data); // 包含 Conversation 实例的数组};tim.on(TencentCloudChat.EVENT.CONVERSATION_LIST_UPDATED, onConversationListUpdated);
// 获取所有的“标星”会话let promise = chat.getConversationList({ markType: TencentCloudChat.TYPES.CONV_MARK_TYPE_STAR });promise.then(function(imResponse) {const conversationList = imResponse.data.conversationList; // 会话列表});
// 获取所有折叠的 C2C 会话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; // 会话列表});
本页内容是否解决了您的问题?