评论组件

优质
小牛编辑
119浏览
2023-12-01

Mudu.Room.Comment 评论组件

获取评论页数

// 返回评论页数,类型为int
var commentPage = Mudu.Room.Comment.GetPage()

发送评论

Mudu.Room.Comment.Send(
  // 要发送的评论文本,类型为string
  '活动很赞很给力',

  // 发送完成的回调函数,参数为response对象
  function (response) {
    response = JSON.parse(response)
    if (response.status === 'y') {
      console.log('发送成功')
    }
    if (response.status === 'n') {
      console.log('发送失败,错误码为:' + response.flag)
    }
  }
)
  • response对象说明
{
  // 成功状态,类型为string,成功时为'y',失败时为'n'
  status: 'y',

  // 状态码码,类型为int,成功时为0,失败不为0
  flag: 100,

  // 信息,类型为string,成功时为'发送消息成功!',失败时为'发送消息失败!'
  info: "发送消息成功!/失败!"
}
  • flag状态码码对照表
flaginfostatus
100发送消息成功y
101管理员禁止了聊天n
102观众被禁言n
103发送失败n
104禁止匿名聊天n

获取评论

Mudu.Room.Comment.Get(
  // 要获取评论的页码,类型为int
  2,

  // 评论获取成功的回调函数,参数为response对象
  function (response) {
    response = JSON.parse(response)
    if (response.status === 'y') {
      console.log('获取评论成功,数据为:', response.data)
    } 
    if (response.status === 'n'){
      console.log('获取评论失败')
    }
  }
)
  • response返回结果说明
{
    // 状态
    "status": 'y',

    // 返回的数据
    "data": {
      // 还剩下多少页
      page: 70,

      // 获取到的评论
      comments: [
        {
          "id": 3438056,
          "visitor_id": "1493401897797743654_api",
          "username": "小白白",
          "message": "这个真不错",
          "avatar": "https://www.xnip.cn/wp-content/uploads/2021/docimg28/32-xzj0vbhvei4.jpg",
          "dateline": "2020-04-16T15:56:00+08:00",
          "pushed": 1,
          "priority": 10,
          "top": 0,
          "msg_type": 10,
          "is_admin": 0
        },
        ......
      ]
    },
}
  • comments说明
名称说明类型
id评论idint
visitor_id观众标志string
username评论者的观众名string
message评论的文本string
avatar评论这个的头像string
dateline评论时间字符串
pushed是否已经发送了弹幕,0未发送,1已发送int
priority优先级 ,0 未审核,10已审核,时间戳(置顶时间)int
top是否置顶 ,0 不置顶,1置顶int
msg_type消息来源类型, 10为普通文本消息...,详情见下表int
is_admin是否为管理员发送, 1是, 0不是int
  • msg_type 和 message之间的映射关系
类型标志位(msg_type)存储类型示例(message)备注
普通评论10字符串"真香"表情替换
发送普通红包20字符串json'{"id":"nm4dk9jm", "type":1, "name":"恭喜发财!大吉大利!", }'type 2:钉钉
发送口令红包21字符串json'{"id":"nm4dk9jm", "type":1, "name":"恭喜发财!大吉大利!"}'type 2:钉钉
发送竞答红包22字符串json'{"id":"nm4dk9jm", "name":"参与竞答领取红包!"}'
发送竞答红包(自定义)23字符串json'{"id":"nm4dk9jm", "name":"参与竞答领取红包!"}'
抢口令红包评论31字符串"大吉大利,今晚吃鸡"
免费道具打赏40字符串json'{"src":"https://xxx.com/a.jpg". "name":"免费道具", "number":1 }'
付费道具打赏41字符串json'{"src":"https://xxx.com/c.jpg". "name":"付费道具", "number":88 }'
现金打赏42字符串json'{"name":"赏赐", "amount":88.99 }'
图片评论50字符串"https://xxx.com/abc.jpg"

Comment.New事件

Comment.New事件会在评论新增的时候被触发

Mudu.MsgBus.On(
  // 事件名,值为Comment.New
  'Comment.New', 

  // 事件处理函数,参数为新的评论,类型为object
  function (newComment) {
    newComment = JSON.parse(newComment) // newComment 结构见页面底部
    console.log(newComment.username + '发送了一条新评论: ' + newComment.message)
  }
)

Comment.Top事件

Comment.Top事件会在评论置顶/取消置顶时触发

Mudu.MsgBus.On(
  // 事件名,值为Comment.Top
  'Comment.Top', 

  // 事件处理函数,参数为新的评论,类型为object
  function (newComment) {
    newComment = JSON.parse(newComment) // newComment 结构见页面底部
    console.log('一条评论被' + (newComment.top === 1 ? '置顶' : '取消置顶') + '了');
  }
)

Comment.Delete事件

Comment.Delete事件会在评论被管理员删除时触发

Mudu.MsgBus.On(
  // 事件名,值为Comment.Delete
  'Comment.Delete', 

  // 事件处理函数,参数为被删除的评论,类型为object
  function (newComment) {
    newComment = JSON.parse(newComment) // newComment 结构见页面底部
    console.log('一条评论被删除了');
  }
)
  • 事件处理函数参数newComment对象说明
名称说明类型
id评论idint
visitor_id观众标志string
username评论者的观众名string
message评论的文本string
avatar评论这个的头像string
dateline评论的时间戳int
pushed是否已经发送了弹幕,0未发送,1已发送int
priority优先级 ,0 未审核,10已审核,时间戳(置顶时间)int
top是否置顶 ,0 不置顶,1置顶int
msg_type消息来源类型, 10为普通文本消息...,详情见上表int
is_admin是否为管理员发送, 1是, 0不是int