NIM SDK API  8.5.1
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>
13 #include "nim_define_include.h"
15 #include "nim_wrapper_util/nim_json_util.h"
16 #include "public_defines.h"
21 namespace nim {
23 NIM_SDK_CPPWRAPPER_DLL_API enum UserNameCardValueKey {
32  kUserNameCardKeyEx = 1 << 7,
33  kUserNameCardKeyAll = (1 << 8) - 1
34 };
35 
37 struct NIM_SDK_CPPWRAPPER_DLL_API UserNameCard {
39  UserNameCard(const std::string& accid)
40  : value_available_flag_(0)
41  , create_timetag_(0)
42  , update_timetag_(0)
43  , gender_(0) {
44  accid_ = accid;
45  }
46 
49  : value_available_flag_(0)
50  , create_timetag_(0)
51  , update_timetag_(0)
52  , gender_(0) {}
53 
54 public:
56  void SetAccId(const std::string& id) { accid_ = id; }
57 
59  std::string GetAccId() const { return accid_; }
60 
62  void SetName(const std::string& name) {
63  nickname_ = name;
64  value_available_flag_ |= kUserNameCardKeyName;
65  }
66 
68  std::string GetName() const { return nickname_; }
69 
71  void SetIconUrl(const std::string& url) {
72  icon_url_ = url;
73  value_available_flag_ |= kUserNameCardKeyIconUrl;
74  }
75 
77  std::string GetIconUrl() const { return icon_url_; }
78 
80  void SetSignature(const std::string& sign) {
81  signature_ = sign;
82  value_available_flag_ |= kUserNameCardKeySignature;
83  }
84 
86  std::string GetSignature() const { return signature_; }
87 
89  void SetGender(int gender) {
90  gender_ = gender;
91  value_available_flag_ |= kUserNameCardKeyGender;
92  }
93 
95  int GetGender() const { return gender_; }
96 
98  void SetEmail(const std::string& email) {
99  email_ = email;
100  value_available_flag_ |= kUserNameCardKeyEmail;
101  }
102 
104  std::string GetEmail() const { return email_; }
105 
107  void SetBirth(const std::string& birth) {
108  birth_ = birth;
109  value_available_flag_ |= kUserNameCardKeyBirthday;
110  }
111 
113  std::string GetBirth() const { return birth_; }
114 
116  void SetMobile(const std::string& mobile) {
117  mobile_ = mobile;
118  value_available_flag_ |= kUserNameCardKeyMobile;
119  }
120 
122  std::string GetMobile() const { return mobile_; }
123 
125  void SetExpand(const nim_cpp_wrapper_util::Json::Value& expand) {
126  expand_ = expand;
127  value_available_flag_ |= kUserNameCardKeyEx;
128  }
129 
131  nim_cpp_wrapper_util::Json::Value GetExpand() const { return expand_; }
132 
134  void SetCreateTimetag(int64_t timetag) { create_timetag_ = timetag; }
135 
137  int64_t GetCreateTimetag() const { return create_timetag_; }
138 
140  void SetUpdateTimetag(int64_t timetag) { update_timetag_ = timetag; }
141 
143  int64_t GetUpdateTimetag() const { return update_timetag_; }
144 
150  void Update(const UserNameCard& namecard) {
151  assert(namecard.GetAccId() == accid_);
152  if (namecard.GetAccId() != accid_)
153  return;
154 
155  if (namecard.ExistValue(kUserNameCardKeyName))
156  SetName(namecard.GetName());
157  if (namecard.ExistValue(kUserNameCardKeyIconUrl))
158  SetIconUrl(namecard.GetIconUrl());
160  SetSignature(namecard.GetSignature());
161  if (namecard.ExistValue(kUserNameCardKeyGender))
162  SetGender(namecard.GetGender());
163  if (namecard.ExistValue(kUserNameCardKeyEmail))
164  SetEmail(namecard.GetEmail());
165  if (namecard.ExistValue(kUserNameCardKeyBirthday))
166  SetBirth(namecard.GetBirth());
167  if (namecard.ExistValue(kUserNameCardKeyMobile))
168  SetMobile(namecard.GetMobile());
169  if (namecard.ExistValue(kUserNameCardKeyEx))
170  SetExpand(namecard.GetExpand());
171  if (namecard.GetCreateTimetag() > 0)
172  create_timetag_ = namecard.GetCreateTimetag();
173  if (namecard.GetUpdateTimetag() > 0)
174  update_timetag_ = namecard.GetUpdateTimetag();
175  }
176 
182  bool ExistValue(UserNameCardValueKey value_key) const { return (value_available_flag_ & value_key) != 0; }
183 
188  std::string ToJsonString() const {
189  nim_cpp_wrapper_util::Json::Value values;
190  values[kNIMNameCardKeyAccid] = GetAccId();
191  if (ExistValue(kUserNameCardKeyName))
192  values[kNIMNameCardKeyName] = GetName();
193  if (ExistValue(kUserNameCardKeyIconUrl))
194  values[kNIMNameCardKeyIcon] = GetIconUrl();
195  if (ExistValue(kUserNameCardKeySignature))
196  values[kNIMNameCardKeySign] = GetSignature();
197  if (ExistValue(kUserNameCardKeyGender))
198  values[kNIMNameCardKeyGender] = GetGender();
199  if (ExistValue(kUserNameCardKeyEmail))
200  values[kNIMNameCardKeyEmail] = GetEmail();
201  if (ExistValue(kUserNameCardKeyBirthday))
202  values[kNIMNameCardKeyBirth] = GetBirth();
203  if (ExistValue(kUserNameCardKeyMobile))
204  values[kNIMNameCardKeyMobile] = GetMobile();
205  if (ExistValue(kUserNameCardKeyEx))
206  values[kNIMNameCardKeyEx] = GetJsonStringWithNoStyled(GetExpand());
207 
208  return GetJsonStringWithNoStyled(values);
209  }
210 
211 private:
212  std::string accid_;
213  std::string nickname_;
214  std::string icon_url_;
215  std::string signature_;
216  int gender_;
217  std::string email_;
218  std::string birth_;
219  std::string mobile_;
220  nim_cpp_wrapper_util::Json::Value expand_;
221  int64_t create_timetag_;
222  int64_t update_timetag_;
224  unsigned int value_available_flag_;
225 };
226 
228 struct NIM_SDK_CPPWRAPPER_DLL_API BlackMuteListInfo {
229  std::string accid_;
230  bool set_black_;
231  bool set_mute_;
232  int64_t create_timetag_;
233  int64_t update_timetag_;
236  : set_black_(false)
237  , set_mute_(false)
238  , create_timetag_(0)
239  , update_timetag_(0) {}
240 };
241 
243 struct NIM_SDK_CPPWRAPPER_DLL_API SpecialRelationshipChangeEvent {
244  NIMUserSpecialRelationshipChangeType type_;
245  std::string content_;
246 };
247 
254 NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCards(const std::string& namecards_json, std::list<UserNameCard>& namecards);
255 
262 NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCards(const nim_cpp_wrapper_util::Json::Value& namecards_json, std::list<UserNameCard>& namecards);
263 
270 NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCard(const std::string& namecard_json, UserNameCard& namecard);
271 
278 NIM_SDK_CPPWRAPPER_DLL_API void ParseNameCard(const nim_cpp_wrapper_util::Json::Value& namecard_json, UserNameCard& namecard);
279 
286 NIM_SDK_CPPWRAPPER_DLL_API bool ParseSpecialListInfo(const std::string& list_json, std::list<BlackMuteListInfo>& black_mute_list);
287 } // namespace nim
288 
289 #endif //_NIM_SDK_CPP_USER_HELPER_H_
nim::UserNameCard::SetBirth
void SetBirth(const std::string &birth)
Definition: nim_user_helper.h:107
nim::UserNameCard::GetMobile
std::string GetMobile() const
Definition: nim_user_helper.h:122
nim::UserNameCard::GetIconUrl
std::string GetIconUrl() const
Definition: nim_user_helper.h:77
nim::kUserNameCardKeyBirthday
@ kUserNameCardKeyBirthday
Definition: nim_user_helper.h:28
nim::BlackMuteListInfo
黑名单 静音名单信息
Definition: nim_user_helper.h:228
nim::UserNameCard::SetSignature
void SetSignature(const std::string &sign)
Definition: nim_user_helper.h:80
nim::UserNameCard::SetEmail
void SetEmail(const std::string &email)
Definition: nim_user_helper.h:98
nim::SpecialRelationshipChangeEvent::content_
std::string content_
Definition: nim_user_helper.h:245
nim::ParseNameCards
NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCards(const std::string &namecards_json, std::list< UserNameCard > &namecards)
解析用户名片
nim::UserNameCard::GetBirth
std::string GetBirth() const
Definition: nim_user_helper.h:113
nim::UserNameCard::GetExpand
nim_cpp_wrapper_util::Json::Value GetExpand() const
Definition: nim_user_helper.h:131
nim::UserNameCard::SetIconUrl
void SetIconUrl(const std::string &url)
Definition: nim_user_helper.h:71
nim::UserNameCard::GetAccId
std::string GetAccId() const
Definition: nim_user_helper.h:59
nim::UserNameCard::GetEmail
std::string GetEmail() const
Definition: nim_user_helper.h:104
nim::kUserNameCardKeyMobile
@ kUserNameCardKeyMobile
Definition: nim_user_helper.h:29
nim::BlackMuteListInfo::create_timetag_
int64_t create_timetag_
Definition: nim_user_helper.h:232
nim::UserNameCard::SetExpand
void SetExpand(const nim_cpp_wrapper_util::Json::Value &expand)
Definition: nim_user_helper.h:125
nim::kUserNameCardKeyName
@ kUserNameCardKeyName
Definition: nim_user_helper.h:25
nim::UserNameCard::GetName
std::string GetName() const
Definition: nim_user_helper.h:68
nim::kUserNameCardKeySignature
@ kUserNameCardKeySignature
Definition: nim_user_helper.h:31
nim::UserNameCard
云信用户名片
Definition: nim_user_helper.h:37
nim::UserNameCard::SetMobile
void SetMobile(const std::string &mobile)
Definition: nim_user_helper.h:116
nim::UserNameCard::ExistValue
bool ExistValue(UserNameCardValueKey value_key) const
用户名片数据标记Key对应的数据是否有效(存在,非初始值状态)
Definition: nim_user_helper.h:182
nim::kUserNameCardKeyIconUrl
@ kUserNameCardKeyIconUrl
Definition: nim_user_helper.h:26
nim::BlackMuteListInfo::update_timetag_
int64_t update_timetag_
Definition: nim_user_helper.h:233
nim::UserNameCard::SetCreateTimetag
void SetCreateTimetag(int64_t timetag)
Definition: nim_user_helper.h:134
nim::UserNameCard::SetGender
void SetGender(int gender)
Definition: nim_user_helper.h:89
nim::BlackMuteListInfo::set_mute_
bool set_mute_
Definition: nim_user_helper.h:231
nim::kUserNameCardKeyGender
@ kUserNameCardKeyGender
Definition: nim_user_helper.h:27
nim::UserNameCard::GetCreateTimetag
int64_t GetCreateTimetag() const
Definition: nim_user_helper.h:137
nim::SpecialRelationshipChangeEvent::type_
NIMUserSpecialRelationshipChangeType type_
Definition: nim_user_helper.h:244
nim::kUserNameCardKeyEx
@ kUserNameCardKeyEx
Definition: nim_user_helper.h:32
nim
namespace nim
nim::UserNameCardValueKey
UserNameCardValueKey
Definition: nim_user_helper.h:23
nim::kUserNameCardKeyEmail
@ kUserNameCardKeyEmail
Definition: nim_user_helper.h:30
nim::UserNameCard::GetUpdateTimetag
int64_t GetUpdateTimetag() const
Definition: nim_user_helper.h:143
nim::UserNameCard::GetSignature
std::string GetSignature() const
Definition: nim_user_helper.h:86
nim::UserNameCard::SetName
void SetName(const std::string &name)
Definition: nim_user_helper.h:62
nim::UserNameCard::SetUpdateTimetag
void SetUpdateTimetag(int64_t timetag)
Definition: nim_user_helper.h:140
nim::ParseSpecialListInfo
NIM_SDK_CPPWRAPPER_DLL_API bool ParseSpecialListInfo(const std::string &list_json, std::list< BlackMuteListInfo > &black_mute_list)
解析黑名单/静音列表
nim::UserNameCard::UserNameCard
UserNameCard(const std::string &accid)
Definition: nim_user_helper.h:39
nim::BlackMuteListInfo::accid_
std::string accid_
Definition: nim_user_helper.h:229
nim::UserNameCard::Update
void Update(const UserNameCard &namecard)
更新用户名片
Definition: nim_user_helper.h:150
nim::UserNameCard::GetGender
int GetGender() const
Definition: nim_user_helper.h:95
nim::UserNameCard::ToJsonString
std::string ToJsonString() const
组装Json Value字符串
Definition: nim_user_helper.h:188
nim::SpecialRelationshipChangeEvent
黑名单和静音名单变更通知
Definition: nim_user_helper.h:243
nim_sdk_cpp_wrapper.h
定义导出宏
nim::UserNameCard::SetAccId
void SetAccId(const std::string &id)
Definition: nim_user_helper.h:56
nim::BlackMuteListInfo::set_black_
bool set_black_
Definition: nim_user_helper.h:230
nim::UserNameCard::UserNameCard
UserNameCard()
Definition: nim_user_helper.h:48
nim::kUserNameCardKeyAll
@ kUserNameCardKeyAll
Definition: nim_user_helper.h:33
nim::ParseNameCard
NIM_SDK_CPPWRAPPER_DLL_API bool ParseNameCard(const std::string &namecard_json, UserNameCard &namecard)
解析用户名片
nim::kUserNameCardKeyNone
@ kUserNameCardKeyNone
Definition: nim_user_helper.h:24