NIM PC Cross Platform 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 {
42 kUserNameCardKeyAll = (1 << 8) - 1
43};
44
48 UserNameCard(const std::string& accid)
49 : value_available_flag_(0)
50 , create_timetag_(0)
51 , update_timetag_(0)
52 , gender_(0) {
53 accid_ = accid;
54 }
55
58 : value_available_flag_(0)
59 , create_timetag_(0)
60 , update_timetag_(0)
61 , gender_(0) {}
62
63public:
65 void SetAccId(const std::string& id) { accid_ = id; }
66
68 std::string GetAccId() const { return accid_; }
69
71 void SetName(const std::string& name) {
72 nickname_ = name;
73 value_available_flag_ |= kUserNameCardKeyName;
74 }
75
77 std::string GetName() const { return nickname_; }
78
80 void SetIconUrl(const std::string& url) {
81 icon_url_ = url;
82 value_available_flag_ |= kUserNameCardKeyIconUrl;
83 }
84
86 std::string GetIconUrl() const { return icon_url_; }
87
89 void SetSignature(const std::string& sign) {
90 signature_ = sign;
91 value_available_flag_ |= kUserNameCardKeySignature;
92 }
93
95 std::string GetSignature() const { return signature_; }
96
98 void SetGender(int gender) {
99 gender_ = gender;
100 value_available_flag_ |= kUserNameCardKeyGender;
101 }
102
104 int GetGender() const { return gender_; }
105
107 void SetEmail(const std::string& email) {
108 email_ = email;
109 value_available_flag_ |= kUserNameCardKeyEmail;
110 }
111
113 std::string GetEmail() const { return email_; }
114
116 void SetBirth(const std::string& birth) {
117 birth_ = birth;
118 value_available_flag_ |= kUserNameCardKeyBirthday;
119 }
120
122 std::string GetBirth() const { return birth_; }
123
125 void SetMobile(const std::string& mobile) {
126 mobile_ = mobile;
127 value_available_flag_ |= kUserNameCardKeyMobile;
128 }
129
131 std::string GetMobile() const { return mobile_; }
132
135 expand_ = expand;
136 value_available_flag_ |= kUserNameCardKeyEx;
137 }
138
141
143 void SetCreateTimetag(int64_t timetag) { create_timetag_ = timetag; }
144
146 int64_t GetCreateTimetag() const { return create_timetag_; }
147
149 void SetUpdateTimetag(int64_t timetag) { update_timetag_ = timetag; }
150
152 int64_t GetUpdateTimetag() const { return update_timetag_; }
153
159 void Update(const UserNameCard& namecard) {
160 assert(namecard.GetAccId() == accid_);
161 if (namecard.GetAccId() != accid_)
162 return;
163
164 if (namecard.ExistValue(kUserNameCardKeyName))
165 SetName(namecard.GetName());
167 SetIconUrl(namecard.GetIconUrl());
169 SetSignature(namecard.GetSignature());
171 SetGender(namecard.GetGender());
172 if (namecard.ExistValue(kUserNameCardKeyEmail))
173 SetEmail(namecard.GetEmail());
175 SetBirth(namecard.GetBirth());
177 SetMobile(namecard.GetMobile());
178 if (namecard.ExistValue(kUserNameCardKeyEx))
179 SetExpand(namecard.GetExpand());
180 if (namecard.GetCreateTimetag() > 0)
181 create_timetag_ = namecard.GetCreateTimetag();
182 if (namecard.GetUpdateTimetag() > 0)
183 update_timetag_ = namecard.GetUpdateTimetag();
184 }
185
191 bool ExistValue(UserNameCardValueKey value_key) const { return (value_available_flag_ & value_key) != 0; }
192
197 std::string ToJsonString() const {
199 values[kNIMNameCardKeyAccid] = GetAccId();
200 if (ExistValue(kUserNameCardKeyName))
201 values[kNIMNameCardKeyName] = GetName();
202 if (ExistValue(kUserNameCardKeyIconUrl))
203 values[kNIMNameCardKeyIcon] = GetIconUrl();
204 if (ExistValue(kUserNameCardKeySignature))
205 values[kNIMNameCardKeySign] = GetSignature();
206 if (ExistValue(kUserNameCardKeyGender))
207 values[kNIMNameCardKeyGender] = GetGender();
208 if (ExistValue(kUserNameCardKeyEmail))
209 values[kNIMNameCardKeyEmail] = GetEmail();
210 if (ExistValue(kUserNameCardKeyBirthday))
211 values[kNIMNameCardKeyBirth] = GetBirth();
212 if (ExistValue(kUserNameCardKeyMobile))
213 values[kNIMNameCardKeyMobile] = GetMobile();
214 if (ExistValue(kUserNameCardKeyEx))
215 values[kNIMNameCardKeyEx] = GetJsonStringWithNoStyled(GetExpand());
216
217 return GetJsonStringWithNoStyled(values);
218 }
219
226 values[kNIMNameCardKeyAccid] = GetAccId();
227 if (ExistValue(kUserNameCardKeyName))
228 values[kNIMNameCardKeyName] = GetName();
229 if (ExistValue(kUserNameCardKeyIconUrl))
230 values[kNIMNameCardKeyIcon] = GetIconUrl();
231 if (ExistValue(kUserNameCardKeySignature))
232 values[kNIMNameCardKeySign] = GetSignature();
233 if (ExistValue(kUserNameCardKeyGender))
234 values[kNIMNameCardKeyGender] = GetGender();
235 if (ExistValue(kUserNameCardKeyEmail))
236 values[kNIMNameCardKeyEmail] = GetEmail();
237 if (ExistValue(kUserNameCardKeyBirthday))
238 values[kNIMNameCardKeyBirth] = GetBirth();
239 if (ExistValue(kUserNameCardKeyMobile))
240 values[kNIMNameCardKeyMobile] = GetMobile();
241 if (ExistValue(kUserNameCardKeyEx))
242 values[kNIMNameCardKeyEx] = GetJsonStringWithNoStyled(GetExpand());
243
244 return values;
245 }
246
247private:
249 std::string accid_;
251 std::string nickname_;
253 std::string icon_url_;
255 std::string signature_;
259 std::string email_;
261 std::string birth_;
263 std::string mobile_;
270
272};
273
277 std::string accid_;
286
288 : set_black_(false)
289 , set_mute_(false)
290 , create_timetag_(0)
291 , update_timetag_(0) {}
292};
293
299 std::string content_;
300};
301
308NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCards(const std::string& namecards_json, std::list<UserNameCard>& namecards);
309
316NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCards(const nim_cpp_wrapper_util::Json::Value& namecards_json, std::list<UserNameCard>& namecards);
317
324NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCard(const std::string& namecard_json, UserNameCard& namecard);
325
333
340NIM_SDK_CPPWRAPPER_DLL_API bool ParseSpecialListInfo(const std::string& list_json, std::list<BlackMuteListInfo>& black_mute_list);
341} // namespace nim
342
343#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
@ kUserNameCardKeyName
昵称
Definition: nim_user_helper.h:26
@ kUserNameCardKeyNone
无内容
Definition: nim_user_helper.h:24
@ kUserNameCardKeyMobile
电话
Definition: nim_user_helper.h:34
@ kUserNameCardKeyAll
全部内容都有
Definition: nim_user_helper.h:42
@ 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:275
int64_t update_timetag_
档案更新时间(毫秒)
Definition: nim_user_helper.h:285
std::string accid_
用户ID
Definition: nim_user_helper.h:277
bool set_mute_
是否被静音
Definition: nim_user_helper.h:281
BlackMuteListInfo()
Definition: nim_user_helper.h:287
int64_t create_timetag_
档案创建时间(毫秒)
Definition: nim_user_helper.h:283
bool set_black_
是否黑名单
Definition: nim_user_helper.h:279
黑名单和静音名单变更通知
Definition: nim_user_helper.h:295
NIMUserSpecialRelationshipChangeType type_
黑名单/静音名单更新事件类型
Definition: nim_user_helper.h:297
std::string content_
黑名单/静音名单更新事件内容,根据事件类型调用ParseXXXChange接口(nim_cpp_user.h)解析该内容
Definition: nim_user_helper.h:299
云信用户名片
Definition: nim_user_helper.h:46
nim_cpp_wrapper_util::Json::Value GetExpand() const
Definition: nim_user_helper.h:140
std::string ToJsonString() const
组装Json Value字符串
Definition: nim_user_helper.h:197
std::string GetMobile() const
Definition: nim_user_helper.h:131
unsigned int value_available_flag_
Definition: nim_user_helper.h:271
std::string GetSignature() const
Definition: nim_user_helper.h:95
void SetName(const std::string &name)
Definition: nim_user_helper.h:71
std::string nickname_
用户昵称
Definition: nim_user_helper.h:251
std::string birth_
用户生日
Definition: nim_user_helper.h:261
UserNameCard()
Definition: nim_user_helper.h:57
int GetGender() const
Definition: nim_user_helper.h:104
nim_cpp_wrapper_util::Json::Value ToJsonObject() const
组装Json Value
Definition: nim_user_helper.h:224
void SetUpdateTimetag(int64_t timetag)
Definition: nim_user_helper.h:149
void SetGender(int gender)
Definition: nim_user_helper.h:98
std::string mobile_
用户电话
Definition: nim_user_helper.h:263
bool ExistValue(UserNameCardValueKey value_key) const
用户名片数据标记Key对应的数据是否有效(存在,非初始值状态)
Definition: nim_user_helper.h:191
UserNameCard(const std::string &accid)
Definition: nim_user_helper.h:48
void SetEmail(const std::string &email)
Definition: nim_user_helper.h:107
std::string GetBirth() const
Definition: nim_user_helper.h:122
int gender_
用户性别
Definition: nim_user_helper.h:257
std::string GetEmail() const
Definition: nim_user_helper.h:113
void SetSignature(const std::string &sign)
Definition: nim_user_helper.h:89
int64_t update_timetag_
用户档案更新时间戳(毫秒)
Definition: nim_user_helper.h:269
std::string GetIconUrl() const
Definition: nim_user_helper.h:86
nim_cpp_wrapper_util::Json::Value expand_
用户扩展数据
Definition: nim_user_helper.h:265
std::string icon_url_
用户头像下载地址
Definition: nim_user_helper.h:253
int64_t GetCreateTimetag() const
Definition: nim_user_helper.h:146
std::string GetAccId() const
Definition: nim_user_helper.h:68
void SetAccId(const std::string &id)
Definition: nim_user_helper.h:65
std::string accid_
用户ID
Definition: nim_user_helper.h:249
void SetMobile(const std::string &mobile)
Definition: nim_user_helper.h:125
std::string signature_
用户签名
Definition: nim_user_helper.h:255
int64_t create_timetag_
用户档案创建时间戳(毫秒)
Definition: nim_user_helper.h:267
std::string email_
用户邮箱
Definition: nim_user_helper.h:259
int64_t GetUpdateTimetag() const
Definition: nim_user_helper.h:152
void Update(const UserNameCard &namecard)
更新用户名片
Definition: nim_user_helper.h:159
void SetExpand(const nim_cpp_wrapper_util::Json::Value &expand)
Definition: nim_user_helper.h:134
std::string GetName() const
Definition: nim_user_helper.h:77
void SetCreateTimetag(int64_t timetag)
Definition: nim_user_helper.h:143
void SetBirth(const std::string &birth)
Definition: nim_user_helper.h:116
void SetIconUrl(const std::string &url)
Definition: nim_user_helper.h:80