2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
2021-08-01 05:17:51 +02:00
|
|
|
#include "td/telegram/EncryptedFile.h"
|
2021-07-05 04:12:04 +02:00
|
|
|
#include "td/telegram/Global.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/logevent/LogEvent.h"
|
2021-07-05 04:12:04 +02:00
|
|
|
#include "td/telegram/secret_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
#include "td/telegram/UserId.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-07-03 21:29:04 +02:00
|
|
|
#include "td/actor/PromiseFuture.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/buffer.h"
|
2019-02-12 21:48:16 +01:00
|
|
|
#include "td/utils/common.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/format.h"
|
2021-07-05 18:28:39 +02:00
|
|
|
#include "td/utils/SliceBuilder.h"
|
2021-07-05 04:25:23 +02:00
|
|
|
#include "td/utils/Status.h"
|
2021-07-05 18:28:39 +02:00
|
|
|
#include "td/utils/StorerBase.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
#include "td/utils/tl_helpers.h"
|
2021-07-05 04:12:04 +02:00
|
|
|
#include "td/utils/tl_parsers.h"
|
2021-07-05 04:25:23 +02:00
|
|
|
#include "td/utils/tl_storers.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-07-05 04:12:04 +02:00
|
|
|
#include <type_traits>
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
namespace td {
|
2020-09-22 01:15:09 +02:00
|
|
|
namespace log_event {
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-07-05 04:25:23 +02:00
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class StorerImpl final : public Storer {
|
|
|
|
public:
|
|
|
|
explicit StorerImpl(const T &event) : event_(event) {
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t size() const final {
|
|
|
|
WithContext<TlStorerCalcLength, Global *> storer;
|
|
|
|
storer.set_context(G());
|
|
|
|
|
|
|
|
storer.store_int(T::version());
|
|
|
|
td::store(static_cast<int32>(event_.get_type()), storer);
|
|
|
|
td::store(event_, storer);
|
|
|
|
return storer.get_length();
|
|
|
|
}
|
|
|
|
size_t store(uint8 *ptr) const final {
|
|
|
|
WithContext<TlStorerUnsafe, Global *> storer(ptr);
|
|
|
|
storer.set_context(G());
|
|
|
|
|
|
|
|
storer.store_int(T::version());
|
|
|
|
td::store(static_cast<int32>(event_.get_type()), storer);
|
|
|
|
td::store(event_, storer);
|
|
|
|
return static_cast<size_t>(storer.get_buf() - ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const T &event_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
2021-07-05 04:12:04 +02:00
|
|
|
class SecretChatEvent : public LogEvent {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
// append only enum
|
|
|
|
enum class Type : int32 {
|
|
|
|
InboundSecretMessage = 1,
|
|
|
|
OutboundSecretMessage = 2,
|
|
|
|
CloseSecretChat = 3,
|
|
|
|
CreateSecretChat = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual Type get_type() const = 0;
|
|
|
|
|
|
|
|
static constexpr int32 version() {
|
2021-09-03 11:27:59 +02:00
|
|
|
return 4;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class F>
|
|
|
|
static void downcast_call(Type type, F &&f);
|
2021-07-05 04:12:04 +02:00
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
|
|
|
downcast_call(get_type(),
|
|
|
|
[&](auto *ptr) { static_cast<const std::decay_t<decltype(*ptr)> *>(this)->store(storer); });
|
|
|
|
}
|
|
|
|
|
|
|
|
static Result<unique_ptr<SecretChatEvent>> from_buffer_slice(BufferSlice slice) {
|
2021-07-05 04:25:23 +02:00
|
|
|
WithVersion<WithContext<TlBufferParser, Global *>> parser{&slice};
|
|
|
|
auto version = parser.fetch_int();
|
|
|
|
parser.set_version(version);
|
|
|
|
parser.set_context(G());
|
|
|
|
auto magic = static_cast<Type>(parser.fetch_int());
|
|
|
|
|
|
|
|
unique_ptr<SecretChatEvent> event;
|
|
|
|
downcast_call(magic, [&](auto *ptr) {
|
|
|
|
auto tmp = make_unique<std::decay_t<decltype(*ptr)>>();
|
|
|
|
tmp->parse(parser);
|
|
|
|
event = std::move(tmp);
|
|
|
|
});
|
|
|
|
parser.fetch_end();
|
|
|
|
TRY_STATUS(parser.get_status());
|
|
|
|
if (event != nullptr) {
|
|
|
|
return std::move(event);
|
|
|
|
}
|
|
|
|
return Status::Error(PSLICE() << "Unknown SecretChatEvent type: " << format::as_hex(magic));
|
2021-07-05 04:12:04 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2019-02-22 16:33:14 +01:00
|
|
|
template <class ChildT>
|
|
|
|
class SecretChatLogEventBase : public SecretChatEvent {
|
|
|
|
public:
|
2021-07-03 22:51:36 +02:00
|
|
|
typename SecretChatEvent::Type get_type() const final {
|
2019-02-22 16:33:14 +01:00
|
|
|
return ChildT::type;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr int32 magic() const {
|
|
|
|
return static_cast<int32>(get_type());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
// Internal structure
|
|
|
|
|
|
|
|
// inputEncryptedFileEmpty#1837c364 = InputEncryptedFile;
|
|
|
|
// inputEncryptedFileUploaded#64bd0306 id:long parts:int md5_checksum:string key_fingerprint:int = InputEncryptedFile;
|
|
|
|
// inputEncryptedFile#5a17b5e5 id:long access_hash:long = InputEncryptedFile;
|
|
|
|
// inputEncryptedFileBigUploaded#2dc173c8 id:long parts:int key_fingerprint:int = InputEncryptedFile;
|
|
|
|
struct EncryptedInputFile {
|
2020-06-16 04:10:16 +02:00
|
|
|
static constexpr int32 MAGIC = 0x4328d38a;
|
2018-10-26 16:11:20 +02:00
|
|
|
enum Type : int32 { Empty = 0, Uploaded = 1, BigUploaded = 2, Location = 3 } type = Type::Empty;
|
|
|
|
int64 id = 0;
|
|
|
|
int64 access_hash = 0;
|
|
|
|
int32 parts = 0;
|
|
|
|
int32 key_fingerprint = 0;
|
2018-10-26 17:04:04 +02:00
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
2018-12-31 20:04:05 +01:00
|
|
|
using td::store;
|
2020-06-16 04:10:16 +02:00
|
|
|
store(MAGIC, storer);
|
2018-12-31 20:04:05 +01:00
|
|
|
store(type, storer);
|
|
|
|
store(id, storer);
|
|
|
|
store(access_hash, storer);
|
|
|
|
store(parts, storer);
|
|
|
|
store(key_fingerprint, storer);
|
|
|
|
}
|
|
|
|
|
2018-10-26 17:36:53 +02:00
|
|
|
EncryptedInputFile() = default;
|
2018-10-26 17:04:04 +02:00
|
|
|
EncryptedInputFile(Type type, int64 id, int64 access_hash, int32 parts, int32 key_fingerprint)
|
|
|
|
: type(type), id(id), access_hash(access_hash), parts(parts), key_fingerprint(key_fingerprint) {
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool empty() const {
|
|
|
|
return type == Empty;
|
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
2018-12-31 20:04:05 +01:00
|
|
|
using td::parse;
|
|
|
|
int32 got_magic;
|
|
|
|
|
|
|
|
parse(got_magic, parser);
|
|
|
|
parse(type, parser);
|
|
|
|
parse(id, parser);
|
|
|
|
parse(access_hash, parser);
|
|
|
|
parse(parts, parser);
|
|
|
|
parse(key_fingerprint, parser);
|
|
|
|
|
2020-06-16 04:10:16 +02:00
|
|
|
if (got_magic != MAGIC) {
|
2018-12-31 20:04:05 +01:00
|
|
|
parser.set_error("EncryptedInputFile magic mismatch");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static EncryptedInputFile from_input_encrypted_file(const tl_object_ptr<telegram_api::InputEncryptedFile> &from) {
|
|
|
|
if (!from) {
|
|
|
|
return EncryptedInputFile{Empty, 0, 0, 0, 0};
|
|
|
|
}
|
|
|
|
return from_input_encrypted_file(*from);
|
|
|
|
}
|
|
|
|
static EncryptedInputFile from_input_encrypted_file(const telegram_api::InputEncryptedFile &from) {
|
|
|
|
switch (from.get_id()) {
|
|
|
|
case telegram_api::inputEncryptedFileEmpty::ID:
|
|
|
|
return EncryptedInputFile{Empty, 0, 0, 0, 0};
|
|
|
|
case telegram_api::inputEncryptedFileUploaded::ID: {
|
|
|
|
auto &uploaded = static_cast<const telegram_api::inputEncryptedFileUploaded &>(from);
|
|
|
|
return EncryptedInputFile{Uploaded, uploaded.id_, 0, uploaded.parts_, uploaded.key_fingerprint_};
|
|
|
|
}
|
|
|
|
case telegram_api::inputEncryptedFileBigUploaded::ID: {
|
|
|
|
auto &uploaded = static_cast<const telegram_api::inputEncryptedFileBigUploaded &>(from);
|
|
|
|
return EncryptedInputFile{BigUploaded, uploaded.id_, 0, uploaded.parts_, uploaded.key_fingerprint_};
|
|
|
|
}
|
|
|
|
case telegram_api::inputEncryptedFile::ID: {
|
|
|
|
auto &uploaded = static_cast<const telegram_api::inputEncryptedFile &>(from);
|
|
|
|
return EncryptedInputFile{Location, uploaded.id_, uploaded.access_hash_, 0, 0};
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tl_object_ptr<telegram_api::InputEncryptedFile> as_input_encrypted_file() const {
|
|
|
|
switch (type) {
|
|
|
|
case Empty:
|
|
|
|
return make_tl_object<telegram_api::inputEncryptedFileEmpty>();
|
|
|
|
case Uploaded:
|
|
|
|
return make_tl_object<telegram_api::inputEncryptedFileUploaded>(id, parts, "", key_fingerprint);
|
|
|
|
case BigUploaded:
|
|
|
|
return make_tl_object<telegram_api::inputEncryptedFileBigUploaded>(id, parts, key_fingerprint);
|
|
|
|
case Location:
|
|
|
|
return make_tl_object<telegram_api::inputEncryptedFile>(id, access_hash);
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
inline StringBuilder &operator<<(StringBuilder &sb, const EncryptedInputFile &file) {
|
|
|
|
return sb << to_string(file.as_input_encrypted_file());
|
|
|
|
}
|
|
|
|
|
|
|
|
// LogEvents
|
|
|
|
// TODO: Qts and SeqNoState could be just Logevents that are updated during regenerate
|
2021-07-04 04:58:54 +02:00
|
|
|
class InboundSecretMessage final : public SecretChatLogEventBase<InboundSecretMessage> {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
static constexpr Type type = SecretChatEvent::Type::InboundSecretMessage;
|
|
|
|
|
|
|
|
int32 chat_id = 0;
|
|
|
|
int32 date = 0;
|
|
|
|
|
|
|
|
BufferSlice encrypted_message; // empty when we store event to binlog
|
2020-08-02 21:07:22 +02:00
|
|
|
Promise<Unit> promise;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
bool is_checked = false;
|
|
|
|
// after decrypted and checked
|
|
|
|
tl_object_ptr<secret_api::decryptedMessageLayer> decrypted_message_layer;
|
|
|
|
|
|
|
|
uint64 auth_key_id = 0;
|
|
|
|
int32 message_id = 0;
|
|
|
|
int32 my_in_seq_no = -1;
|
|
|
|
int32 my_out_seq_no = -1;
|
|
|
|
int32 his_in_seq_no = -1;
|
|
|
|
|
2018-06-14 17:00:10 +02:00
|
|
|
int32 his_layer() const {
|
|
|
|
return decrypted_message_layer->layer_;
|
|
|
|
}
|
|
|
|
|
2021-08-01 05:17:51 +02:00
|
|
|
unique_ptr<EncryptedFile> file;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
bool is_pending = false;
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
2018-12-31 20:04:05 +01:00
|
|
|
using td::store;
|
|
|
|
|
2021-08-01 05:17:51 +02:00
|
|
|
bool has_encrypted_file = file != nullptr;
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_encrypted_file);
|
|
|
|
STORE_FLAG(is_pending);
|
2020-08-02 00:21:43 +02:00
|
|
|
STORE_FLAG(true);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
|
|
|
|
store(chat_id, storer);
|
|
|
|
store(date, storer);
|
|
|
|
// skip encrypted_message
|
2020-08-02 21:07:22 +02:00
|
|
|
// skip promise
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
// TODO
|
|
|
|
decrypted_message_layer->store(storer);
|
|
|
|
storer.store_long(static_cast<int64>(auth_key_id));
|
|
|
|
|
|
|
|
store(message_id, storer);
|
|
|
|
store(my_in_seq_no, storer);
|
|
|
|
store(my_out_seq_no, storer);
|
|
|
|
store(his_in_seq_no, storer);
|
|
|
|
if (has_encrypted_file) {
|
|
|
|
store(file, storer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
2018-12-31 20:04:05 +01:00
|
|
|
using td::parse;
|
|
|
|
|
2021-08-01 05:17:51 +02:00
|
|
|
bool has_encrypted_file;
|
2020-08-02 00:21:43 +02:00
|
|
|
bool no_qts;
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_encrypted_file);
|
|
|
|
PARSE_FLAG(is_pending);
|
2020-08-02 00:21:43 +02:00
|
|
|
PARSE_FLAG(no_qts);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
|
2020-08-02 00:21:43 +02:00
|
|
|
if (!no_qts) {
|
|
|
|
int32 legacy_qts;
|
|
|
|
parse(legacy_qts, parser);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
parse(chat_id, parser);
|
|
|
|
parse(date, parser);
|
|
|
|
// skip encrypted_message
|
2020-08-02 21:07:22 +02:00
|
|
|
// skip promise
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
// TODO
|
|
|
|
decrypted_message_layer = secret_api::decryptedMessageLayer::fetch(parser);
|
|
|
|
auth_key_id = static_cast<uint64>(parser.fetch_long());
|
|
|
|
|
|
|
|
parse(message_id, parser);
|
|
|
|
parse(my_in_seq_no, parser);
|
|
|
|
parse(my_out_seq_no, parser);
|
|
|
|
parse(his_in_seq_no, parser);
|
|
|
|
if (has_encrypted_file) {
|
|
|
|
parse(file, parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
is_checked = true;
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
StringBuilder &print(StringBuilder &sb) const final {
|
2020-09-22 01:15:09 +02:00
|
|
|
return sb << "[Logevent InboundSecretMessage " << tag("id", log_event_id()) << tag("chat_id", chat_id)
|
2020-08-02 00:21:43 +02:00
|
|
|
<< tag("date", date) << tag("auth_key_id", format::as_hex(auth_key_id)) << tag("message_id", message_id)
|
|
|
|
<< tag("my_in_seq_no", my_in_seq_no) << tag("my_out_seq_no", my_out_seq_no)
|
|
|
|
<< tag("his_in_seq_no", his_in_seq_no) << tag("message", to_string(decrypted_message_layer))
|
2021-08-01 05:17:51 +02:00
|
|
|
<< tag("is_pending", is_pending) << format::cond(file != nullptr, tag("file", *file)) << "]";
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class OutboundSecretMessage final : public SecretChatLogEventBase<OutboundSecretMessage> {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
static constexpr Type type = SecretChatEvent::Type::OutboundSecretMessage;
|
|
|
|
|
|
|
|
int32 chat_id = 0;
|
|
|
|
int64 random_id = 0;
|
|
|
|
|
|
|
|
BufferSlice encrypted_message;
|
|
|
|
EncryptedInputFile file;
|
|
|
|
|
|
|
|
int32 message_id = 0;
|
|
|
|
int32 my_in_seq_no = -1;
|
|
|
|
int32 my_out_seq_no = -1;
|
|
|
|
int32 his_in_seq_no = -1;
|
|
|
|
|
2018-06-14 17:00:10 +02:00
|
|
|
int32 his_layer() const {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_sent = false;
|
2020-06-09 13:34:48 +02:00
|
|
|
// need send push notification to the receiver
|
2020-06-09 16:18:59 +02:00
|
|
|
// should send such messages with messages_sendEncryptedService
|
2020-06-09 13:34:48 +02:00
|
|
|
bool need_notify_user = false;
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_rewritable = false;
|
2020-06-09 13:34:48 +02:00
|
|
|
// should notify our parent about state of this message (using context and random_id)
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_external = false;
|
2020-08-21 14:38:23 +02:00
|
|
|
bool is_silent = false;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
tl_object_ptr<secret_api::DecryptedMessageAction> action;
|
|
|
|
uint64 crc = 0; // DEBUG;
|
|
|
|
|
|
|
|
// Flags:
|
|
|
|
// 2. can_fail = !file.empty() // send of other messages can't fail if chat is ok. It is usless to rewrite them with
|
|
|
|
// empty
|
|
|
|
// 3. can_rewrite_with_empty // false for almost all service messages
|
|
|
|
|
2018-12-26 17:11:15 +01:00
|
|
|
// TODO: combine these two functions into one macros hell. Or a lambda hell.
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
2018-12-31 20:04:05 +01:00
|
|
|
using td::store;
|
|
|
|
|
|
|
|
store(chat_id, storer);
|
|
|
|
store(random_id, storer);
|
|
|
|
store(encrypted_message, storer);
|
|
|
|
store(file, storer);
|
|
|
|
store(message_id, storer);
|
|
|
|
store(my_in_seq_no, storer);
|
|
|
|
store(my_out_seq_no, storer);
|
|
|
|
store(his_in_seq_no, storer);
|
|
|
|
|
2021-01-18 13:04:31 +01:00
|
|
|
bool has_action = action != nullptr;
|
2018-12-31 20:04:05 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(is_sent);
|
2020-06-09 13:34:48 +02:00
|
|
|
STORE_FLAG(need_notify_user);
|
2018-12-31 20:04:05 +01:00
|
|
|
STORE_FLAG(has_action);
|
|
|
|
STORE_FLAG(is_rewritable);
|
|
|
|
STORE_FLAG(is_external);
|
2020-08-21 14:38:23 +02:00
|
|
|
STORE_FLAG(is_silent);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
|
|
|
|
if (has_action) {
|
|
|
|
CHECK(action);
|
|
|
|
// TODO
|
|
|
|
storer.store_int(action->get_id());
|
|
|
|
action->store(storer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
2018-12-31 20:04:05 +01:00
|
|
|
using td::parse;
|
|
|
|
|
|
|
|
parse(chat_id, parser);
|
|
|
|
parse(random_id, parser);
|
|
|
|
parse(encrypted_message, parser);
|
|
|
|
parse(file, parser);
|
|
|
|
parse(message_id, parser);
|
|
|
|
parse(my_in_seq_no, parser);
|
|
|
|
parse(my_out_seq_no, parser);
|
|
|
|
parse(his_in_seq_no, parser);
|
|
|
|
|
|
|
|
bool has_action;
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(is_sent);
|
2020-06-09 13:34:48 +02:00
|
|
|
PARSE_FLAG(need_notify_user);
|
2018-12-31 20:04:05 +01:00
|
|
|
PARSE_FLAG(has_action);
|
|
|
|
PARSE_FLAG(is_rewritable);
|
|
|
|
PARSE_FLAG(is_external);
|
2020-08-21 14:38:23 +02:00
|
|
|
PARSE_FLAG(is_silent);
|
2018-12-31 20:04:05 +01:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
|
|
|
|
if (has_action) {
|
|
|
|
// TODO:
|
|
|
|
action = secret_api::DecryptedMessageAction::fetch(parser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
StringBuilder &print(StringBuilder &sb) const final {
|
2020-09-22 01:15:09 +02:00
|
|
|
return sb << "[Logevent OutboundSecretMessage " << tag("id", log_event_id()) << tag("chat_id", chat_id)
|
2020-06-09 13:34:48 +02:00
|
|
|
<< tag("is_sent", is_sent) << tag("need_notify_user", need_notify_user)
|
|
|
|
<< tag("is_rewritable", is_rewritable) << tag("is_external", is_external) << tag("message_id", message_id)
|
|
|
|
<< tag("random_id", random_id) << tag("my_in_seq_no", my_in_seq_no) << tag("my_out_seq_no", my_out_seq_no)
|
2018-07-24 00:45:44 +02:00
|
|
|
<< tag("his_in_seq_no", his_in_seq_no) << tag("file", file) << tag("action", to_string(action)) << "]";
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class CloseSecretChat final : public SecretChatLogEventBase<CloseSecretChat> {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
static constexpr Type type = SecretChatEvent::Type::CloseSecretChat;
|
|
|
|
int32 chat_id = 0;
|
2021-01-18 13:04:31 +01:00
|
|
|
bool delete_history = false;
|
2021-01-18 17:02:24 +01:00
|
|
|
bool is_already_discarded = false;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
2018-12-31 20:04:05 +01:00
|
|
|
using td::store;
|
2021-01-18 13:04:31 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(delete_history);
|
2021-01-18 17:02:24 +01:00
|
|
|
STORE_FLAG(is_already_discarded);
|
2021-01-18 13:04:31 +01:00
|
|
|
END_STORE_FLAGS();
|
2018-12-31 20:04:05 +01:00
|
|
|
store(chat_id, storer);
|
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
2018-12-31 20:04:05 +01:00
|
|
|
using td::parse;
|
2021-01-18 13:04:31 +01:00
|
|
|
if (parser.version() >= 3) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(delete_history);
|
2021-01-18 17:02:24 +01:00
|
|
|
PARSE_FLAG(is_already_discarded);
|
2021-01-18 13:04:31 +01:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
parse(chat_id, parser);
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
StringBuilder &print(StringBuilder &sb) const final {
|
2021-01-18 13:04:31 +01:00
|
|
|
return sb << "[Logevent CloseSecretChat " << tag("id", log_event_id()) << tag("chat_id", chat_id)
|
2021-01-18 17:02:24 +01:00
|
|
|
<< tag("delete_history", delete_history) << tag("is_already_discarded", is_already_discarded) << "]";
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class CreateSecretChat final : public SecretChatLogEventBase<CreateSecretChat> {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
static constexpr Type type = SecretChatEvent::Type::CreateSecretChat;
|
|
|
|
int32 random_id = 0;
|
2021-03-29 10:57:26 +02:00
|
|
|
UserId user_id;
|
2018-12-31 20:04:05 +01:00
|
|
|
int64 user_access_hash = 0;
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const {
|
2018-12-31 20:04:05 +01:00
|
|
|
using td::store;
|
|
|
|
store(random_id, storer);
|
2021-09-03 11:27:59 +02:00
|
|
|
store(user_id, storer);
|
2018-12-31 20:04:05 +01:00
|
|
|
store(user_access_hash, storer);
|
|
|
|
}
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser) {
|
2018-12-31 20:04:05 +01:00
|
|
|
using td::parse;
|
|
|
|
parse(random_id, parser);
|
2021-09-22 09:23:06 +02:00
|
|
|
user_id = UserId(parser.version() >= 4 ? parser.fetch_long() : static_cast<int64>(parser.fetch_int()));
|
2018-12-31 20:04:05 +01:00
|
|
|
parse(user_access_hash, parser);
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
StringBuilder &print(StringBuilder &sb) const final {
|
2021-03-29 10:57:26 +02:00
|
|
|
return sb << "[Logevent CreateSecretChat " << tag("id", log_event_id()) << tag("chat_id", random_id) << user_id
|
|
|
|
<< "]";
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class F>
|
|
|
|
void SecretChatEvent::downcast_call(Type type, F &&f) {
|
|
|
|
switch (type) {
|
|
|
|
case Type::InboundSecretMessage:
|
|
|
|
f(static_cast<InboundSecretMessage *>(nullptr));
|
|
|
|
break;
|
|
|
|
case Type::OutboundSecretMessage:
|
|
|
|
f(static_cast<OutboundSecretMessage *>(nullptr));
|
|
|
|
break;
|
|
|
|
case Type::CloseSecretChat:
|
|
|
|
f(static_cast<CloseSecretChat *>(nullptr));
|
|
|
|
break;
|
|
|
|
case Type::CreateSecretChat:
|
|
|
|
f(static_cast<CreateSecretChat *>(nullptr));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-09-22 01:15:09 +02:00
|
|
|
} // namespace log_event
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-09-22 01:15:09 +02:00
|
|
|
inline auto create_storer(log_event::SecretChatEvent &event) {
|
|
|
|
return log_event::detail::StorerImpl<log_event::SecretChatEvent>(event);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|