Web

圈组快捷评论

更新时间: 2024/03/14 19:21:13

快捷评论是一个操作功能,并非一种消息类型。评论内容并非一条消息,而是一个 number 类型,由开发者指定评论内容与界面展示之间的联系。

快捷评论的 UI 示例见下图。

前提条件

开始圈组快捷评论相关集成前,请确保:

  • 开通圈组的快捷评论功能。圈组的快捷评论功能需要在开通圈组功能的基础上额外开通后才能使用。
  • 已完成圈组初始化。

实现方法

添加/移除快捷评论

API 调用时序

uml diagram

具体流程

本节仅对上图中标为橙色的流程进行说明,其他流程请参考相关文档。例如:

  1. 用户A和用户B注册回调函数并登录。

    示例代码如下:

    注册消息接收事件回调
    const qchat = new QChat({
      // 初始化参数
    })
    qchat.on('message',(message)=>{})
    
    注册系统通知回调
    const qchat = new QChatSDK({
    ... 
    })
    qchat.on('systemNotification', function (systemNotification) {
    console.log('receive a systemNotification', systemNotification)
    })
    
    await qchat.login()
    
  2. 用户B在收到消息后,调用addQuickComment方法为接收到的消息添加快捷评论。调用成功后,系统通知回调触发,用户A收到系统通知。

    用户也可在搜索/查询消息后为消息添加快捷评论,本文仅以接收消息后添加快捷评论作为示例进行说明。

    云信服务端不会下发相关系统通知给发起“添加快捷评论”操作的设备,因为操作者不需要接收当前操作的通知。但如果操作者使用相同 IM 账号在其他设备登录,将收到该通知。


    假设接收者收到的消息的"msgIdServer" 为 "6358276",那么为该消息添加一条快捷评论 (type 为 1)的示例代码如下:

    await qchat.qchatMsg.addQuickComment({
    "commentMessage": {
        "fromAccount": "ctt1",
        "serverId": "1771109",
        "channelId": "1623869",
        "type": "text",
        "body": "星空444444",
        "fileInput": "external-file",
        "msgIdClient": "0002bac24b2e2cac4c999d6ad77c392e",
        "fromClientType": "Web",
        "fromDeviceId": "c19b2572e36ed6d0f3c55d916b52371f",
        "fromNick": "ctt1",
        "time": 1649768937125,
        "updateTime": 1649768937125,
        "msgIdServer": "6358276",
        "status": 0,
        "callbackExt": "callbackext123",
        "historyEnable": true,
        "pushEnable": true,
        "needBadge": true,
        "needPushNick": true,
        "routeEnable": true,
        "deliveryStatus": "success"
    },
    "type": 1
    })
    
  3. (可选)用户B调用removeQuickComment 方法移除快捷评论。调用成功后,快捷评论移除并触发系统通知回调。

    云信服务端不会下发相关系统通知给发起“移除快捷评论”操作的设备,因为操作者不需要接收当前操作的通知。但如果操作者使用相同 IM 账号在其他设备登录,将收到该通知。


    示例代码如下:

    await qchat.qchatMsg.removeQuickComment({
    "commentMessage": {
        "fromAccount": "ctt1",
        "serverId": "1771109",
        "channelId": "1623869",
        "type": "text",
        "body": "星空444444",
        "fileInput": "external-file",
        "msgIdClient": "0002bac24b2e2cac4c999d6ad77c392e",
        "fromClientType": "Web",
        "fromDeviceId": "c19b2572e36ed6d0f3c55d916b52371f",
        "fromNick": "ctt1",
        "time": 1649768937125,
        "updateTime": 1649768937125,
        "msgIdServer": "6358276",
        "status": 0,
        "callbackExt": "callbackext123",
        "historyEnable": true,
        "pushEnable": true,
        "needBadge": true,
        "needPushNick": true,
        "routeEnable": true,
        "deliveryStatus": "success"
    },
    "type": 1
    })
    

查询快捷评论列表

调用getQuickComments可查询指定消息所包含的快捷评论列表。

返回的内容包含 key 为 msgIdServer 的多个对象,指定消息的服务器 ID(serverId)、频道 ID(channelId)、服务器消息 ID(msgIdServer)、总评论数(totalCount)、消息评论最后一次操作的时间(lastUpdateTime)以及每个快捷评论的详情(details)。

其中details的数据类型为 QChatQuickCommentDetail[],具体的参数说明如下:

参数 类型 说明
type number 评论类型
hasSelf boolean 自己是否添加了该类型评论
count number 总评论数
createTime number 消息评论的创建时间
severalAccids string[] 随即抽取若干个添加了此类型评论的用户 ID (accid)的列表

示例代码如下:

const result = await qchat.qchatMsg.getQuickComments({
  "serverId": "1771109",
  "channelId": "1623869",
  "msgList": [{
    "fromAccount": "ctt1",
    "serverId": "1771109",
    "channelId": "1623869",
    "type": "text",
    "body": "星空444444",
    "fileInput": "external-file",
    "msgIdClient": "0002bac24b2e2cac4c999d6ad77c392e",
    "fromClientType": "Web",
    "fromDeviceId": "c19b2572e36ed6d0f3c55d916b52371f",
    "fromNick": "ctt1",
    "time": 1649768937125,
    "updateTime": 1649768937125,
    "msgIdServer": "6358276",
    "status": 0,
    "callbackExt": "callbackext123",
    "historyEnable": true,
    "pushEnable": true,
    "needBadge": true,
    "needPushNick": true,
    "routeEnable": true,
    "deliveryStatus": "success"
  }]
})

console.log(result["6358276"].totalCount)

API 参考

API
说明
message 消息接收事件回调函数
systemNotification 系统通知接收回调函数
addQuickComment 添加快捷评论
removeQuickComment 移除快捷评论
getQuickComments 查询指定消息包含的快捷评论列表
此文档是否对你有帮助?
有帮助
去反馈
  • 前提条件
  • 实现方法
  • 添加/移除快捷评论
  • API 调用时序
  • 具体流程
  • 查询快捷评论列表
  • API 参考