NIM PC Cross Platform SDK
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>
14#include "nim_define_include.h"
16#include "public_defines.h"
21namespace nim {
23enum NIM_SDK_CPPWRAPPER_DLL_API FriendProfileKey {
41 kFriendProfileKeyAll = (1 << 7) - 1
42};
43
45struct NIM_SDK_CPPWRAPPER_DLL_API DeleteFriendOption {
47 : delete_alias_(true) {}
48
49public:
50 bool delete_alias_;
51};
52
54struct NIM_SDK_CPPWRAPPER_DLL_API FriendProfile {
57 : relationship_(kNIMFriendFlagNotFriend)
58 , passive_relationship_(kNIMFriendFlagNotFriend)
60 , bits_(0)
61 , create_timetag_(0)
62 , update_timetag_(0)
63 , value_available_flag_(0) {}
64
66 FriendProfile(const std::string& accid)
67 : relationship_(kNIMFriendFlagNotFriend)
68 , passive_relationship_(kNIMFriendFlagNotFriend)
70 , bits_(0)
71 , create_timetag_(0)
72 , update_timetag_(0)
73 , value_available_flag_(0) {
74 accid_ = accid;
75 }
76
78 void SetAccId(const std::string& accid) { accid_ = accid; }
79
81 std::string GetAccId() const { return accid_; }
82
85 relationship_ = flag;
86 value_available_flag_ |= kFriendProfileKeyRelationship;
87 }
88
90 NIMFriendFlag GetRelationship() const { return relationship_; }
91
94 passive_relationship_ = flag;
95 value_available_flag_ |= kFriendProfileKeyPassiveRelationship;
96 }
97
99 NIMFriendFlag GetPassiveRelationship() const { return passive_relationship_; }
100
103 source_ = src;
104 value_available_flag_ |= kFriendProfileKeySource;
105 }
106
108 NIMFriendSource GetSource() const { return source_; }
109
111 void SetAlias(const std::string& alias) {
112 alias_ = alias;
113 value_available_flag_ |= kFriendProfileKeyAlias;
114 }
115
117 std::string GetAlias() const { return alias_; }
118
120 void SetBits(int64_t bits) {
121 bits_ = bits;
122 value_available_flag_ |= kFriendProfileKeyBits;
123 }
124
126 int64_t GetBits() const { return bits_; }
127
130 expand_ = ex;
131 value_available_flag_ |= kFriendProfileKeyEx;
132 }
133
135 nim_cpp_wrapper_util::Json::Value GetEx() const { return expand_; }
136
138 void SetServerEx(const std::string& srv_ex) {
139 server_expand_ = srv_ex;
140 value_available_flag_ |= kFriendProfileKeyServerEx;
141 }
142
144 std::string GetServerEx() const { return server_expand_; }
145
147 void SetCreateTimetag(int64_t timetag) { create_timetag_ = timetag; }
148
150 int64_t GetCreateTimetag() const { return create_timetag_; }
151
153 void SetUpdateTimetag(int64_t timetag) { update_timetag_ = timetag; }
154
156 int64_t GetUpdateTimetag() const { return update_timetag_; }
157
163 bool ExistValue(FriendProfileKey key) const { return (value_available_flag_ & key) != 0; }
164
169 std::string ToJsonString() const {
170 nim_cpp_wrapper_util::Json::Value friend_profile_json;
171 friend_profile_json[kNIMFriendKeyAccid] = accid_;
172 if (ExistValue(kFriendProfileKeyRelationship))
173 friend_profile_json[kNIMFriendKeyFlag] = relationship_;
175 friend_profile_json[kNIMFriendKeyBeFlag] = passive_relationship_;
176 if (ExistValue(kFriendProfileKeySource))
177 friend_profile_json[kNIMFriendKeySource] = source_;
178 if (ExistValue(kFriendProfileKeyAlias))
179 friend_profile_json[kNIMFriendKeyAlias] = alias_;
180 if (ExistValue(kFriendProfileKeyBits))
181 friend_profile_json[kNIMFriendKeyBits] = bits_;
182 if (ExistValue(kFriendProfileKeyEx))
183 friend_profile_json[kNIMFriendKeyEx] = GetJsonStringWithNoStyled(expand_);
184 if (create_timetag_ > 0)
185 friend_profile_json[kNIMFriendKeyCreateTime] = create_timetag_;
186 if (update_timetag_ > 0)
187 friend_profile_json[kNIMFriendKeyUpdateTime] = update_timetag_;
188 return GetJsonStringWithNoStyled(friend_profile_json);
189 }
190
196 void Update(const FriendProfile& profile) {
197 assert(profile.accid_ == accid_);
198 if (profile.accid_ != accid_)
199 return;
200
202 relationship_ = profile.relationship_;
204 passive_relationship_ = profile.passive_relationship_;
206 source_ = profile.source_;
208 alias_ = profile.alias_;
210 bits_ = profile.bits_;
211 if (profile.ExistValue(kFriendProfileKeyEx))
212 expand_ = profile.expand_;
213 if (profile.create_timetag_ > 0)
214 create_timetag_ = profile.create_timetag_;
215 if (profile.update_timetag_ > 0)
216 update_timetag_ = profile.update_timetag_;
217 }
218
219public:
221 std::string accid_;
229 std::string alias_;
231 int64_t bits_;
237 std::string server_expand_;
242};
243
245struct NIM_SDK_CPPWRAPPER_DLL_API FriendChangeEvent {
249 std::string content_;
250};
251
253struct NIM_SDK_CPPWRAPPER_DLL_API FriendAddEvent {
255 std::string accid_;
259 std::string msg_;
261 std::string server_ex_;
262};
263
265struct NIM_SDK_CPPWRAPPER_DLL_API FriendDelEvent {
267 std::string accid_;
268};
269
271struct NIM_SDK_CPPWRAPPER_DLL_API FriendProfileUpdateEvent {
274};
275
277struct NIM_SDK_CPPWRAPPER_DLL_API FriendProfileSyncEvent {
279 std::list<FriendProfile> profiles_;
280};
281
288NIM_SDK_CPPWRAPPER_DLL_API bool ParseFriendsProfile(const std::string& friends_profile_json, std::list<FriendProfile>& profiles);
289
296NIM_SDK_CPPWRAPPER_DLL_API bool ParseFriendProfile(const std::string& friend_profile_json, FriendProfile& profile);
297
304NIM_SDK_CPPWRAPPER_DLL_API void ParseFriendProfile(const nim_cpp_wrapper_util::Json::Value& friend_profile_json, FriendProfile& profile);
305} // namespace nim
306
307#endif //_NIM_SDK_CPP_FRIEND_HELPER_H_
Represents a JSON value.
Definition: value.h:196
namespace nim
bool ParseFriendsProfile(const std::string &friends_profile_json, std::list< FriendProfile > &profiles)
解析(多)好友信息
Definition: nim_friend_helper.cpp:10
std::string GetJsonStringWithNoStyled(const nim_cpp_wrapper_util::Json::Value &values)
获得非格式化的Json string,传入SDK的json string格式要求为非格式化的,如果是格式化的json string可能会影响功能
Definition: nim_json_util.cpp:89
bool ParseFriendProfile(const std::string &friend_profile_json, FriendProfile &profile)
解析(单个)好友信息
Definition: nim_friend_helper.cpp:26
NIM 公共数据类型定义总的包含文件
NIMFriendChangeType
Definition: nim_friend_def.h:80
static const char * kNIMFriendKeyAccid
string, 好友帐号
Definition: nim_friend_def.h:24
static const char * kNIMFriendKeySource
NIMFriendSource, 好友来源
Definition: nim_friend_def.h:30
static const char * kNIMFriendKeyAlias
string, 备注名
Definition: nim_friend_def.h:32
static const char * kNIMFriendKeyBits
long, 扩展字段,位运算型
Definition: nim_friend_def.h:34
static const char * kNIMFriendKeyEx
string, 扩展字段,必须为可以解析为json的非格式化的字符串
Definition: nim_friend_def.h:36
NIMFriendFlag
Definition: nim_friend_def.h:54
@ kNIMFriendFlagNotFriend
陌生人
Definition: nim_friend_def.h:56
static const char * kNIMFriendKeyBeFlag
NIMFriendFlag, 反向好友关系
Definition: nim_friend_def.h:28
NIMVerifyType
Definition: nim_friend_def.h:68
static const char * kNIMFriendKeyUpdateTime
long, 更新时间戳(ms)
Definition: nim_friend_def.h:40
static const char * kNIMFriendKeyCreateTime
long, 创建时间戳(ms)
Definition: nim_friend_def.h:38
NIMFriendSource
Definition: nim_friend_def.h:62
@ kNIMFriendSourceDefault
默认
Definition: nim_friend_def.h:64
static const char * kNIMFriendKeyFlag
NIMFriendFlag, 好友关系,修改时需要同步更新反向好友关系beflag.
Definition: nim_friend_def.h:26
kFriendProfileKeySource
好友来源
Definition: nim_friend_helper.h:31
kFriendProfileKeyAlias
别称
Definition: nim_friend_helper.h:33
kFriendProfileKeyRelationship
主动好友关系
Definition: nim_friend_helper.h:27
kFriendProfileKeyBits
扩展项,int64
Definition: nim_friend_helper.h:35
kFriendProfileKeyNone
无数据
Definition: nim_friend_helper.h:25
kFriendProfileKeyServerEx
服务端扩展项,string 只读
Definition: nim_friend_helper.h:39
kFriendProfileKeyPassiveRelationship
被动好友关系
Definition: nim_friend_helper.h:29
kFriendProfileKeyEx
扩展项,json value
Definition: nim_friend_helper.h:37
JSON辅助方法
定义导出宏
NIM SDK 及 NIM ChatRoom SDK 公用头文件
删除好有拓展选项
Definition: nim_friend_helper.h:45
云信好友变更事件(请求添加)
Definition: nim_friend_helper.h:253
NIMVerifyType add_type_
验证类型
Definition: nim_friend_helper.h:257
std::string accid_
用户ID
Definition: nim_friend_helper.h:255
std::string msg_
附言
Definition: nim_friend_helper.h:259
std::string server_ex_
服务器下发的拓展字段,只有调用了服务器添加好友接口并且传递该字段时才会有内容
Definition: nim_friend_helper.h:261
云信好友变更事件
Definition: nim_friend_helper.h:245
NIMFriendChangeType type_
事件类型
Definition: nim_friend_helper.h:247
std::string content_
事件内容,根据事件类型通过提供的ParsexxxEvent接口(nim_cpp_friend.h)解析该内容
Definition: nim_friend_helper.h:249
云信好友变更事件(删除)
Definition: nim_friend_helper.h:265
std::string accid_
用户ID
Definition: nim_friend_helper.h:267
云信好友
Definition: nim_friend_helper.h:54
NIMFriendSource source_
好友来源
Definition: nim_friend_helper.h:227
std::string server_expand_
扩展数据
Definition: nim_friend_helper.h:237
NIMFriendFlag GetPassiveRelationship() const
Definition: nim_friend_helper.h:99
void SetSource(NIMFriendSource src)
Definition: nim_friend_helper.h:102
int64_t GetBits() const
Definition: nim_friend_helper.h:126
int64_t update_timetag_
好友更新时间戳(毫秒)
Definition: nim_friend_helper.h:241
std::string accid_
用户账号
Definition: nim_friend_helper.h:221
NIMFriendFlag GetRelationship() const
Definition: nim_friend_helper.h:90
void SetBits(int64_t bits)
Definition: nim_friend_helper.h:120
void Update(const FriendProfile &profile)
更新好友数据
Definition: nim_friend_helper.h:196
NIMFriendSource GetSource() const
Definition: nim_friend_helper.h:108
void SetPassiveRelationship(NIMFriendFlag flag)
Definition: nim_friend_helper.h:93
FriendProfile()
Definition: nim_friend_helper.h:56
std::string ToJsonString() const
组装Json Value字符串
Definition: nim_friend_helper.h:169
void SetEx(const nim_cpp_wrapper_util::Json::Value &ex)
Definition: nim_friend_helper.h:129
bool ExistValue(FriendProfileKey key) const
好友信息数据标记Key对应的数据是否有效(存在,非初始值状态)
Definition: nim_friend_helper.h:163
std::string GetAlias() const
Definition: nim_friend_helper.h:117
unsigned int value_available_flag_
好友数据有效性,结合好友Key使用
Definition: nim_friend_helper.h:235
void SetCreateTimetag(int64_t timetag)
Definition: nim_friend_helper.h:147
void SetUpdateTimetag(int64_t timetag)
Definition: nim_friend_helper.h:153
void SetServerEx(const std::string &srv_ex)
Definition: nim_friend_helper.h:138
FriendProfile(const std::string &accid)
Definition: nim_friend_helper.h:66
nim_cpp_wrapper_util::Json::Value expand_
扩展数据
Definition: nim_friend_helper.h:233
std::string alias_
好友别名
Definition: nim_friend_helper.h:229
NIMFriendFlag passive_relationship_
被动的好友关系
Definition: nim_friend_helper.h:225
int64_t bits_
扩展数据
Definition: nim_friend_helper.h:231
void SetAccId(const std::string &accid)
Definition: nim_friend_helper.h:78
NIMFriendFlag relationship_
主动的好友关系
Definition: nim_friend_helper.h:223
int64_t GetUpdateTimetag() const
Definition: nim_friend_helper.h:156
void SetRelationship(NIMFriendFlag flag)
Definition: nim_friend_helper.h:84
int64_t GetCreateTimetag() const
Definition: nim_friend_helper.h:150
nim_cpp_wrapper_util::Json::Value GetEx() const
Definition: nim_friend_helper.h:135
std::string GetServerEx() const
Definition: nim_friend_helper.h:144
std::string GetAccId() const
Definition: nim_friend_helper.h:81
void SetAlias(const std::string &alias)
Definition: nim_friend_helper.h:111
int64_t create_timetag_
好友创建时间戳(毫秒)
Definition: nim_friend_helper.h:239
云信好友变更事件(多端同步)
Definition: nim_friend_helper.h:277
std::list< FriendProfile > profiles_
用户信息列表
Definition: nim_friend_helper.h:279
云信好友变更事件(更新)
Definition: nim_friend_helper.h:271
FriendProfile profile_
用户信息
Definition: nim_friend_helper.h:273