NIM PC Cross Platform SDK
nim_msglog_helper.h
Go to the documentation of this file.
1
7#ifndef _NIM_SDK_CPP_MSGLOG_HELPER_H_
8#define _NIM_SDK_CPP_MSGLOG_HELPER_H_
9
10#include <functional>
11#include <list>
12#include <string>
19namespace nim {
20
22struct NIM_SDK_CPPWRAPPER_DLL_API QueryMsglogResult {
24 int count_;
28 std::list<IMMessage> msglogs_;
29
32 : count_(0)
33 , source_(kNIMMsglogQuerySourceLocal) {}
34 std::string ToJsonString() const {
36 for (auto& it : msglogs_) {
37 nim_cpp_wrapper_util::Json::Value value = it.ToJsonObject(false);
38 values.append(value);
39 }
40 return nim::GetJsonStringWithNoStyled(values);
41 }
42};
43
45struct NIM_SDK_CPPWRAPPER_DLL_API DeleteMsglogSelfNotifyItemInfo {
46 std::string session_id_; /*会话id */
47 std::string client_id_; /*消息ID */
48 std::string ext_; /*自定义字段 */
49};
51struct NIM_SDK_CPPWRAPPER_DLL_API DeleteMsglogSelfNotifyParam {
53 std::list<DeleteMsglogSelfNotifyItemInfo> item_list;
54};
55
57struct NIM_SDK_CPPWRAPPER_DLL_API MessageStatusChanged {
61 std::string talk_id_;
63 int64_t msg_timetag_;
64
66 : msg_timetag_(0) {}
67};
68
70struct NIM_SDK_CPPWRAPPER_DLL_API MessageStatusChangedResult {
74 std::list<MessageStatusChanged> results_;
75
76 MessageStatusChangedResult(int rescode, std::string& result) {
77 rescode_ = (NIMResCode)rescode;
79 if (nim::ParseJsonValue(result, values) && values.isArray()) {
80 int size = values.size();
81 for (int i = 0; i < size; i++) {
83 changed.status_ = (NIMMsgLogStatus)values[i][kNIMMsglogStatusChangedKeyStatus].asUInt();
85 changed.msg_timetag_ = values[i][kNIMMsglogStatusChangedKeyMsgTimetag].asInt64();
86 results_.push_back(changed);
87 }
88 }
89 }
90};
92class NIM_SDK_CPPWRAPPER_DLL_API LogsBackupExportInfo : protected NIMLogsBackupExportInfo {
93public:
95 : cloned_(false) {
96 ExportBackupToRemotePackageCallback = [](const std::string& file_path, void* user_data) {
97 return file_path;
98 };
99 ExportBackupToRemoteEncryptCallback = [](const std::string& file_path, const std::string& encrypt_key, void* user_data) {
100 return file_path;
101 };
102 ExportBackupToRemoteLogFiter = [](const IMMessage& msg, void* user_data) {
103 return true;
104 };
105 LogsBackupProgressCallback = [](LogsBackupRemoteOperate, float, void* user_data) {};
106 LogsBackupCompleteCallback = [](LogsBackupRemoteOperate, LogsBackupRemoteState state, void* user_data) {
108 delete CastToCPP(user_data);
109 };
110 }
111
112public:
113 void SetEncryptKey(const std::string& encrypt_key) { encrypt_key_ = encrypt_key; }
114 std::string GetEncryptKey() const { return encrypt_key_; }
115 void SetUserData(void* user_data) { NIMLogsBackupExportInfo::user_data_ = user_data; }
116 void* GetUserData() const { return NIMLogsBackupExportInfo::user_data_; }
117 NIMLogsBackupExportInfo* ToCStruct() const {
119 temp->SetUserData(GetUserData());
120 temp->cloned_ = true;
121 return temp->ToCStruct_i();
122 }
123
124private:
125 static inline LogsBackupExportInfo* CastToCPP(void* data) { return ((LogsBackupExportInfo*)(data)); }
126 NIMLogsBackupExportInfo* ToCStruct_i();
127
128public:
134 std::function<std::string(const std::string& file_path, void* user_data)> ExportBackupToRemotePackageCallback;
135
142 std::function<std::string(const std::string& file_path, const std::string& encrypt_key, void* user_data)> ExportBackupToRemoteEncryptCallback;
143
149 std::function<bool(const IMMessage& msg, void* user_data)> ExportBackupToRemoteLogFiter;
156 std::function<void(LogsBackupRemoteOperate op, float progress, void* user_data)> LogsBackupProgressCallback;
163 std::function<void(LogsBackupRemoteOperate op, LogsBackupRemoteState state, void* user_data)> LogsBackupCompleteCallback;
164
165 std::string encrypt_key_;
166 void* src_user_data_;
167 bool cloned_;
168};
169
171class NIM_SDK_CPPWRAPPER_DLL_API LogsBackupImportInfo : public NIMLogsBackupImportInfo {
172public:
174 ImportBackupFromRemoteUnPackageCallback = [](const std::string& file_path, void* user_data) {
175 return file_path;
176 };
177 ImportBackupFromRemoteDecryptCallback = [](const std::string& file_path, const std::string& encrypt_key, void* user_data) {
178 return file_path;
179 };
180 LogsBackupProgressCallback = [](LogsBackupRemoteOperate, float, void* user_data) {};
181 LogsBackupCompleteCallback = [](LogsBackupRemoteOperate, LogsBackupRemoteState state, void* user_data) {
183 delete CastToCPP(user_data);
184 };
185 }
186
187public:
188 void SetUserData(void* user_data) { NIMLogsBackupImportInfo::user_data_ = user_data; }
189 void* GetUserData() const { return NIMLogsBackupImportInfo::user_data_; }
190 NIMLogsBackupImportInfo* ToCStruct() const {
192 temp->SetUserData(GetUserData());
193 temp->cloned_ = true;
194 return temp->ToCStruct_i();
195 }
196
197private:
198 NIMLogsBackupImportInfo* ToCStruct_i();
199 static inline LogsBackupImportInfo* CastToCPP(void* data) { return ((LogsBackupImportInfo*)(data)); }
200
201public:
207 std::function<std::string(const std::string& file_path, void* user_data)> ImportBackupFromRemoteUnPackageCallback;
208
215 std::function<std::string(const std::string& file_path, const std::string& encrypt_key, void* user_data)> ImportBackupFromRemoteDecryptCallback;
216
223 std::function<void(LogsBackupRemoteOperate, float, void* user_data)> LogsBackupProgressCallback;
224
232
233 bool cloned_;
234 void* src_user_data_;
235};
242NIM_SDK_CPPWRAPPER_DLL_API bool ParseMsglogs(const std::string& msgs_json, QueryMsglogResult& res);
243
244} // namespace nim
245
246#endif //_NIM_SDK_CPP_MSGLOG_HELPER_H_
导出消息记录到云端参数定义
Definition: nim_msglog_helper.h:92
std::function< std::string(const std::string &file_path, const std::string &encrypt_key, void *user_data)> ExportBackupToRemoteEncryptCallback
Definition: nim_msglog_helper.h:142
std::function< void(LogsBackupRemoteOperate op, float progress, void *user_data)> LogsBackupProgressCallback
Definition: nim_msglog_helper.h:156
std::function< std::string(const std::string &file_path, void *user_data)> ExportBackupToRemotePackageCallback
Definition: nim_msglog_helper.h:134
std::function< void(LogsBackupRemoteOperate op, LogsBackupRemoteState state, void *user_data)> LogsBackupCompleteCallback
Definition: nim_msglog_helper.h:163
从云端导入消息记录参数定义
Definition: nim_msglog_helper.h:171
std::function< void(LogsBackupRemoteOperate, float, void *user_data)> LogsBackupProgressCallback
Definition: nim_msglog_helper.h:223
std::function< std::string(const std::string &file_path, void *user_data)> ImportBackupFromRemoteUnPackageCallback
Definition: nim_msglog_helper.h:207
std::function< void(LogsBackupRemoteOperate, LogsBackupRemoteState, void *user_data)> LogsBackupCompleteCallback
Definition: nim_msglog_helper.h:231
std::function< std::string(const std::string &file_path, const std::string &encrypt_key, void *user_data)> ImportBackupFromRemoteDecryptCallback
Definition: nim_msglog_helper.h:215
Represents a JSON value.
Definition: value.h:196
Value & append(const Value &value)
Append value to array at the end.
Definition: json_value.cpp:1142
String asString() const
Embedded zeroes are possible.
Definition: json_value.cpp:632
ArrayIndex size() const
Number of values in array or object.
Definition: json_value.cpp:885
namespace nim
bool ParseJsonValue(const std::string &content, nim_cpp_wrapper_util::Json::Value &values)
解析JsonString
Definition: nim_json_util.cpp:70
bool ParseMsglogs(const std::string &msgs_json, QueryMsglogResult &res)
解析查询到的消息历史结果
Definition: nim_msglog_helper.cpp:11
std::string GetJsonStringWithNoStyled(const nim_cpp_wrapper_util::Json::Value &values)
获得非格式化的Json string,传入SDK的json string格式要求为非格式化的,如果是格式化的json string可能会影响功能
Definition: nim_json_util.cpp:89
NIMResCode
Definition: nim_chatroom_res_code_def.h:15
LogsBackupRemoteOperate
Definition: nim_msglog_def.h:445
NIMMsgLogStatus
Definition: nim_msglog_def.h:312
NIMMsglogQuerySource
Definition: nim_msglog_def.h:261
@ kNIMMsglogQuerySourceLocal
本地查询
Definition: nim_msglog_def.h:263
static const char * kNIMMsglogStatusChangedKeyMsgTimetag
临界的消息的时间戳
Definition: nim_msglog_def.h:238
static const char * kNIMMsglogStatusChangedKeyStatus
变更后的状态
Definition: nim_msglog_def.h:240
LogsBackupRemoteState
Definition: nim_msglog_def.h:452
@ LogsBackupRemoteState_FinalState_Begin
是否已是最终状态的一个标识,可以判断state是否为终态(state >= LogsBackupRemoteState_FinalState_Begin)
Definition: nim_msglog_def.h:491
static const char * kNIMMsglogStatusChangedKeyTalkID
会话ID
Definition: nim_msglog_def.h:236
定义导出宏
Talk 辅助方法和数据结构定义
导出消息记录到云端参数定义
Definition: nim_msglog_def.h:498
void * user_data_
APP的自定义用户数据,SDK只负责传回给回调函数,不做任何处理!
Definition: nim_msglog_def.h:540
从云端导入消息记录参数定义
Definition: nim_msglog_def.h:543
void * user_data_
APP的自定义用户数据,SDK只负责传回给回调函数,不做任何处理!
Definition: nim_msglog_def.h:577
单向删除消息记录回调参数
Definition: nim_msglog_helper.h:45
单向删除消息记录回调参数
Definition: nim_msglog_helper.h:51
std::list< DeleteMsglogSelfNotifyItemInfo > item_list
被删除的消息基本信息
Definition: nim_msglog_helper.h:53
Definition: nim_talk_helper.h:281
发送消息已读回执
Definition: nim_msglog_helper.h:57
NIMMsgLogStatus status_
变更后的状态
Definition: nim_msglog_helper.h:59
int64_t msg_timetag_
临界的消息的时间戳
Definition: nim_msglog_helper.h:63
std::string talk_id_
会话ID
Definition: nim_msglog_helper.h:61
发送消息已读回执
Definition: nim_msglog_helper.h:70
NIMResCode rescode_
错误码
Definition: nim_msglog_helper.h:72
std::list< MessageStatusChanged > results_
结果
Definition: nim_msglog_helper.h:74
查询到消息历史结果
Definition: nim_msglog_helper.h:22
int count_
消息历史数
Definition: nim_msglog_helper.h:24
std::list< IMMessage > msglogs_
消息历史
Definition: nim_msglog_helper.h:28
NIMMsglogQuerySource source_
消息历史查询来源
Definition: nim_msglog_helper.h:26
QueryMsglogResult()
Definition: nim_msglog_helper.h:31