Web

圈组系统通知更新

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

NIM SDK 支持更新已发送的圈组系统通知。

功能介绍

用户可通过 QChatMsgServiceInterface 中的 updateSystemNotification 方法更新圈组系统通知的部分信息,如系统通知中的内容、自定义扩展字段等。

支持更新的圈组系统通知类型如下表所示:

系统通知分类 ESystemMessageType 的枚举值 相关限制
内置系统通知 邀请服务器成员 serverMemberInvite 默认自动存离线。这四种通知每月总共至多存 1000 条离线,超限后将无法更新通知的信息
拒绝邀请 serverMemberInviteReject
申请加入服务器 serverMemberApply
拒绝申请 serverMemberApplyReject
自定义系统通知 custom 只有存离线的自定义系统通知才能更新。每月至多存 1000 条离线,超限后将无法更新通知的信息
  • 只有指明通知接收者的自定义系统通知才能设置存离线,即圈组系统通知对象的 toAccids 不为空。
  • 其他内置系统通知,不支持更新。具体的内置系统通知类型,请参见内置系统通知类型

实现方法

本文以服务器所有者(即创建者)和服务器成员的交互为例,介绍服务器成员更新圈组自定义系统通知和内置系统通知的实现流程。

前提条件

如果用户所在服务器的成员人数超过 2000 人阈值,该用户还需先订阅相应的服务器或频道,才能收到对应服务器或频道的系统通知。如未超过该阈值,则无需订阅。订阅相关说明,请参见圈组订阅机制

实现流程

圈组自定义系统通知更新
uml diagram
圈组内置系统通知更新
uml diagram

以下只对部分重要步骤进行说明:

  1. 服务器成员在初始化时注册 systemNotificationsystemNotificationUpdate 分别监听圈组系统通知接收和圈组系统通知更新状态。

示例代码:

const qchat = new QChatSDK({
  ... 
})
qchat.on('systemNotification', function (systemNotification) {
  console.log('receive a systemNotification', systemNotification)
})
qchat.on('systemNotificationUpdate', function (systemNotification) {
  console.log('receive a systemNotificationUpdate', systemNotification)
})

await qchat.login()
  1. 服务器所有者通过调用 sendSystemNotification 发送圈组自定义系统通知。发送的圈组自定义系统通知需要存离线,并指明通知对象,即圈组系统通知的 persistEnable 设置为 truetoAccids 不为空。

示例代码:

await qchat.qchatMsg.sendSystemNotification({
  "serverId": "{{YOUR_SERVER_ID}}",
  "toAccids": ["YOUR_ACCOUNT_ID1", "YOUR_ACCOUNT_ID2"],
  "persistEnable": true,
  "body": "notify some member from server"
})
  1. 服务器成员收到来自服务器所有者的系统通知。

  2. 服务器成员调用 updateSystemNotification 更新圈组系统通知。

其中 UpdateSystemNotificationOptions 是更新圈组系统通知的入参,必须传入系统通知服务端 ID msgIdServer(全局唯一)、系统通知类型 type,选填 bodyextstatus,作为可更新的内容。

示例代码:

let notification = await qchat.qchatMsg.sendSystemNotification({
  "serverId": "{{YOUR_SERVER_ID}}",
  "body": "notify all member from server"
})

notification = await qchat.qchatMsg.updateSystemNotification({
  "msgIdServer": notification.msgIdServer,
  "type": notification.type,
  "body": "I Change the notification"
})
  1. 服务器成员收到更新后的圈组系统通知。

API 参考

API 说明
systemNotification 圈组系统通知接收事件
systemNotificationUpdate 圈组系统通知更新事件
UpdateSystemNotificationOptions 更新圈组系统通知
此文档是否对你有帮助?
有帮助
去反馈
  • 功能介绍
  • 实现方法
  • 前提条件
  • 实现流程
  • API 参考