NIM SDK API  8.5.1
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>
19 namespace nim {
20 
22 struct NIM_SDK_CPPWRAPPER_DLL_API QueryMsglogResult {
23  int count_;
24  NIMMsglogQuerySource source_;
25  std::list<IMMessage> msglogs_;
29  : count_(0)
30  , source_(kNIMMsglogQuerySourceLocal) {}
31  std::string ToJsonString() const {
32  nim_cpp_wrapper_util::Json::Value values;
33  for (auto& it : msglogs_) {
34  nim_cpp_wrapper_util::Json::Value value = it.ToJsonObject(false);
35  values.append(value);
36  }
37  return nim_cpp_wrapper_util::Json::FastWriter().write(values);
38  }
39 };
40 
42 struct NIM_SDK_CPPWRAPPER_DLL_API DeleteMsglogSelfNotifyItemInfo {
43  std::string session_id_; /*会话id */
44  std::string client_id_; /*消息ID */
45  std::string ext_; /*自定义字段 */
46 };
48 struct NIM_SDK_CPPWRAPPER_DLL_API DeleteMsglogSelfNotifyParam {
49  std::list<DeleteMsglogSelfNotifyItemInfo> item_list;
50 };
51 
53 struct NIM_SDK_CPPWRAPPER_DLL_API MessageStatusChanged {
54  NIMMsgLogStatus status_;
55  std::string talk_id_;
56  int64_t msg_timetag_;
59  : msg_timetag_(0) {}
60 };
61 
63 struct NIM_SDK_CPPWRAPPER_DLL_API MessageStatusChangedResult {
64  NIMResCode rescode_;
65  std::list<MessageStatusChanged> results_;
67  MessageStatusChangedResult(int rescode, std::string& result) {
68  rescode_ = (NIMResCode)rescode;
69  nim_cpp_wrapper_util::Json::Value values;
70  nim_cpp_wrapper_util::Json::Reader reader;
71  if (reader.parse(result, values) && values.isArray()) {
72  int size = values.size();
73  for (int i = 0; i < size; i++) {
74  MessageStatusChanged changed;
75  changed.status_ = (NIMMsgLogStatus)values[i][kNIMMsglogStatusChangedKeyStatus].asUInt();
76  changed.talk_id_ = values[i][kNIMMsglogStatusChangedKeyTalkID].asString();
77  changed.msg_timetag_ = values[i][kNIMMsglogStatusChangedKeyMsgTimetag].asInt64();
78  results_.push_back(changed);
79  }
80  }
81  }
82 };
84 class NIM_SDK_CPPWRAPPER_DLL_API LogsBackupExportInfo : protected NIMLogsBackupExportInfo {
85 public:
87  : cloned_(false) {
88  ExportBackupToRemotePackageCallback = [](const std::string& file_path, void* user_data) { return file_path; };
89  ExportBackupToRemoteEncryptCallback = [](const std::string& file_path, const std::string& encrypt_key, void* user_data) { return file_path; };
90  ExportBackupToRemoteLogFiter = [](const IMMessage& msg, void* user_data) { return true; };
91  LogsBackupProgressCallback = [](LogsBackupRemoteOperate, float, void* user_data) {};
92  LogsBackupCompleteCallback = [](LogsBackupRemoteOperate, LogsBackupRemoteState state, void* user_data) {
93  if (state >= LogsBackupRemoteState::LogsBackupRemoteState_FinalState_Begin)
94  delete CastToCPP(user_data);
95  };
96  }
97 
98 public:
99  void SetEncryptKey(const std::string& encrypt_key) { encrypt_key_ = encrypt_key; }
100  std::string GetEncryptKey() const { return encrypt_key_; }
101  void SetUserData(void* user_data) { NIMLogsBackupExportInfo::user_data_ = user_data; }
102  void* GetUserData() const { return NIMLogsBackupExportInfo::user_data_; }
103  NIMLogsBackupExportInfo* ToCStruct() const {
104  LogsBackupExportInfo* temp = new LogsBackupExportInfo(*this);
105  temp->SetUserData(GetUserData());
106  temp->cloned_ = true;
107  return temp->ToCStruct_i();
108  }
109 
110 private:
111  static inline LogsBackupExportInfo* CastToCPP(void* data) { return ((LogsBackupExportInfo*)(data)); }
112  NIMLogsBackupExportInfo* ToCStruct_i();
113 
114 public:
120  std::function<std::string(const std::string& file_path, void* user_data)> ExportBackupToRemotePackageCallback;
121 
128  std::function<std::string(const std::string& file_path, const std::string& encrypt_key, void* user_data)> ExportBackupToRemoteEncryptCallback;
129 
135  std::function<bool(const IMMessage& msg, void* user_data)> ExportBackupToRemoteLogFiter;
142  std::function<void(LogsBackupRemoteOperate op, float progress, void* user_data)> LogsBackupProgressCallback;
149  std::function<void(LogsBackupRemoteOperate op, LogsBackupRemoteState state, void* user_data)> LogsBackupCompleteCallback;
150 
151 private:
152  std::string encrypt_key_;
153  void* src_user_data_;
154  bool cloned_;
155 };
156 
158 class NIM_SDK_CPPWRAPPER_DLL_API LogsBackupImportInfo : public NIMLogsBackupImportInfo {
159 public:
161  ImportBackupFromRemoteUnPackageCallback = [](const std::string& file_path, void* user_data) { return file_path; };
162  ImportBackupFromRemoteDecryptCallback = [](const std::string& file_path, const std::string& encrypt_key, void* user_data) {
163  return file_path;
164  };
165  LogsBackupProgressCallback = [](LogsBackupRemoteOperate, float, void* user_data) {};
166  LogsBackupCompleteCallback = [](LogsBackupRemoteOperate, LogsBackupRemoteState state, void* user_data) {
167  if (state >= LogsBackupRemoteState::LogsBackupRemoteState_FinalState_Begin)
168  delete CastToCPP(user_data);
169  };
170  }
171 
172 public:
173  void SetUserData(void* user_data) { NIMLogsBackupImportInfo::user_data_ = user_data; }
174  void* GetUserData() const { return NIMLogsBackupImportInfo::user_data_; }
175  NIMLogsBackupImportInfo* ToCStruct() const {
176  LogsBackupImportInfo* temp = new LogsBackupImportInfo(*this);
177  temp->SetUserData(GetUserData());
178  temp->cloned_ = true;
179  return temp->ToCStruct_i();
180  }
181 
182 private:
183  NIMLogsBackupImportInfo* ToCStruct_i();
184  static inline LogsBackupImportInfo* CastToCPP(void* data) { return ((LogsBackupImportInfo*)(data)); }
185 
186 public:
192  std::function<std::string(const std::string& file_path, void* user_data)> ImportBackupFromRemoteUnPackageCallback;
193 
200  std::function<std::string(const std::string& file_path, const std::string& encrypt_key, void* user_data)> ImportBackupFromRemoteDecryptCallback;
201 
208  std::function<void(LogsBackupRemoteOperate, float, void* user_data)> LogsBackupProgressCallback;
209 
216  std::function<void(LogsBackupRemoteOperate, LogsBackupRemoteState, void* user_data)> LogsBackupCompleteCallback;
217 
218 private:
219  bool cloned_;
220  void* src_user_data_;
221 };
228 NIM_SDK_CPPWRAPPER_DLL_API bool ParseMsglogs(const std::string& msgs_json, QueryMsglogResult& res);
229 
230 } // namespace nim
231 
232 #endif //_NIM_SDK_CPP_MSGLOG_HELPER_H_
nim::ParseMsglogs
NIM_SDK_CPPWRAPPER_DLL_API bool ParseMsglogs(const std::string &msgs_json, QueryMsglogResult &res)
解析查询到的消息历史结果
nim::MessageStatusChanged
发送消息已读回执
Definition: nim_msglog_helper.h:53
nim::DeleteMsglogSelfNotifyItemInfo
单向删除消息记录回调参数
Definition: nim_msglog_helper.h:42
nim::LogsBackupExportInfo::ExportBackupToRemoteLogFiter
std::function< bool(const IMMessage &msg, void *user_data)> ExportBackupToRemoteLogFiter
Definition: nim_msglog_helper.h:135
nim::LogsBackupImportInfo::LogsBackupProgressCallback
std::function< void(LogsBackupRemoteOperate, float, void *user_data)> LogsBackupProgressCallback
Definition: nim_msglog_helper.h:208
nim::LogsBackupImportInfo::ImportBackupFromRemoteDecryptCallback
std::function< std::string(const std::string &file_path, const std::string &encrypt_key, void *user_data)> ImportBackupFromRemoteDecryptCallback
Definition: nim_msglog_helper.h:200
nim::MessageStatusChangedResult
发送消息已读回执
Definition: nim_msglog_helper.h:63
nim::MessageStatusChanged::status_
NIMMsgLogStatus status_
Definition: nim_msglog_helper.h:54
nim_talk_helper.h
Talk 辅助方法和数据结构定义
nim::LogsBackupImportInfo::ImportBackupFromRemoteUnPackageCallback
std::function< std::string(const std::string &file_path, void *user_data)> ImportBackupFromRemoteUnPackageCallback
Definition: nim_msglog_helper.h:192
nim::QueryMsglogResult::msglogs_
std::list< IMMessage > msglogs_
Definition: nim_msglog_helper.h:25
nim::QueryMsglogResult::count_
int count_
Definition: nim_msglog_helper.h:23
nim
namespace nim
nim::LogsBackupImportInfo
从云端导入消息记录参数定义
Definition: nim_msglog_helper.h:158
nim::LogsBackupExportInfo::LogsBackupProgressCallback
std::function< void(LogsBackupRemoteOperate op, float progress, void *user_data)> LogsBackupProgressCallback
Definition: nim_msglog_helper.h:142
nim::LogsBackupExportInfo::ExportBackupToRemoteEncryptCallback
std::function< std::string(const std::string &file_path, const std::string &encrypt_key, void *user_data)> ExportBackupToRemoteEncryptCallback
Definition: nim_msglog_helper.h:128
nim::LogsBackupExportInfo
导出消息记录到云端参数定义
Definition: nim_msglog_helper.h:84
nim::MessageStatusChangedResult::results_
std::list< MessageStatusChanged > results_
Definition: nim_msglog_helper.h:65
nim::LogsBackupImportInfo::LogsBackupCompleteCallback
std::function< void(LogsBackupRemoteOperate, LogsBackupRemoteState, void *user_data)> LogsBackupCompleteCallback
Definition: nim_msglog_helper.h:216
nim::MessageStatusChanged::msg_timetag_
int64_t msg_timetag_
Definition: nim_msglog_helper.h:56
nim::DeleteMsglogSelfNotifyParam::item_list
std::list< DeleteMsglogSelfNotifyItemInfo > item_list
Definition: nim_msglog_helper.h:49
nim::MessageStatusChanged::talk_id_
std::string talk_id_
Definition: nim_msglog_helper.h:55
nim::QueryMsglogResult::QueryMsglogResult
QueryMsglogResult()
Definition: nim_msglog_helper.h:28
nim::MessageStatusChangedResult::rescode_
NIMResCode rescode_
Definition: nim_msglog_helper.h:64
nim::LogsBackupExportInfo::LogsBackupCompleteCallback
std::function< void(LogsBackupRemoteOperate op, LogsBackupRemoteState state, void *user_data)> LogsBackupCompleteCallback
Definition: nim_msglog_helper.h:149
nim::LogsBackupExportInfo::ExportBackupToRemotePackageCallback
std::function< std::string(const std::string &file_path, void *user_data)> ExportBackupToRemotePackageCallback
Definition: nim_msglog_helper.h:120
nim::QueryMsglogResult
查询到消息历史结果
Definition: nim_msglog_helper.h:22
nim::DeleteMsglogSelfNotifyParam
单向删除消息记录回调参数
Definition: nim_msglog_helper.h:48
nim_sdk_cpp_wrapper.h
定义导出宏
nim::QueryMsglogResult::source_
NIMMsglogQuerySource source_
Definition: nim_msglog_helper.h:24
nim::IMMessage
Definition: nim_talk_helper.h:232