NIM SDK API  8.7.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_
namespace nim
NIM_SDK_CPPWRAPPER_DLL_API bool ParseFriendProfile(const std::string &friend_profile_json, FriendProfile &profile)
解析(单个)好友信息
NIM_SDK_CPPWRAPPER_DLL_API bool ParseFriendsProfile(const std::string &friends_profile_json, std::list< FriendProfile > &profiles)
解析(多)好友信息
kFriendProfileKeySource
Definition: nim_friend_helper.h:27
kFriendProfileKeyAlias
Definition: nim_friend_helper.h:28
kFriendProfileKeyRelationship
Definition: nim_friend_helper.h:25
kFriendProfileKeyBits
Definition: nim_friend_helper.h:29
kFriendProfileKeyNone
Definition: nim_friend_helper.h:24
kFriendProfileKeyServerEx
Definition: nim_friend_helper.h:31
kFriendProfileKeyPassiveRelationship
Definition: nim_friend_helper.h:26
kFriendProfileKeyEx
Definition: nim_friend_helper.h:30
定义导出宏
删除好有拓展选项
Definition: nim_friend_helper.h:36
云信好友变更事件(请求添加)
Definition: nim_friend_helper.h:232
NIMVerifyType add_type_
Definition: nim_friend_helper.h:234
std::string accid_
Definition: nim_friend_helper.h:233
std::string msg_
Definition: nim_friend_helper.h:235
std::string server_ex_
Definition: nim_friend_helper.h:236
云信好友变更事件
Definition: nim_friend_helper.h:226
NIMFriendChangeType type_
Definition: nim_friend_helper.h:227
std::string content_
Definition: nim_friend_helper.h:228
云信好友变更事件(删除)
Definition: nim_friend_helper.h:240
std::string accid_
Definition: nim_friend_helper.h:241
云信好友
Definition: nim_friend_helper.h:45
NIMFriendFlag GetPassiveRelationship() const
Definition: nim_friend_helper.h:90
void SetSource(NIMFriendSource src)
Definition: nim_friend_helper.h:93
int64_t GetBits() const
Definition: nim_friend_helper.h:117
NIMFriendFlag GetRelationship() const
Definition: nim_friend_helper.h:81
void SetBits(int64_t bits)
Definition: nim_friend_helper.h:111
void Update(const FriendProfile &profile)
更新好友数据
Definition: nim_friend_helper.h:187
NIMFriendSource GetSource() const
Definition: nim_friend_helper.h:99
void SetPassiveRelationship(NIMFriendFlag flag)
Definition: nim_friend_helper.h:84
FriendProfile()
Definition: nim_friend_helper.h:47
std::string ToJsonString() const
组装Json Value字符串
Definition: nim_friend_helper.h:160
void SetEx(const nim_cpp_wrapper_util::Json::Value &ex)
Definition: nim_friend_helper.h:120
bool ExistValue(FriendProfileKey key) const
好友信息数据标记Key对应的数据是否有效(存在,非初始值状态)
Definition: nim_friend_helper.h:154
std::string GetAlias() const
Definition: nim_friend_helper.h:108
void SetCreateTimetag(int64_t timetag)
Definition: nim_friend_helper.h:138
void SetUpdateTimetag(int64_t timetag)
Definition: nim_friend_helper.h:144
void SetServerEx(const std::string &srv_ex)
Definition: nim_friend_helper.h:129
FriendProfile(const std::string &accid)
Definition: nim_friend_helper.h:57
void SetAccId(const std::string &accid)
Definition: nim_friend_helper.h:69
int64_t GetUpdateTimetag() const
Definition: nim_friend_helper.h:147
void SetRelationship(NIMFriendFlag flag)
Definition: nim_friend_helper.h:75
int64_t GetCreateTimetag() const
Definition: nim_friend_helper.h:141
nim_cpp_wrapper_util::Json::Value GetEx() const
Definition: nim_friend_helper.h:126
std::string GetServerEx() const
Definition: nim_friend_helper.h:135
std::string GetAccId() const
Definition: nim_friend_helper.h:72
void SetAlias(const std::string &alias)
Definition: nim_friend_helper.h:102
云信好友变更事件(多端同步)
Definition: nim_friend_helper.h:250
std::list< FriendProfile > profiles_
Definition: nim_friend_helper.h:251
云信好友变更事件(更新)
Definition: nim_friend_helper.h:245
FriendProfile profile_
Definition: nim_friend_helper.h:246