NIM SDK API  9.0.0
nim_friend_helper.h
Go to the documentation of this file.
1 
7 #ifndef _NIM_SDK_CPP_FRIEND_HELPER_H_
8 #define _NIM_SDK_CPP_FRIEND_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 enum NIM_SDK_CPPWRAPPER_DLL_API FriendProfileKey {
32  kFriendProfileKeyAll = (1 << 7) - 1
33 };
34 
36 struct NIM_SDK_CPPWRAPPER_DLL_API DeleteFriendOption {
38  : delete_alias_(true) {}
39 
40 public:
41  bool delete_alias_;
42 };
43 
45 struct NIM_SDK_CPPWRAPPER_DLL_API FriendProfile {
48  : relationship_(kNIMFriendFlagNotFriend)
49  , passive_relationship_(kNIMFriendFlagNotFriend)
50  , source_(kNIMFriendSourceDefault)
51  , bits_(0)
52  , create_timetag_(0)
53  , update_timetag_(0)
54  , value_available_flag_(0) {}
55 
57  FriendProfile(const std::string& accid)
58  : relationship_(kNIMFriendFlagNotFriend)
59  , passive_relationship_(kNIMFriendFlagNotFriend)
60  , source_(kNIMFriendSourceDefault)
61  , bits_(0)
62  , create_timetag_(0)
63  , update_timetag_(0)
64  , value_available_flag_(0) {
65  accid_ = accid;
66  }
67 
69  void SetAccId(const std::string& accid) { accid_ = accid; }
70 
72  std::string GetAccId() const { return accid_; }
73 
75  void SetRelationship(NIMFriendFlag flag) {
76  relationship_ = flag;
77  value_available_flag_ |= kFriendProfileKeyRelationship;
78  }
79 
81  NIMFriendFlag GetRelationship() const { return relationship_; }
82 
84  void SetPassiveRelationship(NIMFriendFlag flag) {
85  passive_relationship_ = flag;
86  value_available_flag_ |= kFriendProfileKeyPassiveRelationship;
87  }
88 
90  NIMFriendFlag GetPassiveRelationship() const { return passive_relationship_; }
91 
93  void SetSource(NIMFriendSource src) {
94  source_ = src;
95  value_available_flag_ |= kFriendProfileKeySource;
96  }
97 
99  NIMFriendSource GetSource() const { return source_; }
100 
102  void SetAlias(const std::string& alias) {
103  alias_ = alias;
104  value_available_flag_ |= kFriendProfileKeyAlias;
105  }
106 
108  std::string GetAlias() const { return alias_; }
109 
111  void SetBits(int64_t bits) {
112  bits_ = bits;
113  value_available_flag_ |= kFriendProfileKeyBits;
114  }
115 
117  int64_t GetBits() const { return bits_; }
118 
120  void SetEx(const nim_cpp_wrapper_util::Json::Value& ex) {
121  expand_ = ex;
122  value_available_flag_ |= kFriendProfileKeyEx;
123  }
124 
126  nim_cpp_wrapper_util::Json::Value GetEx() const { return expand_; }
127 
129  void SetServerEx(const std::string& srv_ex) {
130  server_expand_ = srv_ex;
131  value_available_flag_ |= kFriendProfileKeyServerEx;
132  }
133 
135  std::string GetServerEx() const { return server_expand_; }
136 
138  void SetCreateTimetag(int64_t timetag) { create_timetag_ = timetag; }
139 
141  int64_t GetCreateTimetag() const { return create_timetag_; }
142 
144  void SetUpdateTimetag(int64_t timetag) { update_timetag_ = timetag; }
145 
147  int64_t GetUpdateTimetag() const { return update_timetag_; }
148 
154  bool ExistValue(FriendProfileKey key) const { return (value_available_flag_ & key) != 0; }
155 
160  std::string ToJsonString() const {
161  nim_cpp_wrapper_util::Json::Value friend_profile_json;
162  friend_profile_json[kNIMFriendKeyAccid] = accid_;
163  if (ExistValue(kFriendProfileKeyRelationship))
164  friend_profile_json[kNIMFriendKeyFlag] = relationship_;
165  if (ExistValue(kFriendProfileKeyPassiveRelationship))
166  friend_profile_json[kNIMFriendKeyBeFlag] = passive_relationship_;
167  if (ExistValue(kFriendProfileKeySource))
168  friend_profile_json[kNIMFriendKeySource] = source_;
169  if (ExistValue(kFriendProfileKeyAlias))
170  friend_profile_json[kNIMFriendKeyAlias] = alias_;
171  if (ExistValue(kFriendProfileKeyBits))
172  friend_profile_json[kNIMFriendKeyBits] = bits_;
173  if (ExistValue(kFriendProfileKeyEx))
174  friend_profile_json[kNIMFriendKeyEx] = GetJsonStringWithNoStyled(expand_);
175  if (create_timetag_ > 0)
176  friend_profile_json[kNIMFriendKeyCreateTime] = create_timetag_;
177  if (update_timetag_ > 0)
178  friend_profile_json[kNIMFriendKeyUpdateTime] = update_timetag_;
179  return GetJsonStringWithNoStyled(friend_profile_json);
180  }
181 
187  void Update(const FriendProfile& profile) {
188  assert(profile.accid_ == accid_);
189  if (profile.accid_ != accid_)
190  return;
191 
193  relationship_ = profile.relationship_;
195  passive_relationship_ = profile.passive_relationship_;
196  if (profile.ExistValue(kFriendProfileKeySource))
197  source_ = profile.source_;
198  if (profile.ExistValue(kFriendProfileKeyAlias))
199  alias_ = profile.alias_;
200  if (profile.ExistValue(kFriendProfileKeyBits))
201  bits_ = profile.bits_;
202  if (profile.ExistValue(kFriendProfileKeyEx))
203  expand_ = profile.expand_;
204  if (profile.create_timetag_ > 0)
205  create_timetag_ = profile.create_timetag_;
206  if (profile.update_timetag_ > 0)
207  update_timetag_ = profile.update_timetag_;
208  }
209 
210 private:
211  std::string accid_;
212  NIMFriendFlag relationship_;
213  NIMFriendFlag passive_relationship_;
214  NIMFriendSource source_;
215  std::string alias_;
216  int64_t bits_;
217  nim_cpp_wrapper_util::Json::Value expand_;
218  unsigned int value_available_flag_;
219  std::string server_expand_;
220 private:
221  int64_t create_timetag_;
222  int64_t update_timetag_;
223 };
224 
226 struct NIM_SDK_CPPWRAPPER_DLL_API FriendChangeEvent {
227  NIMFriendChangeType type_;
228  std::string content_;
229 };
230 
232 struct NIM_SDK_CPPWRAPPER_DLL_API FriendAddEvent {
233  std::string accid_;
234  NIMVerifyType add_type_;
235  std::string msg_;
236  std::string server_ex_;
237 };
238 
240 struct NIM_SDK_CPPWRAPPER_DLL_API FriendDelEvent {
241  std::string accid_;
242 };
243 
245 struct NIM_SDK_CPPWRAPPER_DLL_API FriendProfileUpdateEvent {
247 };
248 
250 struct NIM_SDK_CPPWRAPPER_DLL_API FriendProfileSyncEvent {
251  std::list<FriendProfile> profiles_;
252 };
253 
260 NIM_SDK_CPPWRAPPER_DLL_API bool ParseFriendsProfile(const std::string& friends_profile_json, std::list<FriendProfile>& profiles);
261 
268 NIM_SDK_CPPWRAPPER_DLL_API bool ParseFriendProfile(const std::string& friend_profile_json, FriendProfile& profile);
269 
276 NIM_SDK_CPPWRAPPER_DLL_API void ParseFriendProfile(const nim_cpp_wrapper_util::Json::Value& friend_profile_json, FriendProfile& profile);
277 } // namespace nim
278 
279 #endif //_NIM_SDK_CPP_FRIEND_HELPER_H_
nim::FriendDelEvent
云信好友变更事件(删除)
Definition: nim_friend_helper.h:240
kFriendProfileKeyNone
kFriendProfileKeyNone
Definition: nim_friend_helper.h:24
nim::FriendProfile
云信好友
Definition: nim_friend_helper.h:45
nim::FriendProfile::ExistValue
bool ExistValue(FriendProfileKey key) const
好友信息数据标记Key对应的数据是否有效(存在,非初始值状态)
Definition: nim_friend_helper.h:154
nim::FriendProfile::SetSource
void SetSource(NIMFriendSource src)
Definition: nim_friend_helper.h:93
nim::FriendChangeEvent::type_
NIMFriendChangeType type_
Definition: nim_friend_helper.h:227
kFriendProfileKeyEx
kFriendProfileKeyEx
Definition: nim_friend_helper.h:30
kFriendProfileKeySource
kFriendProfileKeySource
Definition: nim_friend_helper.h:27
nim::FriendProfile::SetRelationship
void SetRelationship(NIMFriendFlag flag)
Definition: nim_friend_helper.h:75
nim::ParseFriendProfile
NIM_SDK_CPPWRAPPER_DLL_API bool ParseFriendProfile(const std::string &friend_profile_json, FriendProfile &profile)
解析(单个)好友信息
nim::FriendProfile::Update
void Update(const FriendProfile &profile)
更新好友数据
Definition: nim_friend_helper.h:187
nim::FriendProfile::ToJsonString
std::string ToJsonString() const
组装Json Value字符串
Definition: nim_friend_helper.h:160
nim::FriendProfile::GetEx
nim_cpp_wrapper_util::Json::Value GetEx() const
Definition: nim_friend_helper.h:126
kFriendProfileKeyPassiveRelationship
kFriendProfileKeyPassiveRelationship
Definition: nim_friend_helper.h:26
nim::FriendProfile::SetServerEx
void SetServerEx(const std::string &srv_ex)
Definition: nim_friend_helper.h:129
nim::FriendProfile::FriendProfile
FriendProfile()
Definition: nim_friend_helper.h:47
nim::FriendChangeEvent::content_
std::string content_
Definition: nim_friend_helper.h:228
nim::FriendAddEvent::msg_
std::string msg_
Definition: nim_friend_helper.h:235
nim::FriendAddEvent::server_ex_
std::string server_ex_
Definition: nim_friend_helper.h:236
nim::FriendProfile::GetAlias
std::string GetAlias() const
Definition: nim_friend_helper.h:108
nim::FriendProfile::GetUpdateTimetag
int64_t GetUpdateTimetag() const
Definition: nim_friend_helper.h:147
nim::DeleteFriendOption
删除好有拓展选项
Definition: nim_friend_helper.h:36
nim::FriendProfile::SetAlias
void SetAlias(const std::string &alias)
Definition: nim_friend_helper.h:102
nim::FriendProfile::SetEx
void SetEx(const nim_cpp_wrapper_util::Json::Value &ex)
Definition: nim_friend_helper.h:120
kFriendProfileKeyBits
kFriendProfileKeyBits
Definition: nim_friend_helper.h:29
nim::FriendProfile::GetCreateTimetag
int64_t GetCreateTimetag() const
Definition: nim_friend_helper.h:141
nim::FriendProfileUpdateEvent
云信好友变更事件(更新)
Definition: nim_friend_helper.h:245
nim
namespace nim
nim::FriendAddEvent
云信好友变更事件(请求添加)
Definition: nim_friend_helper.h:232
nim::FriendProfile::GetPassiveRelationship
NIMFriendFlag GetPassiveRelationship() const
Definition: nim_friend_helper.h:90
nim::FriendProfile::GetServerEx
std::string GetServerEx() const
Definition: nim_friend_helper.h:135
nim::FriendProfileSyncEvent
云信好友变更事件(多端同步)
Definition: nim_friend_helper.h:250
kFriendProfileKeyRelationship
kFriendProfileKeyRelationship
Definition: nim_friend_helper.h:25
nim::FriendDelEvent::accid_
std::string accid_
Definition: nim_friend_helper.h:241
nim::FriendAddEvent::add_type_
NIMVerifyType add_type_
Definition: nim_friend_helper.h:234
nim::FriendProfile::SetBits
void SetBits(int64_t bits)
Definition: nim_friend_helper.h:111
nim::FriendProfile::GetRelationship
NIMFriendFlag GetRelationship() const
Definition: nim_friend_helper.h:81
nim::FriendProfile::GetSource
NIMFriendSource GetSource() const
Definition: nim_friend_helper.h:99
kFriendProfileKeyAlias
kFriendProfileKeyAlias
Definition: nim_friend_helper.h:28
nim::FriendAddEvent::accid_
std::string accid_
Definition: nim_friend_helper.h:233
nim::ParseFriendsProfile
NIM_SDK_CPPWRAPPER_DLL_API bool ParseFriendsProfile(const std::string &friends_profile_json, std::list< FriendProfile > &profiles)
解析(多)好友信息
kFriendProfileKeyServerEx
kFriendProfileKeyServerEx
Definition: nim_friend_helper.h:31
nim::FriendProfile::SetCreateTimetag
void SetCreateTimetag(int64_t timetag)
Definition: nim_friend_helper.h:138
nim::FriendProfile::SetUpdateTimetag
void SetUpdateTimetag(int64_t timetag)
Definition: nim_friend_helper.h:144
nim::FriendProfile::GetAccId
std::string GetAccId() const
Definition: nim_friend_helper.h:72
nim::FriendProfile::SetPassiveRelationship
void SetPassiveRelationship(NIMFriendFlag flag)
Definition: nim_friend_helper.h:84
nim::FriendProfileUpdateEvent::profile_
FriendProfile profile_
Definition: nim_friend_helper.h:246
nim::FriendProfileSyncEvent::profiles_
std::list< FriendProfile > profiles_
Definition: nim_friend_helper.h:251
nim_sdk_cpp_wrapper.h
定义导出宏
nim::FriendProfile::GetBits
int64_t GetBits() const
Definition: nim_friend_helper.h:117
nim::FriendProfile::SetAccId
void SetAccId(const std::string &accid)
Definition: nim_friend_helper.h:69
nim::FriendProfile::FriendProfile
FriendProfile(const std::string &accid)
Definition: nim_friend_helper.h:57
nim::FriendChangeEvent
云信好友变更事件
Definition: nim_friend_helper.h:226