Add td_api::factCheck.

This commit is contained in:
levlam 2024-05-17 16:04:47 +03:00
parent b6f1a2e195
commit 45baefbf46
6 changed files with 198 additions and 0 deletions

View File

@ -357,6 +357,7 @@ set(TDLIB_SOURCE
td/telegram/EmojiGroup.cpp
td/telegram/EmojiGroupType.cpp
td/telegram/EmojiStatus.cpp
td/telegram/FactCheck.cpp
td/telegram/FileReferenceManager.cpp
td/telegram/files/FileBitmask.cpp
td/telegram/files/FileDb.cpp
@ -673,6 +674,7 @@ set(TDLIB_SOURCE
td/telegram/EmojiGroupType.h
td/telegram/EmojiStatus.h
td/telegram/EncryptedFile.h
td/telegram/FactCheck.h
td/telegram/FileReferenceManager.h
td/telegram/files/FileBitmask.h
td/telegram/files/FileData.h
@ -940,6 +942,7 @@ set(TDLIB_SOURCE
td/telegram/DocumentsManager.hpp
td/telegram/DraftMessage.hpp
td/telegram/EmojiGroup.hpp
td/telegram/FactCheck.hpp
td/telegram/FileReferenceManager.hpp
td/telegram/files/FileData.hpp
td/telegram/files/FileId.hpp

View File

@ -351,6 +351,7 @@ function split_file($file, $chunks, $undo) {
'EmailVerification' => 'EmailVerification',
'EmojiGroup' => 'EmojiGroup',
'EmojiStatus|[a-z_]*_emoji_status' => 'EmojiStatus',
'FactCheck' => 'FactCheck',
'file_reference_manager[_(-](?![.]get[(][)])|FileReferenceManager|file_references[)]' => 'FileReferenceManager',
'file_manager[_(-](?![.]get[(][)])|FileManager([^ ;.]| [^*])|update_file[)]' => 'files/FileManager',
'FolderId' => 'FolderId',

View File

@ -1524,6 +1524,12 @@ inputMessageReplyToMessage chat_id:int53 message_id:int53 quote:inputTextQuote =
inputMessageReplyToStory story_sender_chat_id:int53 story_id:int32 = InputMessageReplyTo;
//@description Describes a fact check added to the message by an independent checker
//@text Text of the fact check
//@country_code A two-letter ISO 3166-1 alpha-2 country code of the country for which the fact check is shown
factCheck text:formattedText country_code:string = FactCheck;
//@description Describes a message
//@id Message identifier; unique for the chat to which the message belongs
//@sender_id Identifier of the sender of the message

68
td/telegram/FactCheck.cpp Normal file
View File

@ -0,0 +1,68 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// 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)
//
#include "td/telegram/FactCheck.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/Td.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserManager.h"
namespace td {
FactCheck::~FactCheck() = default;
unique_ptr<FactCheck> FactCheck::get_fact_check(Td *td, telegram_api::object_ptr<telegram_api::factCheck> &&fact_check,
bool is_bot) {
if (is_bot || fact_check == nullptr || fact_check->hash_ == 0) {
return nullptr;
}
auto result = make_unique<FactCheck>();
result->country_code_ = std::move(fact_check->country_);
if (fact_check->text_ != nullptr) {
result->text_ = get_formatted_text(td->user_manager_.get(), std::move(fact_check->text_), true, false, "factCheck");
}
result->hash_ = fact_check->hash_;
result->need_check_ = fact_check->need_check_;
return result;
}
void FactCheck::update_from(const FactCheck &old_fact_check) {
if (!need_check_ || old_fact_check.need_check_ || hash_ != old_fact_check.hash_) {
return;
}
need_check_ = false;
country_code_ = old_fact_check.country_code_;
text_ = old_fact_check.text_;
}
void FactCheck::add_dependencies(Dependencies &dependencies) const {
add_formatted_text_dependencies(dependencies, &text_);
}
td_api::object_ptr<td_api::factCheck> FactCheck::get_fact_check_object() const {
if (is_empty() || need_check_) {
return nullptr;
}
return td_api::make_object<td_api::factCheck>(get_formatted_text_object(text_, true, -1), country_code_);
}
bool operator==(const unique_ptr<FactCheck> &lhs, const unique_ptr<FactCheck> &rhs) {
if (lhs == nullptr) {
return rhs == nullptr;
}
if (rhs == nullptr) {
return false;
}
return lhs->country_code_ == rhs->country_code_ && lhs->text_ == rhs->text_ && lhs->hash_ == rhs->hash_ &&
lhs->need_check_ == rhs->need_check_;
}
bool operator!=(const unique_ptr<FactCheck> &lhs, const unique_ptr<FactCheck> &rhs) {
return !(lhs == rhs);
}
} // namespace td

65
td/telegram/FactCheck.h Normal file
View File

@ -0,0 +1,65 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// 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
#include "td/telegram/MessageEntity.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/utils/common.h"
namespace td {
class Dependencies;
class Td;
class FactCheck {
string country_code_;
FormattedText text_;
int64 hash_ = 0;
bool need_check_ = false;
friend bool operator==(const unique_ptr<FactCheck> &lhs, const unique_ptr<FactCheck> &rhs);
public:
FactCheck() = default;
FactCheck(const FactCheck &) = delete;
FactCheck &operator=(const FactCheck &) = delete;
FactCheck(FactCheck &&) = default;
FactCheck &operator=(FactCheck &&) = default;
~FactCheck();
static unique_ptr<FactCheck> get_fact_check(Td *td, telegram_api::object_ptr<telegram_api::factCheck> &&fact_check,
bool is_bot);
bool is_empty() const {
return hash_ == 0;
}
bool need_check() const {
return hash_ == 0;
}
void update_from(const FactCheck &old_fact_check);
void add_dependencies(Dependencies &dependencies) const;
td_api::object_ptr<td_api::factCheck> get_fact_check_object() const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
bool operator==(const unique_ptr<FactCheck> &lhs, const unique_ptr<FactCheck> &rhs);
bool operator!=(const unique_ptr<FactCheck> &lhs, const unique_ptr<FactCheck> &rhs);
} // namespace td

55
td/telegram/FactCheck.hpp Normal file
View File

@ -0,0 +1,55 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// 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
#include "td/telegram/FactCheck.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void FactCheck::store(StorerT &storer) const {
CHECK(!is_empty());
bool has_country_code = !country_code_.empty();
bool has_text = !text_.text.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(need_check_);
STORE_FLAG(has_country_code);
STORE_FLAG(has_text);
END_STORE_FLAGS();
td::store(hash_, storer);
if (has_country_code) {
td::store(country_code_, storer);
}
if (has_text) {
td::store(text_, storer);
}
}
template <class ParserT>
void FactCheck::parse(ParserT &parser) {
bool has_country_code;
bool has_text;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(need_check_);
PARSE_FLAG(has_country_code);
PARSE_FLAG(has_text);
END_PARSE_FLAGS();
td::parse(hash_, parser);
if (has_country_code) {
td::parse(country_code_, parser);
}
if (has_text) {
td::parse(text_, parser);
}
if (is_empty()) {
parser.set_error("Load an empty fact check");
}
}
} // namespace td