NIM 跨平台 C++ SDK
载入中...
搜索中...
未找到
nim_user_helper.h
浏览该文件的文档.
1
7#ifndef _NIM_SDK_CPP_USER_HELPER_H_
8#define _NIM_SDK_CPP_USER_HELPER_H_
9
10#include <assert.h>
11#include <list>
12#include <string>
14#include "nim_define_include.h"
20namespace nim {
46 kUserNameCardKeyAll = (1 << 10) - 1
47};
48
52 UserNameCard(const std::string& accid)
53 : value_available_flag_(0)
54 , create_timetag_(0)
55 , update_timetag_(0)
56 , gender_(0) {
57 accid_ = accid;
58 }
59
62 : value_available_flag_(0)
63 , create_timetag_(0)
64 , update_timetag_(0)
65 , gender_(0) {}
66
67public:
69 void SetAccId(const std::string& id) { accid_ = id; }
70
72 std::string GetAccId() const { return accid_; }
73
75 void SetName(const std::string& name) {
76 nickname_ = name;
77 value_available_flag_ |= kUserNameCardKeyName;
78 }
79
81 std::string GetName() const { return nickname_; }
82
84 void SetIconUrl(const std::string& url) {
85 icon_url_ = url;
86 value_available_flag_ |= kUserNameCardKeyIconUrl;
87 }
88
90 std::string GetIconUrl() const { return icon_url_; }
91
93 void SetSignature(const std::string& sign) {
94 signature_ = sign;
95 value_available_flag_ |= kUserNameCardKeySignature;
96 }
97
99 std::string GetSignature() const { return signature_; }
100
102 void SetGender(int gender) {
103 gender_ = gender;
104 value_available_flag_ |= kUserNameCardKeyGender;
105 }
106
108 int GetGender() const { return gender_; }
109
111 void SetEmail(const std::string& email) {
112 email_ = email;
113 value_available_flag_ |= kUserNameCardKeyEmail;
114 }
115
117 std::string GetEmail() const { return email_; }
118
120 void SetBirth(const std::string& birth) {
121 birth_ = birth;
122 value_available_flag_ |= kUserNameCardKeyBirthday;
123 }
124
126 std::string GetBirth() const { return birth_; }
127
129 void SetMobile(const std::string& mobile) {
130 mobile_ = mobile;
131 value_available_flag_ |= kUserNameCardKeyMobile;
132 }
133
135 std::string GetMobile() const { return mobile_; }
136
139 expand_ = expand;
140 value_available_flag_ |= kUserNameCardKeyEx;
141 }
142
145
147 void SetCreateTimetag(int64_t timetag) { create_timetag_ = timetag; }
148
150 int64_t GetCreateTimetag() const { return create_timetag_; }
151
153 void SetUpdateTimetag(int64_t timetag) { update_timetag_ = timetag; }
154
156 int64_t GetUpdateTimetag() const { return update_timetag_; }
157
163 void Update(const UserNameCard& namecard) {
164 assert(namecard.GetAccId() == accid_);
165 if (namecard.GetAccId() != accid_)
166 return;
167 if (namecard.ExistValue(kUserNameCardKeyName))
168 SetName(namecard.GetName());
170 SetIconUrl(namecard.GetIconUrl());
172 SetSignature(namecard.GetSignature());
174 SetGender(namecard.GetGender());
175 if (namecard.ExistValue(kUserNameCardKeyEmail))
176 SetEmail(namecard.GetEmail());
178 SetBirth(namecard.GetBirth());
180 SetMobile(namecard.GetMobile());
181 if (namecard.ExistValue(kUserNameCardKeyEx))
182 SetExpand(namecard.GetExpand());
183 if (namecard.GetCreateTimetag() > 0)
184 create_timetag_ = namecard.GetCreateTimetag();
185 if (namecard.GetUpdateTimetag() > 0)
186 update_timetag_ = namecard.GetUpdateTimetag();
187 }
188
194 bool ExistValue(UserNameCardValueKey value_key) const { return (value_available_flag_ & value_key) != 0; }
195
200 std::string ToJsonString() const {
202 values[kNIMNameCardKeyAccid] = GetAccId();
203 if (ExistValue(kUserNameCardKeyName))
204 values[kNIMNameCardKeyName] = GetName();
205 if (ExistValue(kUserNameCardKeyIconUrl))
206 values[kNIMNameCardKeyIcon] = GetIconUrl();
207 if (ExistValue(kUserNameCardKeySignature))
208 values[kNIMNameCardKeySign] = GetSignature();
209 if (ExistValue(kUserNameCardKeyGender))
210 values[kNIMNameCardKeyGender] = GetGender();
211 if (ExistValue(kUserNameCardKeyEmail))
212 values[kNIMNameCardKeyEmail] = GetEmail();
213 if (ExistValue(kUserNameCardKeyBirthday))
214 values[kNIMNameCardKeyBirth] = GetBirth();
215 if (ExistValue(kUserNameCardKeyMobile))
216 values[kNIMNameCardKeyMobile] = GetMobile();
217 if (ExistValue(kUserNameCardKeyEx))
218 values[kNIMNameCardKeyEx] = GetJsonStringWithNoStyled(GetExpand());
219
220 return GetJsonStringWithNoStyled(values);
221 }
222
229 values[kNIMNameCardKeyAccid] = GetAccId();
230 if (ExistValue(kUserNameCardKeyName))
231 values[kNIMNameCardKeyName] = GetName();
232 if (ExistValue(kUserNameCardKeyIconUrl))
233 values[kNIMNameCardKeyIcon] = GetIconUrl();
234 if (ExistValue(kUserNameCardKeySignature))
235 values[kNIMNameCardKeySign] = GetSignature();
236 if (ExistValue(kUserNameCardKeyGender))
237 values[kNIMNameCardKeyGender] = GetGender();
238 if (ExistValue(kUserNameCardKeyEmail))
239 values[kNIMNameCardKeyEmail] = GetEmail();
240 if (ExistValue(kUserNameCardKeyBirthday))
241 values[kNIMNameCardKeyBirth] = GetBirth();
242 if (ExistValue(kUserNameCardKeyMobile))
243 values[kNIMNameCardKeyMobile] = GetMobile();
244 if (ExistValue(kUserNameCardKeyEx))
245 values[kNIMNameCardKeyEx] = GetJsonStringWithNoStyled(GetExpand());
246
247 return values;
248 }
249
250private:
252 std::string accid_;
254 std::string nickname_;
256 std::string icon_url_;
258 std::string signature_;
262 std::string email_;
264 std::string birth_;
266 std::string mobile_;
273
274protected:
277};
278
282 std::string accid_;
291
293 : set_black_(false)
294 , set_mute_(false)
295 , create_timetag_(0)
296 , update_timetag_(0) {}
297};
298
304 std::string content_;
305};
306
313NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCards(const std::string& namecards_json, std::list<UserNameCard>& namecards);
314
321NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCards(const nim_cpp_wrapper_util::Json::Value& namecards_json, std::list<UserNameCard>& namecards);
322
329NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCard(const std::string& namecard_json, UserNameCard& namecard);
330
338
345NIM_SDK_CPPWRAPPER_DLL_API bool ParseSpecialListInfo(const std::string& list_json, std::list<BlackMuteListInfo>& black_mute_list);
346} // namespace nim
347
348#endif //_NIM_SDK_CPP_USER_HELPER_H_
Represents a JSON value.
Definition: value.h:196
namespace nim
bool ParseNameCards(const std::string &namecards_json, std::list< UserNameCard > &namecards)
解析数字人用户名片
Definition: nim_user_helper.cpp:11
bool ParseSpecialListInfo(const std::string &list_json, std::list< BlackMuteListInfo > &mute_black_list)
解析黑名单/静音列表
Definition: nim_user_helper.cpp:66
UserNameCardValueKey
Definition: nim_user_helper.h:22
@ kUserNameCardKeyGender
性别
Definition: nim_user_helper.h:30
@ kUserNameCardKeyIconUrl
头像下载地址
Definition: nim_user_helper.h:28
@ kUserNameCardKeyEx
扩展
Definition: nim_user_helper.h:40
@ kUserNameCardKeyBirthday
生日
Definition: nim_user_helper.h:32
@ kUserNameCardKeyEmail
电子邮件
Definition: nim_user_helper.h:36
@ kUserNameCardKeyModelConfig
Model config 字段有效
Definition: nim_user_helper.h:44
@ kUserNameCardKeyName
昵称
Definition: nim_user_helper.h:26
@ kUserNameCardKeyModelType
Model type 字段有效
Definition: nim_user_helper.h:42
@ kUserNameCardKeyNone
无内容
Definition: nim_user_helper.h:24
@ kUserNameCardKeyMobile
电话
Definition: nim_user_helper.h:34
@ kUserNameCardKeyAll
全部内容都有
Definition: nim_user_helper.h:46
@ kUserNameCardKeySignature
签名
Definition: nim_user_helper.h:38
bool ParseNameCard(const std::string &namecard_json, UserNameCard &namecard)
解析数字人用户名片
Definition: nim_user_helper.cpp:33
std::string GetJsonStringWithNoStyled(const nim_cpp_wrapper_util::Json::Value &values)
获得非格式化的Json string,传入SDK的json string格式要求为非格式化的,如果是格式化的json string可能会影响功能
Definition: nim_json_util.cpp:89
NIM 公共数据类型定义总的包含文件
JSON辅助方法
定义导出宏
#define NIM_SDK_CPPWRAPPER_DLL_API
Definition: nim_sdk_cpp_wrapper.h:38
static const char * kNIMNameCardKeyAccid
string 帐号
Definition: nim_user_def.h:61
static const char * kNIMNameCardKeyName
string 昵称
Definition: nim_user_def.h:63
static const char * kNIMNameCardKeyIcon
string 头像
Definition: nim_user_def.h:65
static const char * kNIMNameCardKeyMobile
string 电话
Definition: nim_user_def.h:75
static const char * kNIMNameCardKeyEx
string 扩展字段, 必须为可以解析为json的非格式化的字符串
Definition: nim_user_def.h:77
static const char * kNIMNameCardKeyGender
int 性别
Definition: nim_user_def.h:69
NIMUserSpecialRelationshipChangeType
Definition: nim_user_def.h:19
static const char * kNIMNameCardKeySign
string 签名
Definition: nim_user_def.h:67
static const char * kNIMNameCardKeyEmail
string 邮箱
Definition: nim_user_def.h:71
static const char * kNIMNameCardKeyBirth
string 生日
Definition: nim_user_def.h:73
#define false
Definition: stdbool.h:33
黑名单 静音名单信息
Definition: nim_user_helper.h:280
int64_t update_timetag_
档案更新时间(毫秒)
Definition: nim_user_helper.h:290
std::string accid_
用户ID
Definition: nim_user_helper.h:282
bool set_mute_
是否被静音
Definition: nim_user_helper.h:286
BlackMuteListInfo()
Definition: nim_user_helper.h:292
int64_t create_timetag_
档案创建时间(毫秒)
Definition: nim_user_helper.h:288
bool set_black_
是否黑名单
Definition: nim_user_helper.h:284
黑名单和静音名单变更通知
Definition: nim_user_helper.h:300
NIMUserSpecialRelationshipChangeType type_
黑名单/静音名单更新事件类型
Definition: nim_user_helper.h:302
std::string content_
黑名单/静音名单更新事件内容,根据事件类型调用ParseXXXChange接口(nim_cpp_user.h)解析该内容
Definition: nim_user_helper.h:304
云信用户名片
Definition: nim_user_helper.h:50
nim_cpp_wrapper_util::Json::Value GetExpand() const
Definition: nim_user_helper.h:144
std::string ToJsonString() const
组装Json Value字符串
Definition: nim_user_helper.h:200
std::string GetMobile() const
Definition: nim_user_helper.h:135
unsigned int value_available_flag_
字段有效性标记
Definition: nim_user_helper.h:276
std::string GetSignature() const
Definition: nim_user_helper.h:99
void SetName(const std::string &name)
Definition: nim_user_helper.h:75
std::string nickname_
用户昵称
Definition: nim_user_helper.h:254
std::string birth_
用户生日
Definition: nim_user_helper.h:264
UserNameCard()
Definition: nim_user_helper.h:61
int GetGender() const
Definition: nim_user_helper.h:108
nim_cpp_wrapper_util::Json::Value ToJsonObject() const
组装Json Value
Definition: nim_user_helper.h:227
void SetUpdateTimetag(int64_t timetag)
Definition: nim_user_helper.h:153
void SetGender(int gender)
Definition: nim_user_helper.h:102
std::string mobile_
用户电话
Definition: nim_user_helper.h:266
bool ExistValue(UserNameCardValueKey value_key) const
用户名片数据标记Key对应的数据是否有效(存在,非初始值状态)
Definition: nim_user_helper.h:194
UserNameCard(const std::string &accid)
Definition: nim_user_helper.h:52
void SetEmail(const std::string &email)
Definition: nim_user_helper.h:111
std::string GetBirth() const
Definition: nim_user_helper.h:126
int gender_
用户性别
Definition: nim_user_helper.h:260
std::string GetEmail() const
Definition: nim_user_helper.h:117
void SetSignature(const std::string &sign)
Definition: nim_user_helper.h:93
int64_t update_timetag_
用户档案更新时间戳(毫秒)
Definition: nim_user_helper.h:272
std::string GetIconUrl() const
Definition: nim_user_helper.h:90
nim_cpp_wrapper_util::Json::Value expand_
用户扩展数据
Definition: nim_user_helper.h:268
std::string icon_url_
用户头像下载地址
Definition: nim_user_helper.h:256
int64_t GetCreateTimetag() const
Definition: nim_user_helper.h:150
std::string GetAccId() const
Definition: nim_user_helper.h:72
void SetAccId(const std::string &id)
Definition: nim_user_helper.h:69
std::string accid_
用户ID
Definition: nim_user_helper.h:252
void SetMobile(const std::string &mobile)
Definition: nim_user_helper.h:129
std::string signature_
用户签名
Definition: nim_user_helper.h:258
int64_t create_timetag_
用户档案创建时间戳(毫秒)
Definition: nim_user_helper.h:270
std::string email_
用户邮箱
Definition: nim_user_helper.h:262
int64_t GetUpdateTimetag() const
Definition: nim_user_helper.h:156
void Update(const UserNameCard &namecard)
更新用户名片
Definition: nim_user_helper.h:163
void SetExpand(const nim_cpp_wrapper_util::Json::Value &expand)
Definition: nim_user_helper.h:138
std::string GetName() const
Definition: nim_user_helper.h:81
void SetCreateTimetag(int64_t timetag)
Definition: nim_user_helper.h:147
void SetBirth(const std::string &birth)
Definition: nim_user_helper.h:120
void SetIconUrl(const std::string &url)
Definition: nim_user_helper.h:84