Add td_api::sharedUser/sharedChat.

This commit is contained in:
levlam 2024-03-21 21:53:39 +03:00
parent ee030cf5f7
commit cfa47d5283
6 changed files with 244 additions and 0 deletions

View File

@ -497,6 +497,7 @@ set(TDLIB_SOURCE
td/telegram/SendCodeHelper.cpp
td/telegram/SentEmailCode.cpp
td/telegram/SequenceDispatcher.cpp
td/telegram/SharedDialog.cpp
td/telegram/SpecialStickerSetType.cpp
td/telegram/SponsoredMessageManager.cpp
td/telegram/StateManager.cpp
@ -847,6 +848,7 @@ set(TDLIB_SOURCE
td/telegram/SequenceDispatcher.h
td/telegram/ServerMessageId.h
td/telegram/SetWithPosition.h
td/telegram/SharedDialog.h
td/telegram/SpecialStickerSetType.h
td/telegram/SponsoredMessageManager.h
td/telegram/StateManager.h
@ -962,6 +964,7 @@ set(TDLIB_SOURCE
td/telegram/ScopeNotificationSettings.hpp
td/telegram/SecureValue.hpp
td/telegram/SendCodeHelper.hpp
td/telegram/SharedDialog.hpp
td/telegram/StickerMaskPosition.hpp
td/telegram/StickerPhotoSize.hpp
td/telegram/StickersManager.hpp

View File

@ -396,6 +396,7 @@ function split_file($file, $chunks, $undo) {
'secret_chats_manager[_(-]|SecretChatsManager' => 'SecretChatsManager',
'secure_manager[_(-](?![.]get[(][)])|SecureManager' => 'SecureManager',
'SentEmailCode' => 'SentEmailCode',
'SharedDialog' => 'SharedDialog',
'sponsored_message_manager[_(-](?![.]get[(][)])|SponsoredMessageManager' => 'SponsoredMessageManager',
'state_manager[_(-](?![.]get[(][)])|StateManager' => 'StateManager',
'statistics_manager[_(-](?![.]get[(][)])|StatisticsManager' => 'StatisticsManager',

View File

@ -2058,6 +2058,22 @@ forumTopics total_count:int32 topics:vector<forumTopic> next_offset_date:int32 n
linkPreviewOptions is_disabled:Bool url:string force_small_media:Bool force_large_media:Bool show_above_text:Bool = LinkPreviewOptions;
//@description Contains information about a user shared with a bot
//@user_id User identifier
//@first_name First name of the user; for bots only
//@last_name Last name of the user; for bots only
//@username Username of the user; for bots only
//@photo Profile photo of the user; for bots only; may be null
sharedUser user_id:int53 first_name:string last_name:string username:string photo:photo = SharedUser;
//@description Contains information about a chat shared with a bot
//@chat_id Chat identifier
//@title Title of the chat; for bots only
//@username Username of the chat; for bots only
//@photo Photo of the chat; for bots only; may be null
sharedChat chat_id:int53 title:string username:string photo:photo = SharedChat;
//@class RichText @description Describes a text object inside an instant-view web page
//@description A plain text @text Text

View File

@ -0,0 +1,86 @@
//
// 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/SharedDialog.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/ChannelId.h"
#include "td/telegram/ChatId.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogManager.h"
#include "td/telegram/files/FileManager.h"
#include "td/telegram/Td.h"
#include "td/telegram/UserId.h"
#include "td/utils/logging.h"
namespace td {
SharedDialog::SharedDialog(Td *td, telegram_api::object_ptr<telegram_api::RequestedPeer> &&requested_peer_ptr) {
CHECK(requested_peer_ptr != nullptr);
switch (requested_peer_ptr->get_id()) {
case telegram_api::requestedPeerUser::ID: {
auto requested_peer = telegram_api::move_object_as<telegram_api::requestedPeerUser>(requested_peer_ptr);
dialog_id_ = DialogId(UserId(requested_peer->user_id_));
first_name_ = std::move(requested_peer->first_name_);
last_name_ = std::move(requested_peer->last_name_);
username_ = std::move(requested_peer->username_);
photo_ = get_photo(td, std::move(requested_peer->photo_), dialog_id_);
break;
}
case telegram_api::requestedPeerChat::ID: {
auto requested_peer = telegram_api::move_object_as<telegram_api::requestedPeerChat>(requested_peer_ptr);
dialog_id_ = DialogId(UserId(requested_peer->chat_id_));
first_name_ = std::move(requested_peer->title_);
photo_ = get_photo(td, std::move(requested_peer->photo_), dialog_id_);
break;
}
case telegram_api::requestedPeerChannel::ID: {
auto requested_peer = telegram_api::move_object_as<telegram_api::requestedPeerChannel>(requested_peer_ptr);
dialog_id_ = DialogId(UserId(requested_peer->channel_id_));
first_name_ = std::move(requested_peer->title_);
username_ = std::move(requested_peer->username_);
photo_ = get_photo(td, std::move(requested_peer->photo_), dialog_id_);
break;
}
default:
UNREACHABLE();
}
}
td_api::object_ptr<td_api::sharedUser> SharedDialog::get_shared_user_object(Td *td) const {
CHECK(is_user());
auto user_id = td->auth_manager_->is_bot()
? dialog_id_.get_user_id().get()
: td->contacts_manager_->get_user_id_object(dialog_id_.get_user_id(), "sharedUser");
return td_api::make_object<td_api::sharedUser>(user_id, first_name_, last_name_, username_,
get_photo_object(td->file_manager_.get(), photo_));
}
td_api::object_ptr<td_api::sharedChat> SharedDialog::get_shared_chat_object(Td *td) const {
CHECK(is_dialog());
auto chat_id = td->auth_manager_->is_bot() ? dialog_id_.get()
: td->dialog_manager_->get_chat_id_object(dialog_id_, "sharedChat");
return td_api::make_object<td_api::sharedChat>(chat_id, first_name_, username_,
get_photo_object(td->file_manager_.get(), photo_));
}
bool operator==(const SharedDialog &lhs, const SharedDialog &rhs) {
return lhs.dialog_id_ == rhs.dialog_id_ && lhs.first_name_ == rhs.first_name_ && lhs.last_name_ == rhs.last_name_ &&
lhs.username_ == rhs.username_ && lhs.photo_ == rhs.photo_;
}
bool operator!=(const SharedDialog &lhs, const SharedDialog &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const SharedDialog &shared_dialog) {
return string_builder << "shared " << shared_dialog.dialog_id_ << '(' << shared_dialog.first_name_ << ' '
<< shared_dialog.last_name_ << ' ' << shared_dialog.username_ << ' ' << shared_dialog.photo_
<< ')';
}
} // namespace td

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)
//
#pragma once
#include "td/telegram/DialogId.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/StringBuilder.h"
namespace td {
class Td;
class SharedDialog {
public:
SharedDialog() = default;
SharedDialog(Td *td, telegram_api::object_ptr<telegram_api::RequestedPeer> &&requested_peer_ptr);
bool is_valid() const {
return dialog_id_.is_valid();
}
bool is_user() const {
return dialog_id_.get_type() == DialogType::User;
}
bool is_dialog() const {
auto dialog_type = dialog_id_.get_type();
return dialog_type == DialogType::Chat || dialog_type == DialogType::Channel;
}
td_api::object_ptr<td_api::sharedUser> get_shared_user_object(Td *td) const;
td_api::object_ptr<td_api::sharedChat> get_shared_chat_object(Td *td) const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
private:
friend bool operator==(const SharedDialog &lhs, const SharedDialog &rhs);
friend bool operator!=(const SharedDialog &lhs, const SharedDialog &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const SharedDialog &shared_dialog);
DialogId dialog_id_;
string first_name_;
string last_name_;
string username_;
Photo photo_;
};
bool operator==(const SharedDialog &lhs, const SharedDialog &rhs);
bool operator!=(const SharedDialog &lhs, const SharedDialog &rhs);
StringBuilder &operator<<(StringBuilder &string_builder, const SharedDialog &shared_dialog);
} // namespace td

View File

@ -0,0 +1,70 @@
//
// 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/Photo.hpp"
#include "td/telegram/SharedDialog.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void SharedDialog::store(StorerT &storer) const {
bool has_first_name = !first_name_.empty();
bool has_last_name = !last_name_.empty();
bool has_username = !username_.empty();
bool has_photo = !photo_.is_empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_first_name);
STORE_FLAG(has_last_name);
STORE_FLAG(has_username);
STORE_FLAG(has_photo);
END_STORE_FLAGS();
td::store(dialog_id_, storer);
if (has_first_name) {
td::store(first_name_, storer);
}
if (has_last_name) {
td::store(last_name_, storer);
}
if (has_username) {
td::store(username_, storer);
}
if (has_photo) {
td::store(photo_, storer);
}
}
template <class ParserT>
void SharedDialog::parse(ParserT &parser) {
bool has_first_name;
bool has_last_name;
bool has_username;
bool has_photo;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_first_name);
PARSE_FLAG(has_last_name);
PARSE_FLAG(has_username);
PARSE_FLAG(has_photo);
END_PARSE_FLAGS();
td::parse(dialog_id_, parser);
if (has_first_name) {
td::parse(first_name_, parser);
}
if (has_last_name) {
td::parse(last_name_, parser);
}
if (has_username) {
td::parse(username_, parser);
}
if (has_photo) {
td::parse(photo_, parser);
}
}
} // namespace td