NIM SDK API  9.0.0
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>
13 #include "nim_define_include.h"
16 #include "nim_wrapper_util/nim_json_util.h"
21 namespace nim {
23 struct NIM_SDK_CPPWRAPPER_DLL_API SysMessageSetting {
24  BoolStatus need_push_;
25  BoolStatus push_need_badge_;
26  BoolStatus push_need_prefix_;
27  BoolStatus need_offline_;
28  nim_cpp_wrapper_util::Json::Value push_payload_;
29  std::string push_content_;
30  BoolStatus anti_spam_enable_;
31  std::string anti_spam_content_;
32  std::string env_config_;
36  : need_push_(BS_NOT_INIT)
37  , push_need_badge_(BS_NOT_INIT)
38  , push_need_prefix_(BS_NOT_INIT)
39  , need_offline_(BS_NOT_INIT)
40  , anti_spam_enable_(BS_NOT_INIT) {}
41 
47  void ToJsonValue(nim_cpp_wrapper_util::Json::Value& message) const {
48  if (push_need_badge_ != BS_NOT_INIT)
49  message[kNIMSysMsgKeyPushNeedBadge] = push_need_badge_;
50  if (need_push_ != BS_NOT_INIT)
51  message[kNIMSysMsgKeyPushEnable] = need_push_;
52  if (push_need_prefix_ != BS_NOT_INIT)
53  message[kNIMSysMsgKeyPushNeedPrefix] = push_need_prefix_;
54  if (need_offline_ != BS_NOT_INIT)
55  message[kNIMSysMsgKeyCustomSaveFlag] = need_offline_;
56  if (!push_payload_.empty())
57  message[kNIMSysMsgKeyPushPayload] = GetJsonStringWithNoStyled(push_payload_);
58  if (!push_content_.empty())
59  message[kNIMSysMsgKeyCustomApnsText] = push_content_;
60  if (anti_spam_enable_ != BS_NOT_INIT)
61  message[kNIMSysMsgKeyAntiSpamEnable] = anti_spam_enable_ == BS_TRUE ? 1 : 0;
62  if (!anti_spam_content_.empty())
63  message[kNIMSysMsgKeyAntiSpamContent] = anti_spam_content_;
64  if (!env_config_.empty())
65  message[kNIMSysMsgKeyEnvConfig] = env_config_;
66  }
67 
73  void ParseMessageSetting(const nim_cpp_wrapper_util::Json::Value& message) {
74  if (message.isMember(kNIMSysMsgKeyPushNeedBadge))
75  push_need_badge_ = (BoolStatus)message[kNIMSysMsgKeyPushNeedBadge].asInt() == 1 ? BS_TRUE : BS_FALSE;
76  if (message.isMember(kNIMSysMsgKeyPushEnable))
77  need_push_ = (BoolStatus)message[kNIMSysMsgKeyPushEnable].asInt() == 1 ? BS_TRUE : BS_FALSE;
78  if (message.isMember(kNIMSysMsgKeyPushNeedPrefix))
79  push_need_prefix_ = (BoolStatus)message[kNIMSysMsgKeyPushNeedPrefix].asInt() == 1 ? BS_TRUE : BS_FALSE;
80  if (message.isMember(kNIMSysMsgKeyCustomSaveFlag))
81  need_offline_ = (BoolStatus)message[kNIMSysMsgKeyCustomSaveFlag].asInt() == 1 ? BS_TRUE : BS_FALSE;
82  nim_cpp_wrapper_util::Json::Reader reader;
83  if (!reader.parse(message[kNIMSysMsgKeyPushPayload].asString(), push_payload_) || !push_payload_.isObject())
84  // assert(0);
85  push_content_ = message[kNIMSysMsgKeyCustomApnsText].asString();
86  if (message.isMember(kNIMSysMsgKeyAntiSpamEnable))
87  anti_spam_enable_ = message[kNIMSysMsgKeyAntiSpamEnable].asInt() == 1 ? BS_TRUE : BS_FALSE;
88  anti_spam_content_ = message[kNIMSysMsgKeyAntiSpamContent].asString();
89  if (message.isMember(kNIMSysMsgKeyEnvConfig))
90  env_config_ = message[kNIMSysMsgKeyEnvConfig].asString();
91  }
92 };
93 
95 struct NIM_SDK_CPPWRAPPER_DLL_API SysMessage {
96  int64_t timetag_;
97  NIMSysMsgType type_;
98  std::string receiver_accid_;
99  std::string sender_accid_;
100  std::string content_;
101  std::string attach_;
102  int64_t id_;
103  NIMSysMsgStatus status_;
106  NIMResCode rescode_;
107  NIMMessageFeature feature_;
109  std::string client_msg_id_;
110  std::string callbac_ext_;
113  : timetag_(0)
114  , id_(0)
115  , total_unread_count_(0)
116  , type_(kNIMSysMsgTypeUnknown)
117  , status_(kNIMSysMsgStatusNone)
118  , feature_(kNIMMessageFeatureDefault) {}
119 
124  std::string ToJsonString() const {
125  nim_cpp_wrapper_util::Json::Value values;
126  values[kNIMSysMsgKeyToAccount] = receiver_accid_;
127  values[kNIMSysMsgKeyFromAccount] = sender_accid_;
128  values[kNIMSysMsgKeyType] = type_;
129  values[kNIMSysMsgKeyAttach] = attach_;
130  values[kNIMSysMsgKeyMsg] = content_;
131  values[kNIMSysMsgKeyLocalClientMsgId] = client_msg_id_;
132  values[kNIMSysMsgKeyTime] = timetag_;
133  values[kNIMSysMsgKeyMsgId] = id_;
134  values[kNIMSysMsgKeyLocalStatus] = status_;
135  msg_setting_.ToJsonValue(values);
136  return GetJsonStringWithNoStyled(values);
137  }
138 };
139 
146 NIM_SDK_CPPWRAPPER_DLL_API bool ParseSysMessage(const std::string& sysmsg_json, SysMessage& msg);
147 
155 NIM_SDK_CPPWRAPPER_DLL_API bool ParseSysMessages(const std::string& sysmsgs_json, std::list<SysMessage>& msgs, int* unread);
156 
163 NIM_SDK_CPPWRAPPER_DLL_API void ParseSysMessageContent(const nim_cpp_wrapper_util::Json::Value& content_json, SysMessage& msg);
164 } // namespace nim
165 
166 #endif //_NIM_SDK_CPP_SYSMSG_HELPER_H_
nim::ParseSysMessageContent
NIM_SDK_CPPWRAPPER_DLL_API void ParseSysMessageContent(const nim_cpp_wrapper_util::Json::Value &content_json, SysMessage &msg)
解析系统消息或自定义通知的内容
nim::SysMessage::sender_accid_
std::string sender_accid_
Definition: nim_sysmsg_helper.h:99
nim::SysMessage::ToJsonString
std::string ToJsonString() const
组装Json Value字符串
Definition: nim_sysmsg_helper.h:124
nim::SysMessage::rescode_
NIMResCode rescode_
Definition: nim_sysmsg_helper.h:106
nim::SysMessage::timetag_
int64_t timetag_
Definition: nim_sysmsg_helper.h:96
nim::SysMessageSetting::env_config_
std::string env_config_
Definition: nim_sysmsg_helper.h:32
nim::SysMessageSetting::SysMessageSetting
SysMessageSetting()
Definition: nim_sysmsg_helper.h:35
nim::SysMessageSetting
系统消息和自定义通知属性设置
Definition: nim_sysmsg_helper.h:23
nim::SysMessageSetting::push_need_badge_
BoolStatus push_need_badge_
Definition: nim_sysmsg_helper.h:25
nim::SysMessageSetting::ParseMessageSetting
void ParseMessageSetting(const nim_cpp_wrapper_util::Json::Value &message)
从Json Value解析出消息属性设置
Definition: nim_sysmsg_helper.h:73
nim::SysMessage::msg_setting_
SysMessageSetting msg_setting_
Definition: nim_sysmsg_helper.h:104
nim::SysMessage::status_
NIMSysMsgStatus status_
Definition: nim_sysmsg_helper.h:103
nim::SysMessageSetting::anti_spam_enable_
BoolStatus anti_spam_enable_
Definition: nim_sysmsg_helper.h:30
nim::SysMessage::receiver_accid_
std::string receiver_accid_
Definition: nim_sysmsg_helper.h:98
nim::ParseSysMessage
NIM_SDK_CPPWRAPPER_DLL_API bool ParseSysMessage(const std::string &sysmsg_json, SysMessage &msg)
解析系统消息或自定义通知
nim::SysMessageSetting::ToJsonValue
void ToJsonValue(nim_cpp_wrapper_util::Json::Value &message) const
组装Json Value字符串
Definition: nim_sysmsg_helper.h:47
nim::SysMessage::callbac_ext_
std::string callbac_ext_
Definition: nim_sysmsg_helper.h:110
nim::SysMessageSetting::anti_spam_content_
std::string anti_spam_content_
Definition: nim_sysmsg_helper.h:31
nim::SysMessage::total_unread_count_
int total_unread_count_
Definition: nim_sysmsg_helper.h:108
nim::SysMessage::content_
std::string content_
Definition: nim_sysmsg_helper.h:100
nim::SysMessageSetting::need_push_
BoolStatus need_push_
Definition: nim_sysmsg_helper.h:24
nim::ParseSysMessages
NIM_SDK_CPPWRAPPER_DLL_API bool ParseSysMessages(const std::string &sysmsgs_json, std::list< SysMessage > &msgs, int *unread)
解析系统消息或自定义通知
nim
namespace nim
nim::SysMessage::feature_
NIMMessageFeature feature_
Definition: nim_sysmsg_helper.h:107
nim::SysMessageSetting::need_offline_
BoolStatus need_offline_
Definition: nim_sysmsg_helper.h:27
nim::SysMessage::id_
int64_t id_
Definition: nim_sysmsg_helper.h:102
nim::SysMessageSetting::push_content_
std::string push_content_
Definition: nim_sysmsg_helper.h:29
nim::SysMessage::type_
NIMSysMsgType type_
Definition: nim_sysmsg_helper.h:97
nim::SysMessage::attach_
std::string attach_
Definition: nim_sysmsg_helper.h:101
nim::SysMessage::SysMessage
SysMessage()
Definition: nim_sysmsg_helper.h:112
nim::SysMessage::client_msg_id_
std::string client_msg_id_
Definition: nim_sysmsg_helper.h:109
nim::SysMessageSetting::push_payload_
nim_cpp_wrapper_util::Json::Value push_payload_
Definition: nim_sysmsg_helper.h:28
nim::SysMessage
系统消息和自定义通知数据
Definition: nim_sysmsg_helper.h:95
nim::SysMessageSetting::push_need_prefix_
BoolStatus push_need_prefix_
Definition: nim_sysmsg_helper.h:26
nim_sdk_loader_helper.h
加载 NIM SDK 的帮助类头文件
nim_sdk_cpp_wrapper.h
定义导出宏