NIM PC Cross Platform SDK
nim_user_helper.h
Go to the documentation of this file.
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"
16#include "public_defines.h"
21namespace nim {
23NIM_SDK_CPPWRAPPER_DLL_API enum UserNameCardValueKey {
43 kUserNameCardKeyAll = (1 << 8) - 1
44};
45
47struct NIM_SDK_CPPWRAPPER_DLL_API UserNameCard {
49 UserNameCard(const std::string& accid)
50 : value_available_flag_(0)
51 , create_timetag_(0)
52 , update_timetag_(0)
53 , gender_(0) {
54 accid_ = accid;
55 }
56
59 : value_available_flag_(0)
60 , create_timetag_(0)
61 , update_timetag_(0)
62 , gender_(0) {}
63
64public:
66 void SetAccId(const std::string& id) { accid_ = id; }
67
69 std::string GetAccId() const { return accid_; }
70
72 void SetName(const std::string& name) {
73 nickname_ = name;
74 value_available_flag_ |= kUserNameCardKeyName;
75 }
76
78 std::string GetName() const { return nickname_; }
79
81 void SetIconUrl(const std::string& url) {
82 icon_url_ = url;
83 value_available_flag_ |= kUserNameCardKeyIconUrl;
84 }
85
87 std::string GetIconUrl() const { return icon_url_; }
88
90 void SetSignature(const std::string& sign) {
91 signature_ = sign;
92 value_available_flag_ |= kUserNameCardKeySignature;
93 }
94
96 std::string GetSignature() const { return signature_; }
97
99 void SetGender(int gender) {
100 gender_ = gender;
101 value_available_flag_ |= kUserNameCardKeyGender;
102 }
103
105 int GetGender() const { return gender_; }
106
108 void SetEmail(const std::string& email) {
109 email_ = email;
110 value_available_flag_ |= kUserNameCardKeyEmail;
111 }
112
114 std::string GetEmail() const { return email_; }
115
117 void SetBirth(const std::string& birth) {
118 birth_ = birth;
119 value_available_flag_ |= kUserNameCardKeyBirthday;
120 }
121
123 std::string GetBirth() const { return birth_; }
124
126 void SetMobile(const std::string& mobile) {
127 mobile_ = mobile;
128 value_available_flag_ |= kUserNameCardKeyMobile;
129 }
130
132 std::string GetMobile() const { return mobile_; }
133
136 expand_ = expand;
137 value_available_flag_ |= kUserNameCardKeyEx;
138 }
139
142
144 void SetCreateTimetag(int64_t timetag) { create_timetag_ = timetag; }
145
147 int64_t GetCreateTimetag() const { return create_timetag_; }
148
150 void SetUpdateTimetag(int64_t timetag) { update_timetag_ = timetag; }
151
153 int64_t GetUpdateTimetag() const { return update_timetag_; }
154
160 void Update(const UserNameCard& namecard) {
161 assert(namecard.GetAccId() == accid_);
162 if (namecard.GetAccId() != accid_)
163 return;
164
165 if (namecard.ExistValue(kUserNameCardKeyName))
166 SetName(namecard.GetName());
168 SetIconUrl(namecard.GetIconUrl());
170 SetSignature(namecard.GetSignature());
172 SetGender(namecard.GetGender());
173 if (namecard.ExistValue(kUserNameCardKeyEmail))
174 SetEmail(namecard.GetEmail());
176 SetBirth(namecard.GetBirth());
178 SetMobile(namecard.GetMobile());
179 if (namecard.ExistValue(kUserNameCardKeyEx))
180 SetExpand(namecard.GetExpand());
181 if (namecard.GetCreateTimetag() > 0)
182 create_timetag_ = namecard.GetCreateTimetag();
183 if (namecard.GetUpdateTimetag() > 0)
184 update_timetag_ = namecard.GetUpdateTimetag();
185 }
186
192 bool ExistValue(UserNameCardValueKey value_key) const { return (value_available_flag_ & value_key) != 0; }
193
198 std::string ToJsonString() const {
200 values[kNIMNameCardKeyAccid] = GetAccId();
201 if (ExistValue(kUserNameCardKeyName))
202 values[kNIMNameCardKeyName] = GetName();
203 if (ExistValue(kUserNameCardKeyIconUrl))
204 values[kNIMNameCardKeyIcon] = GetIconUrl();
205 if (ExistValue(kUserNameCardKeySignature))
206 values[kNIMNameCardKeySign] = GetSignature();
207 if (ExistValue(kUserNameCardKeyGender))
208 values[kNIMNameCardKeyGender] = GetGender();
209 if (ExistValue(kUserNameCardKeyEmail))
210 values[kNIMNameCardKeyEmail] = GetEmail();
211 if (ExistValue(kUserNameCardKeyBirthday))
212 values[kNIMNameCardKeyBirth] = GetBirth();
213 if (ExistValue(kUserNameCardKeyMobile))
214 values[kNIMNameCardKeyMobile] = GetMobile();
215 if (ExistValue(kUserNameCardKeyEx))
216 values[kNIMNameCardKeyEx] = GetJsonStringWithNoStyled(GetExpand());
217
218 return GetJsonStringWithNoStyled(values);
219 }
220
227 values[kNIMNameCardKeyAccid] = GetAccId();
228 if (ExistValue(kUserNameCardKeyName))
229 values[kNIMNameCardKeyName] = GetName();
230 if (ExistValue(kUserNameCardKeyIconUrl))
231 values[kNIMNameCardKeyIcon] = GetIconUrl();
232 if (ExistValue(kUserNameCardKeySignature))
233 values[kNIMNameCardKeySign] = GetSignature();
234 if (ExistValue(kUserNameCardKeyGender))
235 values[kNIMNameCardKeyGender] = GetGender();
236 if (ExistValue(kUserNameCardKeyEmail))
237 values[kNIMNameCardKeyEmail] = GetEmail();
238 if (ExistValue(kUserNameCardKeyBirthday))
239 values[kNIMNameCardKeyBirth] = GetBirth();
240 if (ExistValue(kUserNameCardKeyMobile))
241 values[kNIMNameCardKeyMobile] = GetMobile();
242 if (ExistValue(kUserNameCardKeyEx))
243 values[kNIMNameCardKeyEx] = GetJsonStringWithNoStyled(GetExpand());
244
245 return values;
246 }
247
248public:
250 std::string accid_;
252 std::string nickname_;
254 std::string icon_url_;
256 std::string signature_;
260 std::string email_;
262 std::string birth_;
264 std::string mobile_;
271
272 unsigned int value_available_flag_;
273};
274
276struct NIM_SDK_CPPWRAPPER_DLL_API BlackMuteListInfo {
278 std::string accid_;
287
289 : set_black_(false)
290 , set_mute_(false)
291 , create_timetag_(0)
292 , update_timetag_(0) {}
293};
294
296struct NIM_SDK_CPPWRAPPER_DLL_API SpecialRelationshipChangeEvent {
300 std::string content_;
301};
302
309NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCards(const std::string& namecards_json, std::list<UserNameCard>& namecards);
310
317NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCards(const nim_cpp_wrapper_util::Json::Value& namecards_json, std::list<UserNameCard>& namecards);
318
325NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCard(const std::string& namecard_json, UserNameCard& namecard);
326
333NIM_SDK_CPPWRAPPER_DLL_API void ParseNameCard(const nim_cpp_wrapper_util::Json::Value& namecard_json, UserNameCard& namecard);
334
341NIM_SDK_CPPWRAPPER_DLL_API bool ParseSpecialListInfo(const std::string& list_json, std::list<BlackMuteListInfo>& black_mute_list);
342} // namespace nim
343
344#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:23
@ kUserNameCardKeyGender
性别
Definition: nim_user_helper.h:31
@ kUserNameCardKeyIconUrl
头像下载地址
Definition: nim_user_helper.h:29
@ kUserNameCardKeyEx
扩展
Definition: nim_user_helper.h:41
@ kUserNameCardKeyBirthday
生日
Definition: nim_user_helper.h:33
@ kUserNameCardKeyEmail
电子邮件
Definition: nim_user_helper.h:37
@ kUserNameCardKeyName
昵称
Definition: nim_user_helper.h:27
@ kUserNameCardKeyNone
无内容
Definition: nim_user_helper.h:25
@ kUserNameCardKeyMobile
电话
Definition: nim_user_helper.h:35
@ kUserNameCardKeyAll
全部内容都有
Definition: nim_user_helper.h:43
@ kUserNameCardKeySignature
签名
Definition: nim_user_helper.h:39
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辅助方法
定义导出宏
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
NIM SDK 及 NIM ChatRoom SDK 公用头文件
黑名单 静音名单信息
Definition: nim_user_helper.h:276
int64_t update_timetag_
档案更新时间(毫秒)
Definition: nim_user_helper.h:286
std::string accid_
用户ID
Definition: nim_user_helper.h:278
bool set_mute_
是否被静音
Definition: nim_user_helper.h:282
int64_t create_timetag_
档案创建时间(毫秒)
Definition: nim_user_helper.h:284
bool set_black_
是否黑名单
Definition: nim_user_helper.h:280
黑名单和静音名单变更通知
Definition: nim_user_helper.h:296
NIMUserSpecialRelationshipChangeType type_
黑名单/静音名单更新事件类型
Definition: nim_user_helper.h:298
std::string content_
黑名单/静音名单更新事件内容,根据事件类型调用ParseXXXChange接口(nim_cpp_user.h)解析该内容
Definition: nim_user_helper.h:300
云信用户名片
Definition: nim_user_helper.h:47
nim_cpp_wrapper_util::Json::Value GetExpand() const
Definition: nim_user_helper.h:141
std::string ToJsonString() const
组装Json Value字符串
Definition: nim_user_helper.h:198
std::string GetMobile() const
Definition: nim_user_helper.h:132
std::string GetSignature() const
Definition: nim_user_helper.h:96
void SetName(const std::string &name)
Definition: nim_user_helper.h:72
std::string nickname_
用户昵称
Definition: nim_user_helper.h:252
std::string birth_
用户生日
Definition: nim_user_helper.h:262
UserNameCard()
Definition: nim_user_helper.h:58
int GetGender() const
Definition: nim_user_helper.h:105
nim_cpp_wrapper_util::Json::Value ToJsonObject() const
组装Json Value
Definition: nim_user_helper.h:225
void SetUpdateTimetag(int64_t timetag)
Definition: nim_user_helper.h:150
void SetGender(int gender)
Definition: nim_user_helper.h:99
std::string mobile_
用户电话
Definition: nim_user_helper.h:264
bool ExistValue(UserNameCardValueKey value_key) const
用户名片数据标记Key对应的数据是否有效(存在,非初始值状态)
Definition: nim_user_helper.h:192
UserNameCard(const std::string &accid)
Definition: nim_user_helper.h:49
void SetEmail(const std::string &email)
Definition: nim_user_helper.h:108
std::string GetBirth() const
Definition: nim_user_helper.h:123
int gender_
用户性别
Definition: nim_user_helper.h:258
std::string GetEmail() const
Definition: nim_user_helper.h:114
void SetSignature(const std::string &sign)
Definition: nim_user_helper.h:90
int64_t update_timetag_
用户档案更新时间戳(毫秒)
Definition: nim_user_helper.h:270
std::string GetIconUrl() const
Definition: nim_user_helper.h:87
nim_cpp_wrapper_util::Json::Value expand_
用户扩展数据
Definition: nim_user_helper.h:266
std::string icon_url_
用户头像下载地址
Definition: nim_user_helper.h:254
int64_t GetCreateTimetag() const
Definition: nim_user_helper.h:147
std::string GetAccId() const
Definition: nim_user_helper.h:69
void SetAccId(const std::string &id)
Definition: nim_user_helper.h:66
std::string accid_
用户ID
Definition: nim_user_helper.h:250
void SetMobile(const std::string &mobile)
Definition: nim_user_helper.h:126
std::string signature_
用户签名
Definition: nim_user_helper.h:256
int64_t create_timetag_
用户档案创建时间戳(毫秒)
Definition: nim_user_helper.h:268
std::string email_
用户邮箱
Definition: nim_user_helper.h:260
int64_t GetUpdateTimetag() const
Definition: nim_user_helper.h:153
void Update(const UserNameCard &namecard)
更新用户名片
Definition: nim_user_helper.h:160
void SetExpand(const nim_cpp_wrapper_util::Json::Value &expand)
Definition: nim_user_helper.h:135
std::string GetName() const
Definition: nim_user_helper.h:78
void SetCreateTimetag(int64_t timetag)
Definition: nim_user_helper.h:144
void SetBirth(const std::string &birth)
Definition: nim_user_helper.h:117
void SetIconUrl(const std::string &url)
Definition: nim_user_helper.h:81