Windows/macOS

圈组系统通知更新

更新时间: 2024/03/12 10:20:50

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

功能介绍

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

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

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

实现方法

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

前提条件

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

实现流程

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

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

  1. 服务器成员在登录圈组前,调用 RegRecvCbRegUpdatedCb 分别监听圈组系统通知接收和圈组系统通知更新状态。

    示例代码:

    监听圈组系统通知接收
    QChatRegRecvSystemNotificationCbParam reg_receive_sysmessage_cb_param;
    reg_receive_sysmessage_cb_param.cb = [this](const QChatRecvSystemNotificationResp& resp) {
        if (resp.res_code != NIMResCode::kNIMResSuccess) {
            // error handling
            return;
        }
        // process response
        // ...
    };
    SystemNotification::RegRecvCb(reg_receive_sysmessage_cb_param);
    
    圈组系统通知更新状态
    QChatRegSystemNotificationUpdatedCbParam reg_notification_updated_cb_param;
    reg_notification_updated_cb_param.cb = [this](const QChatSystemNotificationUpdatedResp& resp) {
        if (resp.res_code != NIMResCode::kNIMResSuccess) {
            // error handling
            return;
        }
        // process response
        // ...
    };
    SystemNotification::RegUpdatedCb(reg_notification_updated_cb_param);
    
  2. 服务器所有者调用 Send 发送圈组自定义系统通知。发送的圈组自定义系统通知需要存离线,并指明通知对象,即圈组系统通知的 history_enabletrueto_accids 不为空。

    示例代码:

    QChatSendSystemNotificationParam param;
    param.notification.server_id = 123456;
    param.notification.channel_id = 123456;
    param.notification.msg_type = kNIMQChatSystemNotificationTypeCustom;
    param.notification.msg_body = "msg body";
    param.notification.msg_attach = "msg attach";
    param.notification.msg_ext = "msg ext";
    param.notification.resend_flag = false;
    param.notification.msg_id = ""; // only for resend. if not, leave it empty, we will generate it
    param.notification.to_accids = {"accid1", "accid2"};
    param.notification.history_enable = true;
    param.notification.push_payload = "push payload";
    param.notification.push_content = "push content";
    param.notification.push_enable = false;
    param.notification.need_badge = true;
    param.notification.need_push_nick = true;
    param.cb = [this](const QChatSendSystemNotificationResp& resp) {
        if (resp.res_code != NIMResCode::kNIMResSuccess) {
            // error handling
            return;
        }
        // process response
        // ...
    };
    SystemNotification::Send(param);
    
  3. 服务器成员收到来自服务器所有者的系统通知。

  4. 服务器成员调用 Update 更新圈组系统通知。其中 QChatUpdateSystemNotificationParam 是更新圈组系统通知的入参,参数说明如下:

    参数 说明
    msg_server_id 系统通知服务器 ID,全局唯一
    msg_type 系统通知类型,具体请参见NIMQChatSystemNotificationType
    status 系统通知状态,具体请参见NIMQChatSystemNotificationStatus仅自定义系统通知类型才可以更改状态值,且必须大于等于 10,000,否则会返回 414 错误码
    msg_body 系统通知内容
    msg_ext 系统通知扩展字段
    update_info 更新内容,包括推送相关,是否抄送等字段,具体请参见QChatMessageUpdateInfo
    cb 更新系统通知的回调

    示例代码:

    QChatUpdateSystemNotificationParam param;
    param.msg_server_id = 123456;
    param.msg_type = kNIMQChatSystemNotificationTypeCustom;
    param.status = kNIMQChatSystemNotificationNormal;
    param.msg_body = "msg body";
    param.msg_ext = "msg ext";
    param.update_info.postscript = "postscript";
    param.update_info.extension = "extension";
    param.update_info.push_content = "push content";
    param.update_info.push_payload = "push payload";
    param.cb = [this](const QChatUpdateSystemNotificationResp& resp) {
        if (resp.res_code != NIMResCode::kNIMResSuccess) {
            // error handling
            return;
        }
        // process response
        // ...
    };
    SystemNotification::Update(param);
    
  5. 服务器成员收到更新后的圈组系统通知。

此文档是否对你有帮助?
有帮助
去反馈
  • 功能介绍
  • 实现方法
  • 前提条件
  • 实现流程