Allow sending dice from dice media tooltip.

This commit is contained in:
John Preston 2020-04-20 14:18:09 +04:00
parent abfd3ad1b9
commit 54f757e770
4 changed files with 28 additions and 4 deletions

View File

@ -1330,6 +1330,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_dialogs_show_archive_in_search" = "With results from archive";
"lng_about_random" = "Send a {emoji} emoji to any chat to get a random number from Telegram.";
"lng_about_random_send" = "Send";
"lng_open_this_link" = "Open this link?";
"lng_open_link" = "Open";

View File

@ -23,6 +23,6 @@ void SendExistingPhoto(
Api::MessageToSend &&message,
not_null<PhotoData*> photo);
[[nodiscard]] bool SendDice(Api::MessageToSend &message);
bool SendDice(Api::MessageToSend &message);
} // namespace Api

View File

@ -9,11 +9,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h"
#include "chat_helpers/stickers_dice_pack.h"
#include "api/api_sending.h"
#include "api/api_common.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "history/view/history_view_element.h"
#include "ui/toast/toast.h"
#include "ui/text/text_utilities.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
@ -28,12 +31,32 @@ namespace {
return session.diceStickersPacks().lookup(emoji, value);
}
[[nodiscard]] ClickHandlerPtr MakeDiceHandler(const QString &emoji) {
[[nodiscard]] ClickHandlerPtr MakeDiceHandler(
not_null<History*> history,
const QString &emoji) {
return std::make_shared<LambdaClickHandler>([=] {
auto config = Ui::Toast::Config();
config.multiline = true;
config.minWidth = st::msgMinWidth;
config.maxWidth = st::toastMaxWidth + st::msgMinWidth;
config.text = { tr::lng_about_random(tr::now, lt_emoji, emoji) };
config.durationMs = Ui::Toast::kDefaultDuration * 2;
auto link = Ui::Text::Link(
tr::lng_about_random_send(tr::now).toUpper());
link.entities.push_back(
EntityInText(EntityType::Bold, 0, link.text.size()));
config.text.append(' ').append(std::move(link));
config.filter = crl::guard(&history->session(), [=](
const ClickHandlerPtr &handler,
Qt::MouseButton button) {
if (button == Qt::LeftButton) {
auto message = Api::MessageToSend(history);
message.action.clearDraft = false;
message.textWithTags.text = emoji;
Api::SendDice(message);
}
return false;
});
Ui::Toast::Show(config);
});
}
@ -45,7 +68,7 @@ Dice::Dice(not_null<Element*> parent, not_null<Data::MediaDice*> dice)
, _dice(dice)
, _link(_parent->data()->Has<HistoryMessageForwarded>()
? nullptr
: MakeDiceHandler(dice->emoji())) {
: MakeDiceHandler(_parent->history(), dice->emoji())) {
if (const auto document = Lookup(parent, dice->emoji(), 0)) {
_start.emplace(parent, document);
_start->setDiceIndex(_dice->emoji(), 0);

@ -1 +1 @@
Subproject commit 2cb10e1d13b49653f67474c13a3281a84ec82c03
Subproject commit 6d261326857f48906c272601a9f265d22269bb87