Show only one dice-media tooltip. Hide on SEND.

This commit is contained in:
John Preston 2020-05-05 15:51:55 +04:00
parent 0bf933b009
commit 9c17147f60
2 changed files with 14 additions and 2 deletions

View File

@ -382,6 +382,7 @@ historyDateFadeDuration: 200;
historyDiceToast: Toast(defaultToast) {
minWidth: msgMinWidth;
maxWidth: 640px;
durationFadeOut: 200;
}
historyErrorToast: Toast(defaultToast) {
minWidth: msgMinWidth;

View File

@ -35,6 +35,13 @@ namespace {
[[nodiscard]] ClickHandlerPtr MakeDiceHandler(
not_null<History*> history,
const QString &emoji) {
static auto ShownToast = base::weak_ptr<Ui::Toast::Instance>();
static const auto HideExisting = [] {
if (const auto toast = ShownToast.get()) {
toast->hideAnimated();
ShownToast = nullptr;
}
};
return std::make_shared<LambdaClickHandler>([=] {
auto config = Ui::Toast::Config{
.text = { tr::lng_about_random(tr::now, lt_emoji, emoji) },
@ -51,16 +58,20 @@ namespace {
config.filter = crl::guard(&history->session(), [=](
const ClickHandlerPtr &handler,
Qt::MouseButton button) {
if (button == Qt::LeftButton) {
if (button == Qt::LeftButton && !ShownToast.empty()) {
auto message = Api::MessageToSend(history);
message.action.clearDraft = false;
message.textWithTags.text = emoji;
Api::SendDice(message);
HideExisting();
}
return false;
});
}
Ui::Toast::Show(config);
HideExisting();
ShownToast = Ui::Toast::Show(config);
});
}