NIM PC Cross Platform SDK
nim_sysmsg_helper.h
Go to the documentation of this file.
1
7#ifndef _NIM_SDK_CPP_SYSMSG_HELPER_H_
8#define _NIM_SDK_CPP_SYSMSG_HELPER_H_
9
10#include <functional>
11#include <list>
12#include <string>
15#include "nim_define_include.h"
21namespace nim {
23struct NIM_SDK_CPPWRAPPER_DLL_API SysMessageSetting {
35 std::string push_content_;
39 std::string anti_spam_content_;
41 std::string env_config_;
42
45 : need_push_(BS_NOT_INIT)
46 , push_need_badge_(BS_NOT_INIT)
47 , push_need_prefix_(BS_NOT_INIT)
48 , need_offline_(BS_NOT_INIT)
49 , anti_spam_enable_(BS_NOT_INIT) {}
50
57 if (push_need_badge_ != BS_NOT_INIT)
58 message[kNIMSysMsgKeyPushNeedBadge] = push_need_badge_;
59 if (need_push_ != BS_NOT_INIT)
60 message[kNIMSysMsgKeyPushEnable] = need_push_;
61 if (push_need_prefix_ != BS_NOT_INIT)
62 message[kNIMSysMsgKeyPushNeedPrefix] = push_need_prefix_;
63 if (need_offline_ != BS_NOT_INIT)
64 message[kNIMSysMsgKeyCustomSaveFlag] = need_offline_;
65 if (!push_payload_.empty())
67 if (!push_content_.empty())
68 message[kNIMSysMsgKeyCustomApnsText] = push_content_;
69 if (anti_spam_enable_ != BS_NOT_INIT)
70 message[kNIMSysMsgKeyAntiSpamEnable] = anti_spam_enable_ == BS_TRUE ? 1 : 0;
71 if (!anti_spam_content_.empty())
72 message[kNIMSysMsgKeyAntiSpamContent] = anti_spam_content_;
73 if (!env_config_.empty())
74 message[kNIMSysMsgKeyEnvConfig] = env_config_;
75 }
76
84 push_need_badge_ = (BoolStatus)message[kNIMSysMsgKeyPushNeedBadge].asInt() == 1 ? BS_TRUE : BS_FALSE;
86 need_push_ = (BoolStatus)message[kNIMSysMsgKeyPushEnable].asInt() == 1 ? BS_TRUE : BS_FALSE;
88 push_need_prefix_ = (BoolStatus)message[kNIMSysMsgKeyPushNeedPrefix].asInt() == 1 ? BS_TRUE : BS_FALSE;
90 need_offline_ = (BoolStatus)message[kNIMSysMsgKeyCustomSaveFlag].asInt() == 1 ? BS_TRUE : BS_FALSE;
91 if (!nim::ParseJsonValue(message[kNIMSysMsgKeyPushPayload].asString(), push_payload_) || !push_payload_.isObject())
92 // assert(0);
93 push_content_ = message[kNIMSysMsgKeyCustomApnsText].asString();
95 anti_spam_enable_ = message[kNIMSysMsgKeyAntiSpamEnable].asInt() == 1 ? BS_TRUE : BS_FALSE;
96 anti_spam_content_ = message[kNIMSysMsgKeyAntiSpamContent].asString();
98 env_config_ = message[kNIMSysMsgKeyEnvConfig].asString();
99 }
100};
101
103struct NIM_SDK_CPPWRAPPER_DLL_API SysMessage {
105 int64_t timetag_;
109 std::string receiver_accid_;
111 std::string sender_accid_;
113 std::string content_;
115 std::string attach_;
117 int64_t id_;
122
130 std::string client_msg_id_;
132 std::string callbac_ext_;
135 : timetag_(0)
136 , id_(0)
137 , total_unread_count_(0)
138 , type_(kNIMSysMsgTypeUnknown)
139 , status_(kNIMSysMsgStatusNone)
140 , feature_(kNIMMessageFeatureDefault) {}
141
146 std::string ToJsonString() const {
148 values[kNIMSysMsgKeyToAccount] = receiver_accid_;
149 values[kNIMSysMsgKeyFromAccount] = sender_accid_;
150 values[kNIMSysMsgKeyType] = type_;
151 values[kNIMSysMsgKeyAttach] = attach_;
152 values[kNIMSysMsgKeyMsg] = content_;
153 values[kNIMSysMsgKeyLocalClientMsgId] = client_msg_id_;
154 values[kNIMSysMsgKeyTime] = timetag_;
155 values[kNIMSysMsgKeyMsgId] = id_;
156 values[kNIMSysMsgKeyLocalStatus] = status_;
157 msg_setting_.ToJsonValue(values);
158 return GetJsonStringWithNoStyled(values);
159 }
160
167 values[kNIMSysMsgKeyToAccount] = receiver_accid_;
168 values[kNIMSysMsgKeyFromAccount] = sender_accid_;
169 values[kNIMSysMsgKeyType] = type_;
170 values[kNIMSysMsgKeyAttach] = attach_;
171 values[kNIMSysMsgKeyMsg] = content_;
172 values[kNIMSysMsgKeyLocalClientMsgId] = client_msg_id_;
173 values[kNIMSysMsgKeyTime] = timetag_;
174 values[kNIMSysMsgKeyMsgId] = id_;
175 values[kNIMSysMsgKeyLocalStatus] = status_;
176 msg_setting_.ToJsonValue(values);
177 return values;
178 }
179};
180
187NIM_SDK_CPPWRAPPER_DLL_API bool ParseSysMessage(const std::string& sysmsg_json, SysMessage& msg);
188
196NIM_SDK_CPPWRAPPER_DLL_API bool ParseSysMessages(const std::string& sysmsgs_json, std::list<SysMessage>& msgs, int* unread);
197
204NIM_SDK_CPPWRAPPER_DLL_API void ParseSysMessageContent(const nim_cpp_wrapper_util::Json::Value& content_json, SysMessage& msg);
205} // namespace nim
206
207#endif //_NIM_SDK_CPP_SYSMSG_HELPER_H_
Represents a JSON value.
Definition: value.h:196
bool isMember(const char *key) const
Definition: json_value.cpp:1241
bool empty() const
Return true if empty array, empty object, or null; otherwise, false.
Definition: json_value.cpp:908
String asString() const
Embedded zeroes are possible.
Definition: json_value.cpp:632
namespace nim
bool ParseJsonValue(const std::string &content, nim_cpp_wrapper_util::Json::Value &values)
解析JsonString
Definition: nim_json_util.cpp:70
bool ParseSysMessages(const std::string &sysmsgs_json, std::list< SysMessage > &msgs, int *unread)
解析系统消息或自定义通知
Definition: nim_sysmsg_helper.cpp:28
std::string GetJsonStringWithNoStyled(const nim_cpp_wrapper_util::Json::Value &values)
获得非格式化的Json string,传入SDK的json string格式要求为非格式化的,如果是格式化的json string可能会影响功能
Definition: nim_json_util.cpp:89
void ParseSysMessageContent(const nim_cpp_wrapper_util::Json::Value &content_json, SysMessage &msg)
解析系统消息或自定义通知的内容
Definition: nim_sysmsg_helper.cpp:45
bool ParseSysMessage(const std::string &sysmsg_json, SysMessage &msg)
解析系统消息或自定义通知
Definition: nim_sysmsg_helper.cpp:12
NIMResCode
Definition: nim_chatroom_res_code_def.h:15
NIM 公共数据类型定义总的包含文件
JSON辅助方法
NIMMessageFeature
Definition: nim_msglog_def.h:298
@ kNIMMessageFeatureDefault
默认
Definition: nim_msglog_def.h:300
定义导出宏
加载 NIM SDK 的帮助类头文件
BoolStatus
Definition: nim_sdk_util.h:22
@ BS_TRUE
true
Definition: nim_sdk_util.h:28
@ BS_NOT_INIT
未初始化
Definition: nim_sdk_util.h:24
@ BS_FALSE
false
Definition: nim_sdk_util.h:26
static const char * kNIMSysMsgKeyMsgId
long 服务器消息id(自定义通知消息,必须填0),发送方不需要填写
Definition: nim_sysmsg_def.h:130
static const char * kNIMSysMsgKeyAntiSpamEnable
int, (功能暂时不开放)是否需要过易盾反垃圾, 0:不需要,1:需要, 默认0
Definition: nim_sysmsg_def.h:148
NIMSysMsgStatus
Definition: nim_sysmsg_def.h:159
@ kNIMSysMsgStatusNone
默认,未读
Definition: nim_sysmsg_def.h:161
static const char * kNIMSysMsgKeyLocalStatus
int 本地定义的系统消息状态,见NIMSysMsgStatus,发送方不需要填写
Definition: nim_sysmsg_def.h:132
static const char * kNIMSysMsgKeyFromAccount
string 自己id,选填
Definition: nim_sysmsg_def.h:124
static const char * kNIMSysMsgKeyCustomSaveFlag
int (可选)自定义通知消息是否存离线:0-不存(只发给在线用户),1-存(可发给离线用户)
Definition: nim_sysmsg_def.h:136
static const char * kNIMSysMsgKeyPushPayload
json string, (可选)第三方自定义的推送属性,必须为可以解析为Json的非格式化的字符串,长度2048
Definition: nim_sysmsg_def.h:140
static const char * kNIMSysMsgKeyPushEnable
int (可选)是否需要推送, 0:不需要,1:需要,默认1
Definition: nim_sysmsg_def.h:142
static const char * kNIMSysMsgKeyAntiSpamContent
string, (功能暂时不开放)(可选)开发者自定义的反垃圾字段
Definition: nim_sysmsg_def.h:150
static const char * kNIMSysMsgKeyPushNeedPrefix
int (可选)推送需要前缀,0:不需要,1:需要,默认0
Definition: nim_sysmsg_def.h:146
static const char * kNIMSysMsgKeyMsg
string 只读字段,SDK不转发该字段
Definition: nim_sysmsg_def.h:126
static const char * kNIMSysMsgKeyEnvConfig
string, (可选) 指向自定义抄送的配置
Definition: nim_sysmsg_def.h:152
static const char * kNIMSysMsgKeyTime
long 时间戳,选填
Definition: nim_sysmsg_def.h:118
static const char * kNIMSysMsgKeyAttach
string 消息内容,规定是可以解析为Json格式的字符串,必须为非格式化形式
Definition: nim_sysmsg_def.h:128
NIMSysMsgType
Definition: nim_sysmsg_def.h:175
@ kNIMSysMsgTypeUnknown
未知类型,本地使用,发送时勿使用,作为默认
Definition: nim_sysmsg_def.h:195
static const char * kNIMSysMsgKeyPushNeedBadge
int (可选)推送是否要做消息计数(角标),0:不需要,1:需要,默认1
Definition: nim_sysmsg_def.h:144
static const char * kNIMSysMsgKeyLocalClientMsgId
string 本地定义的消息id,发送方必填,建议使用uuid
Definition: nim_sysmsg_def.h:134
static const char * kNIMSysMsgKeyToAccount
string 接收者id,如果是个人,则是对方用户id,如果是群,则是群id,必填
Definition: nim_sysmsg_def.h:122
static const char * kNIMSysMsgKeyType
int 通知类型,NIMSysMsgType,必填
Definition: nim_sysmsg_def.h:120
static const char * kNIMSysMsgKeyCustomApnsText
string (可选)自定义通知消息推送文本,不填则不推送
Definition: nim_sysmsg_def.h:138
系统消息和自定义通知数据
Definition: nim_sysmsg_helper.h:103
std::string ToJsonString() const
组装Json Value字符串
Definition: nim_sysmsg_helper.h:146
std::string sender_accid_
发送者ID
Definition: nim_sysmsg_helper.h:111
int total_unread_count_
总计的通知未读数
Definition: nim_sysmsg_helper.h:128
int64_t id_
通知ID
Definition: nim_sysmsg_helper.h:117
std::string content_
只读,SDK不转发该字段
Definition: nim_sysmsg_helper.h:113
SysMessage()
Definition: nim_sysmsg_helper.h:134
int64_t timetag_
通知时间戳(毫秒)
Definition: nim_sysmsg_helper.h:105
nim_cpp_wrapper_util::Json::Value ToJsonObject() const
组装Json Value
Definition: nim_sysmsg_helper.h:165
SysMessageSetting msg_setting_
消息属性设置
Definition: nim_sysmsg_helper.h:121
NIMSysMsgStatus status_
通知状态
Definition: nim_sysmsg_helper.h:119
std::string client_msg_id_
通知ID(客户端)
Definition: nim_sysmsg_helper.h:130
NIMResCode rescode_
通知错误码
Definition: nim_sysmsg_helper.h:124
NIMMessageFeature feature_
通知属性
Definition: nim_sysmsg_helper.h:126
NIMSysMsgType type_
通知类型
Definition: nim_sysmsg_helper.h:107
std::string receiver_accid_
接收者ID
Definition: nim_sysmsg_helper.h:109
std::string callbac_ext_
v8.2.0 第三方回调返回的自定义字段
Definition: nim_sysmsg_helper.h:132
std::string attach_
通知附件
Definition: nim_sysmsg_helper.h:115
系统消息和自定义通知属性设置
Definition: nim_sysmsg_helper.h:23
nim_cpp_wrapper_util::Json::Value push_payload_
第三方自定义的推送属性,长度2048
Definition: nim_sysmsg_helper.h:33
BoolStatus need_push_
是否需要推送
Definition: nim_sysmsg_helper.h:25
std::string anti_spam_content_
(功能暂时不开放)(可选)开发者自定义的反垃圾字段
Definition: nim_sysmsg_helper.h:39
BoolStatus push_need_prefix_
需要推送昵称
Definition: nim_sysmsg_helper.h:29
SysMessageSetting()
Definition: nim_sysmsg_helper.h:44
std::string push_content_
自定义推送文案,长度限制200字节
Definition: nim_sysmsg_helper.h:35
void ParseMessageSetting(const nim_cpp_wrapper_util::Json::Value &message)
从Json Value解析出消息属性设置
Definition: nim_sysmsg_helper.h:82
void ToJsonValue(nim_cpp_wrapper_util::Json::Value &message) const
组装Json Value字符串
Definition: nim_sysmsg_helper.h:56
std::string env_config_
(可选) 指向自定义抄送的配置
Definition: nim_sysmsg_helper.h:41
BoolStatus need_offline_
是否支持离线消息
Definition: nim_sysmsg_helper.h:31
BoolStatus anti_spam_enable_
(功能暂时不开放)是否需要过易盾反垃圾
Definition: nim_sysmsg_helper.h:37
BoolStatus push_need_badge_
是否要做消息计数
Definition: nim_sysmsg_helper.h:27