Add td_api::webApp.
This commit is contained in:
parent
670a42885a
commit
2268ae87a4
@ -476,6 +476,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/VideoNotesManager.cpp
|
td/telegram/VideoNotesManager.cpp
|
||||||
td/telegram/VideosManager.cpp
|
td/telegram/VideosManager.cpp
|
||||||
td/telegram/VoiceNotesManager.cpp
|
td/telegram/VoiceNotesManager.cpp
|
||||||
|
td/telegram/WebApp.cpp
|
||||||
td/telegram/WebPageBlock.cpp
|
td/telegram/WebPageBlock.cpp
|
||||||
td/telegram/WebPagesManager.cpp
|
td/telegram/WebPagesManager.cpp
|
||||||
|
|
||||||
@ -758,6 +759,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/VideoNotesManager.h
|
td/telegram/VideoNotesManager.h
|
||||||
td/telegram/VideosManager.h
|
td/telegram/VideosManager.h
|
||||||
td/telegram/VoiceNotesManager.h
|
td/telegram/VoiceNotesManager.h
|
||||||
|
td/telegram/WebApp.h
|
||||||
td/telegram/WebPageBlock.h
|
td/telegram/WebPageBlock.h
|
||||||
td/telegram/WebPageId.h
|
td/telegram/WebPageId.h
|
||||||
td/telegram/WebPagesManager.h
|
td/telegram/WebPagesManager.h
|
||||||
@ -810,6 +812,7 @@ set(TDLIB_SOURCE
|
|||||||
td/telegram/VideoNotesManager.hpp
|
td/telegram/VideoNotesManager.hpp
|
||||||
td/telegram/VideosManager.hpp
|
td/telegram/VideosManager.hpp
|
||||||
td/telegram/VoiceNotesManager.hpp
|
td/telegram/VoiceNotesManager.hpp
|
||||||
|
td/telegram/WebApp.hpp
|
||||||
|
|
||||||
${TL_TD_SCHEME_SOURCE}
|
${TL_TD_SCHEME_SOURCE}
|
||||||
|
|
||||||
|
@ -472,6 +472,14 @@ venue location:location title:string address:string provider:string id:string ty
|
|||||||
//@animation Game animation; may be null
|
//@animation Game animation; may be null
|
||||||
game id:int64 short_name:string title:string text:formattedText description:string photo:photo animation:animation = Game;
|
game id:int64 short_name:string title:string text:formattedText description:string photo:photo animation:animation = Game;
|
||||||
|
|
||||||
|
//@description Describes a web app
|
||||||
|
//@short_name Web app short name. To share a web app use the URL https://t.me/{bot_username}/{app_short_name}?startapp={start_parameter}
|
||||||
|
//@title Web App title
|
||||||
|
//@param_description Web App description
|
||||||
|
//@photo Web App photo
|
||||||
|
//@animation Web App animation; may be null
|
||||||
|
webApp short_name:string title:string description:string photo:photo animation:animation = WebApp;
|
||||||
|
|
||||||
//@description Describes a poll
|
//@description Describes a poll
|
||||||
//@id Unique poll identifier
|
//@id Unique poll identifier
|
||||||
//@question Poll question; 1-300 characters
|
//@question Poll question; 1-300 characters
|
||||||
|
@ -26,7 +26,7 @@ Game::Game(Td *td, UserId bot_user_id, tl_object_ptr<telegram_api::game> &&game,
|
|||||||
id_ = game->id_;
|
id_ = game->id_;
|
||||||
access_hash_ = game->access_hash_;
|
access_hash_ = game->access_hash_;
|
||||||
bot_user_id_ = bot_user_id.is_valid() ? bot_user_id : UserId();
|
bot_user_id_ = bot_user_id.is_valid() ? bot_user_id : UserId();
|
||||||
short_name_ = game->short_name_;
|
short_name_ = std::move(game->short_name_);
|
||||||
text_ = std::move(text);
|
text_ = std::move(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
81
td/telegram/WebApp.cpp
Normal file
81
td/telegram/WebApp.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
||||||
|
//
|
||||||
|
// 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/WebApp.h"
|
||||||
|
|
||||||
|
#include "td/telegram/AnimationsManager.h"
|
||||||
|
#include "td/telegram/Document.h"
|
||||||
|
#include "td/telegram/DocumentsManager.h"
|
||||||
|
#include "td/telegram/misc.h"
|
||||||
|
#include "td/telegram/Photo.h"
|
||||||
|
#include "td/telegram/Td.h"
|
||||||
|
|
||||||
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/logging.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
WebApp::WebApp(Td *td, telegram_api::object_ptr<telegram_api::botApp> &&web_app, DialogId owner_dialog_id)
|
||||||
|
: id_(web_app->id_)
|
||||||
|
, access_hash_(web_app->access_hash_)
|
||||||
|
, short_name_(std::move(web_app->short_name_))
|
||||||
|
, title_(std::move(web_app->title_))
|
||||||
|
, description_(std::move(web_app->description_))
|
||||||
|
, hash_(web_app->hash_) {
|
||||||
|
CHECK(td != nullptr);
|
||||||
|
photo_ = get_photo(td, std::move(web_app->photo_), owner_dialog_id);
|
||||||
|
if (photo_.is_empty()) {
|
||||||
|
LOG(ERROR) << "Receive empty photo for Web App " << short_name_ << '/' << title_;
|
||||||
|
photo_.id = 0; // to prevent null photo in td_api
|
||||||
|
}
|
||||||
|
if (web_app->document_ != nullptr) {
|
||||||
|
int32 document_id = web_app->document_->get_id();
|
||||||
|
if (document_id == telegram_api::document::ID) {
|
||||||
|
auto parsed_document = td->documents_manager_->on_get_document(
|
||||||
|
move_tl_object_as<telegram_api::document>(web_app->document_), owner_dialog_id);
|
||||||
|
if (parsed_document.type == Document::Type::Animation) {
|
||||||
|
animation_file_id_ = parsed_document.file_id;
|
||||||
|
} else {
|
||||||
|
LOG(ERROR) << "Receive non-animation document for Web App " << short_name_ << '/' << title_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WebApp::is_empty() const {
|
||||||
|
return short_name_.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<FileId> WebApp::get_file_ids(const Td *td) const {
|
||||||
|
auto result = photo_get_file_ids(photo_);
|
||||||
|
Document(Document::Type::Animation, animation_file_id_).append_file_ids(td, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::webApp> WebApp::get_web_app_object(Td *td) const {
|
||||||
|
return td_api::make_object<td_api::webApp>(short_name_, title_, description_,
|
||||||
|
get_photo_object(td->file_manager_.get(), photo_),
|
||||||
|
td->animations_manager_->get_animation_object(animation_file_id_));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const WebApp &lhs, const WebApp &rhs) {
|
||||||
|
return lhs.id_ == rhs.id_ && lhs.access_hash_ == rhs.access_hash_ && lhs.short_name_ == rhs.short_name_ &&
|
||||||
|
lhs.title_ == rhs.title_ && lhs.description_ == rhs.description_ && lhs.photo_ == rhs.photo_ &&
|
||||||
|
lhs.animation_file_id_ == rhs.animation_file_id_ && lhs.hash_ == rhs.hash_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const WebApp &lhs, const WebApp &rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder &operator<<(StringBuilder &string_builder, const WebApp &web_app) {
|
||||||
|
return string_builder << "WebApp[ID = " << web_app.id_ << ", access_hash = " << web_app.access_hash_
|
||||||
|
<< ", short_name = " << web_app.short_name_ << ", title = " << web_app.title_
|
||||||
|
<< ", description = " << web_app.description_ << ", photo = " << web_app.photo_
|
||||||
|
<< ", animation_file_id = " << web_app.animation_file_id_ << "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace td
|
62
td/telegram/WebApp.h
Normal file
62
td/telegram/WebApp.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
||||||
|
//
|
||||||
|
// 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/DialogId.h"
|
||||||
|
#include "td/telegram/files/FileId.h"
|
||||||
|
#include "td/telegram/Photo.h"
|
||||||
|
#include "td/telegram/td_api.h"
|
||||||
|
#include "td/telegram/telegram_api.h"
|
||||||
|
|
||||||
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/Status.h"
|
||||||
|
#include "td/utils/StringBuilder.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
class ContactsManager;
|
||||||
|
class Td;
|
||||||
|
|
||||||
|
class WebApp {
|
||||||
|
int64 id_ = 0;
|
||||||
|
int64 access_hash_ = 0;
|
||||||
|
string short_name_;
|
||||||
|
string title_;
|
||||||
|
string description_;
|
||||||
|
Photo photo_;
|
||||||
|
FileId animation_file_id_;
|
||||||
|
int64 hash_ = 0;
|
||||||
|
|
||||||
|
friend bool operator==(const WebApp &lhs, const WebApp &rhs);
|
||||||
|
friend bool operator!=(const WebApp &lhs, const WebApp &rhs);
|
||||||
|
|
||||||
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const WebApp &web_app);
|
||||||
|
|
||||||
|
public:
|
||||||
|
WebApp() = default;
|
||||||
|
|
||||||
|
WebApp(Td *td, telegram_api::object_ptr<telegram_api::botApp> &&web_app, DialogId owner_dialog_id);
|
||||||
|
|
||||||
|
bool is_empty() const;
|
||||||
|
|
||||||
|
vector<FileId> get_file_ids(const Td *td) const;
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::webApp> get_web_app_object(Td *td) const;
|
||||||
|
|
||||||
|
template <class StorerT>
|
||||||
|
void store(StorerT &storer) const;
|
||||||
|
|
||||||
|
template <class ParserT>
|
||||||
|
void parse(ParserT &parser);
|
||||||
|
};
|
||||||
|
|
||||||
|
bool operator==(const WebApp &lhs, const WebApp &rhs);
|
||||||
|
bool operator!=(const WebApp &lhs, const WebApp &rhs);
|
||||||
|
|
||||||
|
StringBuilder &operator<<(StringBuilder &string_builder, const WebApp &web_app);
|
||||||
|
|
||||||
|
} // namespace td
|
58
td/telegram/WebApp.hpp
Normal file
58
td/telegram/WebApp.hpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
//
|
||||||
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
||||||
|
//
|
||||||
|
// 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/WebApp.h"
|
||||||
|
|
||||||
|
#include "td/telegram/AnimationsManager.hpp"
|
||||||
|
#include "td/telegram/Photo.hpp"
|
||||||
|
#include "td/telegram/Td.h"
|
||||||
|
#include "td/telegram/Version.h"
|
||||||
|
|
||||||
|
#include "td/utils/tl_helpers.h"
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
|
||||||
|
template <class StorerT>
|
||||||
|
void WebApp::store(StorerT &storer) const {
|
||||||
|
using td::store;
|
||||||
|
bool has_animation = animation_file_id_.is_valid();
|
||||||
|
BEGIN_STORE_FLAGS();
|
||||||
|
STORE_FLAG(has_animation);
|
||||||
|
END_STORE_FLAGS();
|
||||||
|
store(id_, storer);
|
||||||
|
store(access_hash_, storer);
|
||||||
|
store(short_name_, storer);
|
||||||
|
store(title_, storer);
|
||||||
|
store(description_, storer);
|
||||||
|
store(photo_, storer);
|
||||||
|
if (has_animation) {
|
||||||
|
storer.context()->td().get_actor_unsafe()->animations_manager_->store_animation(animation_file_id_, storer);
|
||||||
|
}
|
||||||
|
store(hash_, storer);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ParserT>
|
||||||
|
void WebApp::parse(ParserT &parser) {
|
||||||
|
using td::parse;
|
||||||
|
bool has_animation;
|
||||||
|
BEGIN_PARSE_FLAGS();
|
||||||
|
PARSE_FLAG(has_animation);
|
||||||
|
END_PARSE_FLAGS();
|
||||||
|
parse(id_, parser);
|
||||||
|
parse(access_hash_, parser);
|
||||||
|
parse(short_name_, parser);
|
||||||
|
parse(title_, parser);
|
||||||
|
parse(description_, parser);
|
||||||
|
parse(photo_, parser);
|
||||||
|
if (has_animation) {
|
||||||
|
animation_file_id_ = parser.context()->td().get_actor_unsafe()->animations_manager_->parse_animation(parser);
|
||||||
|
}
|
||||||
|
parse(hash_, parser);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace td
|
Loading…
Reference in New Issue
Block a user