Make td_api::saveApplicationLogEvent persistent.
This commit is contained in:
parent
0147c97f9c
commit
6898d07793
@ -26,6 +26,7 @@ inputStickerSetThumbLegacy#dbaeae9 stickerset:InputStickerSet volume_id:long loc
|
|||||||
|
|
||||||
test.useError = Error;
|
test.useError = Error;
|
||||||
test.useConfigSimple = help.ConfigSimple;
|
test.useConfigSimple = help.ConfigSimple;
|
||||||
|
test.parseInputAppEvent = InputAppEvent;
|
||||||
|
|
||||||
---types---
|
---types---
|
||||||
|
|
||||||
|
@ -7,11 +7,18 @@
|
|||||||
#include "td/telegram/Application.h"
|
#include "td/telegram/Application.h"
|
||||||
|
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
|
#include "td/telegram/logevent/LogEvent.h"
|
||||||
|
#include "td/telegram/logevent/LogEventHelper.h"
|
||||||
#include "td/telegram/Td.h"
|
#include "td/telegram/Td.h"
|
||||||
|
#include "td/telegram/TdDb.h"
|
||||||
|
|
||||||
|
#include "td/db/binlog/BinlogEvent.h"
|
||||||
|
#include "td/db/binlog/BinlogHelper.h"
|
||||||
|
|
||||||
#include "td/utils/buffer.h"
|
#include "td/utils/buffer.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
|
#include "td/utils/tl_parsers.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
@ -48,11 +55,9 @@ class SaveAppLogQuery final : public Td::ResultHandler {
|
|||||||
explicit SaveAppLogQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
explicit SaveAppLogQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void send(const string &type, DialogId dialog_id, tl_object_ptr<telegram_api::JSONValue> &&data) {
|
void send(telegram_api::object_ptr<telegram_api::inputAppEvent> &&input_app_event) {
|
||||||
CHECK(data != nullptr);
|
|
||||||
vector<telegram_api::object_ptr<telegram_api::inputAppEvent>> input_app_events;
|
vector<telegram_api::object_ptr<telegram_api::inputAppEvent>> input_app_events;
|
||||||
input_app_events.push_back(
|
input_app_events.push_back(std::move(input_app_event));
|
||||||
make_tl_object<telegram_api::inputAppEvent>(G()->server_time_cached(), type, dialog_id.get(), std::move(data)));
|
|
||||||
send_query(G()->net_query_creator().create_unauth(telegram_api::help_saveAppLog(std::move(input_app_events))));
|
send_query(G()->net_query_creator().create_unauth(telegram_api::help_saveAppLog(std::move(input_app_events))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,9 +81,55 @@ void get_invite_text(Td *td, Promise<string> &&promise) {
|
|||||||
td->create_handler<GetInviteTextQuery>(std::move(promise))->send();
|
td->create_handler<GetInviteTextQuery>(std::move(promise))->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SaveAppLogLogEvent {
|
||||||
|
public:
|
||||||
|
const telegram_api::inputAppEvent *input_app_event_in_ = nullptr;
|
||||||
|
telegram_api::object_ptr<telegram_api::inputAppEvent> input_app_event_out_;
|
||||||
|
|
||||||
|
template <class StorerT>
|
||||||
|
void store(StorerT &storer) const {
|
||||||
|
input_app_event_in_->store(storer);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ParserT>
|
||||||
|
void parse(ParserT &parser) {
|
||||||
|
auto buffer = parser.fetch_string_raw<BufferSlice>(parser.get_left_len());
|
||||||
|
TlBufferParser buffer_parser{&buffer};
|
||||||
|
input_app_event_out_ = telegram_api::make_object<telegram_api::inputAppEvent>(buffer_parser);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static void save_app_log_impl(Td *td, telegram_api::object_ptr<telegram_api::inputAppEvent> input_app_event,
|
||||||
|
uint64 log_event_id, Promise<Unit> &&promise) {
|
||||||
|
if (log_event_id == 0) {
|
||||||
|
SaveAppLogLogEvent log_event;
|
||||||
|
log_event.input_app_event_in_ = input_app_event.get();
|
||||||
|
log_event_id =
|
||||||
|
binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SaveAppLog, get_log_event_storer(log_event));
|
||||||
|
}
|
||||||
|
|
||||||
|
td->create_handler<SaveAppLogQuery>(get_erase_log_event_promise(log_event_id, std::move(promise)))
|
||||||
|
->send(std::move(input_app_event));
|
||||||
|
}
|
||||||
|
|
||||||
void save_app_log(Td *td, const string &type, DialogId dialog_id, tl_object_ptr<telegram_api::JSONValue> &&data,
|
void save_app_log(Td *td, const string &type, DialogId dialog_id, tl_object_ptr<telegram_api::JSONValue> &&data,
|
||||||
Promise<Unit> &&promise) {
|
Promise<Unit> &&promise) {
|
||||||
td->create_handler<SaveAppLogQuery>(std::move(promise))->send(type, dialog_id, std::move(data));
|
CHECK(data != nullptr);
|
||||||
|
auto input_app_event = telegram_api::make_object<telegram_api::inputAppEvent>(G()->server_time_cached(), type,
|
||||||
|
dialog_id.get(), std::move(data));
|
||||||
|
save_app_log_impl(td, std::move(input_app_event), 0, std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_save_app_log_binlog_event(Td *td, BinlogEvent &&event) {
|
||||||
|
if (G()->close_flag()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CHECK(event.id_ != 0);
|
||||||
|
CHECK(event.type_ == LogEvent::HandlerType::SaveAppLog);
|
||||||
|
SaveAppLogLogEvent log_event;
|
||||||
|
log_event_parse(log_event, event.data_).ensure();
|
||||||
|
|
||||||
|
save_app_log_impl(td, std::move(log_event.input_app_event_out_), event.id_, Promise<Unit>());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
|
struct BinlogEvent;
|
||||||
|
|
||||||
class Td;
|
class Td;
|
||||||
|
|
||||||
void get_invite_text(Td *td, Promise<string> &&promise);
|
void get_invite_text(Td *td, Promise<string> &&promise);
|
||||||
@ -21,4 +23,6 @@ void get_invite_text(Td *td, Promise<string> &&promise);
|
|||||||
void save_app_log(Td *td, const string &type, DialogId dialog_id, tl_object_ptr<telegram_api::JSONValue> &&data,
|
void save_app_log(Td *td, const string &type, DialogId dialog_id, tl_object_ptr<telegram_api::JSONValue> &&data,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
void on_save_app_log_binlog_event(Td *td, BinlogEvent &&event);
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -3801,6 +3801,10 @@ void Td::init(Result<TdDb::OpenedDatabase> r_opened_database) {
|
|||||||
web_pages_manager_->on_binlog_web_page_event(std::move(event));
|
web_pages_manager_->on_binlog_web_page_event(std::move(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto &event : events.save_app_log_events) {
|
||||||
|
on_save_app_log_binlog_event(this, std::move(event));
|
||||||
|
}
|
||||||
|
|
||||||
if (is_online_) {
|
if (is_online_) {
|
||||||
on_online_updated(true, true);
|
on_online_updated(true, true);
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,9 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue<Binlog> &binlog_p
|
|||||||
case LogEvent::HandlerType::EditMessagePushNotification:
|
case LogEvent::HandlerType::EditMessagePushNotification:
|
||||||
events.to_notification_manager.push_back(event.clone());
|
events.to_notification_manager.push_back(event.clone());
|
||||||
break;
|
break;
|
||||||
|
case LogEvent::HandlerType::SaveAppLog:
|
||||||
|
events.save_app_log_events.push_back(event.clone());
|
||||||
|
break;
|
||||||
case LogEvent::HandlerType::BinlogPmcMagic:
|
case LogEvent::HandlerType::BinlogPmcMagic:
|
||||||
binlog_pmc.external_init_handle(event);
|
binlog_pmc.external_init_handle(event);
|
||||||
break;
|
break;
|
||||||
|
@ -63,6 +63,7 @@ class TdDb {
|
|||||||
vector<BinlogEvent> channel_events;
|
vector<BinlogEvent> channel_events;
|
||||||
vector<BinlogEvent> secret_chat_events;
|
vector<BinlogEvent> secret_chat_events;
|
||||||
vector<BinlogEvent> web_page_events;
|
vector<BinlogEvent> web_page_events;
|
||||||
|
vector<BinlogEvent> save_app_log_events;
|
||||||
vector<BinlogEvent> to_poll_manager;
|
vector<BinlogEvent> to_poll_manager;
|
||||||
vector<BinlogEvent> to_messages_manager;
|
vector<BinlogEvent> to_messages_manager;
|
||||||
vector<BinlogEvent> to_notification_manager;
|
vector<BinlogEvent> to_notification_manager;
|
||||||
|
@ -104,6 +104,7 @@ class LogEvent {
|
|||||||
GetChannelDifference = 0x140,
|
GetChannelDifference = 0x140,
|
||||||
AddMessagePushNotification = 0x200,
|
AddMessagePushNotification = 0x200,
|
||||||
EditMessagePushNotification = 0x201,
|
EditMessagePushNotification = 0x201,
|
||||||
|
SaveAppLog = 0x300,
|
||||||
ConfigPmcMagic = 0x1f18,
|
ConfigPmcMagic = 0x1f18,
|
||||||
BinlogPmcMagic = 0x4327
|
BinlogPmcMagic = 0x4327
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user