mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-09-02 07:35:12 +00:00
Allow sending dice from dice media tooltip.
This commit is contained in:
@@ -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";
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
Submodule Telegram/lib_ui updated: 2cb10e1d13...6d26132685
Reference in New Issue
Block a user