NIM 跨平台 C++ SDK
载入中...
搜索中...
未找到
nim_friend_helper.h
浏览该文件的文档.
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"
20namespace nim {
22enum NIM_SDK_CPPWRAPPER_DLL_API FriendProfileKey {
40 kFriendProfileKeyAll = (1 << 7) - 1
41};
42
46 : delete_alias_(true) {}
47
48public:
50};
51
56 : relationship_(kNIMFriendFlagNotFriend)
57 , passive_relationship_(kNIMFriendFlagNotFriend)
59 , bits_(0)
60 , create_timetag_(0)
61 , update_timetag_(0)
62 , value_available_flag_(0) {}
63
65 FriendProfile(const std::string& accid)
66 : relationship_(kNIMFriendFlagNotFriend)
67 , passive_relationship_(kNIMFriendFlagNotFriend)
69 , bits_(0)
70 , create_timetag_(0)
71 , update_timetag_(0)
72 , value_available_flag_(0) {
73 accid_ = accid;
74 }
75
77 void SetAccId(const std::string& accid) { accid_ = accid; }
78
80 std::string GetAccId() const { return accid_; }
81
84 relationship_ = flag;
85 value_available_flag_ |= kFriendProfileKeyRelationship;
86 }
87
89 NIMFriendFlag GetRelationship() const { return relationship_; }
90
93 passive_relationship_ = flag;
94 value_available_flag_ |= kFriendProfileKeyPassiveRelationship;
95 }
96
98 NIMFriendFlag GetPassiveRelationship() const { return passive_relationship_; }
99
102 source_ = src;
103 value_available_flag_ |= kFriendProfileKeySource;
104 }
105
107 NIMFriendSource GetSource() const { return source_; }
108
110 void SetAlias(const std::string& alias) {
111 alias_ = alias;
112 value_available_flag_ |= kFriendProfileKeyAlias;
113 }
114
116 std::string GetAlias() const { return alias_; }
117
119 void SetBits(int64_t bits) {
120 bits_ = bits;
121 value_available_flag_ |= kFriendProfileKeyBits;
122 }
123
125 int64_t GetBits() const { return bits_; }
126
129 expand_ = ex;
130 value_available_flag_ |= kFriendProfileKeyEx;
131 }
132
134 nim_cpp_wrapper_util::Json::Value GetEx() const { return expand_; }
135
137 void SetServerEx(const std::string& srv_ex) {
138 server_expand_ = srv_ex;
139 value_available_flag_ |= kFriendProfileKeyServerEx;
140 }
141
143 std::string GetServerEx() const { return server_expand_; }
144
146 void SetCreateTimetag(int64_t timetag) { create_timetag_ = timetag; }
147
149 int64_t GetCreateTimetag() const { return create_timetag_; }
150
152 void SetUpdateTimetag(int64_t timetag) { update_timetag_ = timetag; }
153
155 int64_t GetUpdateTimetag() const { return update_timetag_; }
156
162 bool ExistValue(FriendProfileKey key) const { return (value_available_flag_ & key) != 0; }
163
168 std::string ToJsonString() const {
169 nim_cpp_wrapper_util::Json::Value friend_profile_json;
170 friend_profile_json[kNIMFriendKeyAccid] = accid_;
171 if (ExistValue(kFriendProfileKeyRelationship))
172 friend_profile_json[kNIMFriendKeyFlag] = relationship_;
174 friend_profile_json[kNIMFriendKeyBeFlag] = passive_relationship_;
175 if (ExistValue(kFriendProfileKeySource))
176 friend_profile_json[kNIMFriendKeySource] = source_;
177 if (ExistValue(kFriendProfileKeyAlias))
178 friend_profile_json[kNIMFriendKeyAlias] = alias_;
179 if (ExistValue(kFriendProfileKeyBits))
180 friend_profile_json[kNIMFriendKeyBits] = bits_;
181 if (ExistValue(kFriendProfileKeyEx))
182 friend_profile_json[kNIMFriendKeyEx] = GetJsonStringWithNoStyled(expand_);
183 if (ExistValue(kFriendProfileKeyServerEx))
184 friend_profile_json[kNIMFriendServerEx] = server_expand_;
185 if (create_timetag_ > 0)
186 friend_profile_json[kNIMFriendKeyCreateTime] = create_timetag_;
187 if (update_timetag_ > 0)
188 friend_profile_json[kNIMFriendKeyUpdateTime] = update_timetag_;
189 return GetJsonStringWithNoStyled(friend_profile_json);
190 }
191
197 void Update(const FriendProfile& profile) {
198 assert(profile.accid_ == accid_);
199 if (profile.accid_ != accid_)
200 return;
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_;
214 server_expand_ = profile.server_expand_;
215 if (profile.create_timetag_ > 0)
216 create_timetag_ = profile.create_timetag_;
217 if (profile.update_timetag_ > 0)
218 update_timetag_ = profile.update_timetag_;
219 }
220
221private:
223 std::string accid_;
231 std::string alias_;
233 int64_t bits_;
239 std::string server_expand_;
244};
245
253
265
271
277
281 std::list<FriendProfile> profiles_;
282};
283
290NIM_SDK_CPPWRAPPER_DLL_API bool ParseFriendsProfile(const std::string& friends_profile_json, std::list<FriendProfile>& profiles);
291
298NIM_SDK_CPPWRAPPER_DLL_API bool ParseFriendProfile(const std::string& friend_profile_json, FriendProfile& profile);
299
307} // namespace nim
308
309#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 * kNIMFriendServerEx
string, 服务端扩展字段,此字段客户端sdk只读,服务端api读写
Definition nim_friend_def.h:42
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:30
kFriendProfileKeyAlias
别称
Definition nim_friend_helper.h:32
kFriendProfileKeyRelationship
主动好友关系
Definition nim_friend_helper.h:26
kFriendProfileKeyBits
扩展项,int64
Definition nim_friend_helper.h:34
kFriendProfileKeyNone
无数据
Definition nim_friend_helper.h:24
kFriendProfileKeyServerEx
服务端扩展项,string 只读
Definition nim_friend_helper.h:38
kFriendProfileKeyPassiveRelationship
被动好友关系
Definition nim_friend_helper.h:28
kFriendProfileKeyEx
扩展项,json value
Definition nim_friend_helper.h:36
JSON辅助方法
定义导出宏
#define NIM_SDK_CPPWRAPPER_DLL_API
Definition nim_sdk_cpp_wrapper.h:38
#define true
Definition stdbool.h:30
删除好有拓展选项
Definition nim_friend_helper.h:44
DeleteFriendOption()
Definition nim_friend_helper.h:45
bool delete_alias_
Definition nim_friend_helper.h:49
云信好友变更事件(请求添加)
Definition nim_friend_helper.h:255
NIMVerifyType add_type_
验证类型
Definition nim_friend_helper.h:259
std::string accid_
用户ID
Definition nim_friend_helper.h:257
std::string msg_
附言
Definition nim_friend_helper.h:261
std::string server_ex_
服务器下发的拓展字段,只有调用了服务器添加好友接口并且传递该字段时才会有内容
Definition nim_friend_helper.h:263
云信好友变更事件
Definition nim_friend_helper.h:247
NIMFriendChangeType type_
事件类型
Definition nim_friend_helper.h:249
std::string content_
事件内容,根据事件类型通过提供的ParsexxxEvent接口(nim_cpp_friend.h)解析该内容
Definition nim_friend_helper.h:251
云信好友变更事件(删除)
Definition nim_friend_helper.h:267
std::string accid_
用户ID
Definition nim_friend_helper.h:269
云信好友
Definition nim_friend_helper.h:53
NIMFriendSource source_
好友来源
Definition nim_friend_helper.h:229
std::string server_expand_
扩展数据
Definition nim_friend_helper.h:239
NIMFriendFlag GetPassiveRelationship() const
Definition nim_friend_helper.h:98
void SetSource(NIMFriendSource src)
Definition nim_friend_helper.h:101
int64_t GetBits() const
Definition nim_friend_helper.h:125
int64_t update_timetag_
好友更新时间戳(毫秒)
Definition nim_friend_helper.h:243
std::string accid_
用户账号
Definition nim_friend_helper.h:223
NIMFriendFlag GetRelationship() const
Definition nim_friend_helper.h:89
void SetBits(int64_t bits)
Definition nim_friend_helper.h:119
void Update(const FriendProfile &profile)
更新好友数据
Definition nim_friend_helper.h:197
NIMFriendSource GetSource() const
Definition nim_friend_helper.h:107
void SetPassiveRelationship(NIMFriendFlag flag)
Definition nim_friend_helper.h:92
FriendProfile()
Definition nim_friend_helper.h:55
std::string ToJsonString() const
组装Json Value字符串
Definition nim_friend_helper.h:168
void SetEx(const nim_cpp_wrapper_util::Json::Value &ex)
Definition nim_friend_helper.h:128
bool ExistValue(FriendProfileKey key) const
好友信息数据标记Key对应的数据是否有效(存在,非初始值状态)
Definition nim_friend_helper.h:162
std::string GetAlias() const
Definition nim_friend_helper.h:116
unsigned int value_available_flag_
好友数据有效性,结合好友Key使用
Definition nim_friend_helper.h:237
void SetCreateTimetag(int64_t timetag)
Definition nim_friend_helper.h:146
void SetUpdateTimetag(int64_t timetag)
Definition nim_friend_helper.h:152
void SetServerEx(const std::string &srv_ex)
Definition nim_friend_helper.h:137
FriendProfile(const std::string &accid)
Definition nim_friend_helper.h:65
nim_cpp_wrapper_util::Json::Value expand_
扩展数据
Definition nim_friend_helper.h:235
std::string alias_
好友别名
Definition nim_friend_helper.h:231
NIMFriendFlag passive_relationship_
被动的好友关系
Definition nim_friend_helper.h:227
int64_t bits_
扩展数据
Definition nim_friend_helper.h:233
void SetAccId(const std::string &accid)
Definition nim_friend_helper.h:77
NIMFriendFlag relationship_
主动的好友关系
Definition nim_friend_helper.h:225
int64_t GetUpdateTimetag() const
Definition nim_friend_helper.h:155
void SetRelationship(NIMFriendFlag flag)
Definition nim_friend_helper.h:83
int64_t GetCreateTimetag() const
Definition nim_friend_helper.h:149
nim_cpp_wrapper_util::Json::Value GetEx() const
Definition nim_friend_helper.h:134
std::string GetServerEx() const
Definition nim_friend_helper.h:143
std::string GetAccId() const
Definition nim_friend_helper.h:80
void SetAlias(const std::string &alias)
Definition nim_friend_helper.h:110
int64_t create_timetag_
好友创建时间戳(毫秒)
Definition nim_friend_helper.h:241
云信好友变更事件(多端同步)
Definition nim_friend_helper.h:279
std::list< FriendProfile > profiles_
用户信息列表
Definition nim_friend_helper.h:281
云信好友变更事件(更新)
Definition nim_friend_helper.h:273
FriendProfile profile_
用户信息
Definition nim_friend_helper.h:275