/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/history_item_reply_markup.h" #include "data/data_session.h" #include "history/history_item.h" #include "history/history_item_components.h" #include "inline_bots/bot_attach_web_view.h" namespace { [[nodiscard]] InlineBots::PeerTypes PeerTypesFromMTP( const MTPvector &types) { using namespace InlineBots; auto result = PeerTypes(0); for (const auto &type : types.v) { result |= type.match([&](const MTPDinlineQueryPeerTypePM &data) { return PeerType::User; }, [&](const MTPDinlineQueryPeerTypeChat &data) { return PeerType::Group; }, [&](const MTPDinlineQueryPeerTypeMegagroup &data) { return PeerType::Group; }, [&](const MTPDinlineQueryPeerTypeBroadcast &data) { return PeerType::Broadcast; }, [&](const MTPDinlineQueryPeerTypeBotPM &data) { return PeerType::Bot; }, [&](const MTPDinlineQueryPeerTypeSameBotPM &data) { return PeerType(); }); } return result; } [[nodiscard]] RequestPeerQuery RequestPeerQueryFromTL( const MTPDkeyboardButtonRequestPeer &query) { using Type = RequestPeerQuery::Type; using Restriction = RequestPeerQuery::Restriction; auto result = RequestPeerQuery(); result.maxQuantity = query.vmax_quantity().v; const auto restriction = [](const MTPBool *value) { return !value ? Restriction::Any : mtpIsTrue(*value) ? Restriction::Yes : Restriction::No; }; const auto rights = [](const MTPChatAdminRights *value) { return value ? ChatAdminRightsInfo(*value).flags : ChatAdminRights(); }; query.vpeer_type().match([&](const MTPDrequestPeerTypeUser &data) { result.type = Type::User; result.userIsBot = restriction(data.vbot()); result.userIsPremium = restriction(data.vpremium()); }, [&](const MTPDrequestPeerTypeChat &data) { result.type = Type::Group; result.amCreator = data.is_creator(); result.isBotParticipant = data.is_bot_participant(); result.groupIsForum = restriction(data.vforum()); result.hasUsername = restriction(data.vhas_username()); result.myRights = rights(data.vuser_admin_rights()); result.botRights = rights(data.vbot_admin_rights()); }, [&](const MTPDrequestPeerTypeBroadcast &data) { result.type = Type::Broadcast; result.amCreator = data.is_creator(); result.hasUsername = restriction(data.vhas_username()); result.myRights = rights(data.vuser_admin_rights()); result.botRights = rights(data.vbot_admin_rights()); }); return result; } } // namespace HistoryMessageMarkupButton::HistoryMessageMarkupButton( Type type, const QString &text, const QByteArray &data, const QString &forwardText, int64 buttonId) : type(type) , text(text) , forwardText(forwardText) , data(data) , buttonId(buttonId) { } HistoryMessageMarkupButton *HistoryMessageMarkupButton::Get( not_null owner, FullMsgId itemId, int row, int column) { if (const auto item = owner->message(itemId)) { if (const auto markup = item->Get()) { if (row < markup->data.rows.size()) { auto &buttons = markup->data.rows[row]; if (column < buttons.size()) { return &buttons[column]; } } } } return nullptr; } void HistoryMessageMarkupData::fillRows( const QVector &list) { rows.clear(); if (list.isEmpty()) { return; } using Type = Button::Type; rows.reserve(list.size()); for (const auto &row : list) { row.match([&](const MTPDkeyboardButtonRow &data) { auto row = std::vector