系统通知

更新时间: 2022/06/16 06:08:07

圈组系统通知概览

系统通知可分为内置系统通知和自定义系统通知。

系统通知类型 说明 离线系统通知限制
内置系统通知 圈组内置的系统通知, 类型包括“邀请服务器成员”、“踢除服务器成员”、“修改频道信息” 等 服务器成员管理事件的系统通知支持存离线,每月至多存 1,000 条离线通知。其他内置系统通知不存离线
自定义系统通知 开发者自定义系统通知。 SDK 不解析自定义系统通知,仅负责传递 每月 1,000 条离线通知

内置系统通知分类

圈组内置系统通知,可进一步分为服务器成员管理事件的系统通知服务器其他相关事件的系统通知频道事件系统通知频道分组事件系统通知身份组成员管理事件的系统通知身份组权限事件系统通知。除了服务器成员管理事件的系统通知,其余类型都通过参与者与观察者机制控制接收人及其接收条件。

每个类型的具体触发条件和接收条件,请参考服务端的圈组系统通知

技术原理

圈组中的系统通知时由云信服务器下发给用户的通知类消息,用于包括创建 Server、创建 Channel、申请加入 Server 等事件的通知。

SDK 中的 QChatSystemNotification 结构定义圈组的系统通知。

其中,QChatSystemNotification 中的系统通知类型,具体可参考 NIMQChatSystemNotificationType

实现方法

发送系统通知

可通过 send 方法发送系统消息。 其中,QChatSendSystemNotificationParam是发送系统通知的入参。

示例代码

cppQChatSendSystemNotificationParam 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 = false;
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);

更新系统通知

可通过 Update 方法更新系统通知。 其中,QChatUpdateSystemNotificationParam 是更新系统通知的入参。

示例代码

cppQChatUpdateSystemNotificationParam 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);

标记系统通知已读

可通过 MarkSystemNotificationsRead 方法标记系统通知已读。 其中,QChatMarkSystemNotificationsReadParam 是标记系统通知已读的入参。

cppQChatMarkSystemNotificationsReadParam param;
NIMQChatSystemNotificationMarkReadInfo info;
info.msg_server_id = 123456;
info.msg_type = kNIMQChatSystemNotificationTypeCustom;
param.mark_read_infos.emplace_back(info);
param.cb = [this](const QChatMarkReadSystemNotificationResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
SystemNotification::MarkSystemNotificationsRead(param);

接收系统通知回调

可通过 RegRecvCb 方法注册接收系统通知回调,当发生能触发系统通知的事件后,用户会接收到系统通知回调。 其中,QChatRegRecvSystemNotificationCbParam 是注册接收系统通知回调的入参。

示例代码

cppQChatRegRecvSystemNotificationCbParam 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);

系统通知变更回调

可通过 RegUpdatedCb 方法注册接收系统通知回调,当发生能触发系统通知变更的事件后,用户会接收到系统通知变更回调。 其中,QChatRegSystemNotificationUpdatedCbParam 是注册系统通知变更回调的入参。

示例代码

cppQChatRegSystemNotificationUpdatedCbParam 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);
此文档是否对你有帮助?
有帮助
去反馈
  • 圈组系统通知概览
  • 内置系统通知分类
  • 技术原理
  • 实现方法
  • 发送系统通知
  • 示例代码
  • 更新系统通知
  • 示例代码
  • 标记系统通知已读
  • 接收系统通知回调
  • 示例代码
  • 系统通知变更回调
  • 示例代码