chore: add buttons to toasts & fix badges & enable new filter by default

This commit is contained in:
AlexeyZavar
2026-04-25 21:11:08 +03:00
parent ae5b140da0
commit 504346d9a0
9 changed files with 168 additions and 47 deletions
+2
View File
@@ -134,6 +134,8 @@ set(ayugram_files
ayu/utils/taptic_engine/platform/taptic_engine_mac.h
ayu/ui/ayu_logo.cpp
ayu/ui/ayu_logo.h
ayu/ui/toasts.cpp
ayu/ui/toasts.h
ayu/ui/ayu_userpic.cpp
ayu/ui/ayu_userpic.h
ayu/ui/utils/ayu_profile_values.cpp
@@ -890,6 +890,8 @@ void AddCreateFilterAction(not_null<Ui::PopupMenu*> menu,
{
RegexFilter filter;
filter.text = selectedText.toStdString();
filter.enabled = true;
filter.caseInsensitive = true;
filter.reversed = false;
controller->show(Settings::RegexEditBox(&filter, {}, getDialogIdFromPeer(item->history()->peer), true));
@@ -10,6 +10,7 @@
#include "ayu/ayu_settings.h"
#include "ayu/data/ayu_database.h"
#include "ayu/features/filters/filters_cache_controller.h"
#include "ayu/ui/toasts.h"
#include "base/event_filter.h"
#include "base/platform/base_platform_info.h"
#include "boxes/delete_messages_box.h"
@@ -31,7 +32,6 @@
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h"
namespace Settings {
std::vector<char> generate_uuid_bytes() {
@@ -218,26 +218,26 @@ void RegexEditBuilder(
FiltersCacheController::fireUpdate();
if (showToast) {
const auto onClick = [=](const auto &...) mutable
{
newFilter.dialogId = dialogId;
AyuDatabase::updateRegexFilter(newFilter);
FiltersCacheController::rebuildCache();
FiltersCacheController::fireUpdate();
return true;
};
// todo: custom toast with "Move to shared" button
// based on `PaidReactionToast`
Ui::Toast::Show(Ui::Toast::Config{
auto config = Ui::Toast::Config{
.text = tr::ayu_RegexFilterBulletinText(
tr::now,
tr::rich
),
.filter = onClick,
.adaptive = true
});
tr::rich),
.adaptive = true,
};
if (dialogId.has_value()) {
Ayu::Ui::ShowToastWithAction(
std::move(config),
tr::ayu_RegexFilterBulletinAction(tr::now),
[=]() mutable {
newFilter.dialogId = dialogId;
AyuDatabase::updateRegexFilter(newFilter);
FiltersCacheController::rebuildCache();
FiltersCacheController::fireUpdate();
});
} else {
Ui::Toast::Show(std::move(config));
}
}
});
});
@@ -265,4 +265,4 @@ object_ptr<Ui::GenericBox> RegexEditBox(RegexFilter *filter,
return Box(RegexEditBuilder, filter, onDone, dialogId, showToast);
}
} // namespace Settings
} // namespace Settings
+66
View File
@@ -0,0 +1,66 @@
#include "ayu/ui/toasts.h"
#include "styles/style_chat.h"
#include "ui/widgets/buttons.h"
#include <memory>
namespace Ayu::Ui {
void ShowToastWithAction(
::Ui::Toast::Config &&config,
const QString &buttonText,
Fn<void()> callback) {
const auto st = std::make_shared<style::Toast>(*config.st);
st->padding.setRight(st::historyPremiumViewSet.style.font->width(buttonText)
- st::historyPremiumViewSet.width);
config.st = st.get();
config.acceptinput = true;
const auto weak = ::Ui::Toast::Show(std::move(config));
const auto strong = weak.get();
if (!strong) {
return;
}
const auto widget = strong->widget();
widget->lifetime().add([st] {});
const auto hideToast = [weak] {
if (const auto strong = weak.get()) {
strong->hideAnimated();
}
};
const auto clickableBackground = ::Ui::CreateChild<::Ui::AbstractButton>(
widget.get());
clickableBackground->setPointerCursor(false);
clickableBackground->setAcceptBoth();
clickableBackground->show();
clickableBackground->addClickHandler([=](Qt::MouseButton button) {
if (button == Qt::RightButton) {
hideToast();
}
});
const auto button = ::Ui::CreateChild<::Ui::RoundButton>(
widget.get(),
rpl::single(buttonText),
st::historyPremiumViewSet);
button->show();
rpl::combine(
widget->sizeValue(),
button->sizeValue()
) | rpl::on_next([=](QSize outer, QSize inner) {
button->moveToRight(
0,
(outer.height() - inner.height()) / 2,
outer.width());
clickableBackground->resize(outer);
}, widget->lifetime());
button->setClickedCallback([=] {
callback();
hideToast();
});
}
}
+12
View File
@@ -0,0 +1,12 @@
#pragma once
#include "ui/toast/toast.h"
namespace Ayu::Ui {
void ShowToastWithAction(
::Ui::Toast::Config &&config,
const QString &buttonText,
Fn<void()> callback);
}
@@ -14,6 +14,7 @@ namespace {
constexpr auto kPrimaryUrl = "https://update.ayugram.one/rc/current/desktop2";
constexpr auto kExteraUrl = "https://api.exteragram.app/api/v1/profiles/compact";
constexpr auto kFetchTimeout = 15 * 1000;
}
@@ -57,6 +58,7 @@ void RCManager::sendRequest() {
auto request = QNetworkRequest(QUrl(url));
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
request.setTransferTimeout(kFetchTimeout);
_reply = _manager->get(request);
connect(_reply,
&QNetworkReply::finished,
+2 -2
View File
@@ -100,9 +100,9 @@ private:
std::unordered_map<ID, CustomBadge> _customBadges = {};
QString _donateUsername = QString("@ayugramOwner");
QString _donateAmountUsd = QString("4.60");
QString _donateAmountUsd = QString("5.00");
QString _donateAmountTon = QString("3.50");
QString _donateAmountRub = QString("360");
QString _donateAmountRub = QString("386");
QTimer* _timer = nullptr;
@@ -15,8 +15,11 @@
#include "ayu/data/entities.h"
#include "ayu/data/messages_storage.h"
#include "ayu/features/filters/filters_controller.h"
#include "ayu/ui/boxes/donate_info_box.h"
#include "ayu/ui/toasts.h"
#include "ayu/utils/rc_manager.h"
#include "core/core_settings.h"
#include "core/application.h"
#include "base/unixtime.h"
#include "core/mime_type.h"
#include "data/data_channel.h"
@@ -44,9 +47,11 @@
#include "styles/style_ayu_styles.h"
#include "styles/style_info.h"
#include "ui/emoji_config.h"
#include "ui/layers/generic_box.h"
#include "ui/text/format_values.h"
#include "ui/text/text_entity.h"
#include "ui/toast/toast.h"
#include "window/window_controller.h"
#include <functional>
#include <latch>
@@ -259,13 +264,31 @@ Fn<void()> badgeClickHandler(not_null<PeerData*> peer) {
return;
}
Ui::Toast::Show({
auto config = Ui::Toast::Config{
.text = text,
.iconContent = MakeBadgeToastIcon(peer, badge),
.st = &st::exteraBadgeToast,
.adaptive = true,
.duration = 3 * crl::time(1000),
});
};
if (badge.badge == Info::Profile::BadgeType::ExteraSupporter) {
Ayu::Ui::ShowToastWithAction(
std::move(config),
tr::lng_collectible_learn_more(tr::now),
[=] {
const auto window = Core::App().activeWindow();
const auto controller = window
? window->sessionController()
: nullptr;
if (!controller) {
return;
}
controller->show(Box(Ui::FillDonateInfoBox, controller));
window->activate();
});
} else {
Ui::Toast::Show(std::move(config));
}
};
}
+37 -23
View File
@@ -184,43 +184,54 @@ int PeerBadge::drawGetWidth(Painter &p, Descriptor &&descriptor) {
&& !hidePremiumStatuses;
const auto paintExteraCustom =
isCustomBadgePeer(getBareID(peer));
const auto paintExteraDev =
isExteraPeer(getBareID(peer)) && (!paintEmoji || descriptor.bothVerifyAndStatus) && !paintExteraCustom;
const auto paintExteraSupporter = !paintExteraDev &&
isSupporterPeer(getBareID(peer)) && (!paintEmoji || descriptor.bothVerifyAndStatus) && !paintExteraCustom;
const auto exteraWidth = paintExteraDev
? descriptor.exteraOfficial->width()
: paintExteraSupporter
? descriptor.exteraSupporter->width()
: 0;
const auto exteraCustomWidth = descriptor.premium->width() - 4 * ((st::emojiSize - Ui::Text::AdjustCustomEmojiSize(st::emojiSize)) / 2);
isCustomBadgePeer(getBareID(peer)) && !hidePremiumStatuses;
const auto paintExteraDev = isExteraPeer(getBareID(peer))
&& !paintExteraCustom
&& !hidePremiumStatuses;
const auto paintExteraSupporter = !paintExteraDev
&& isSupporterPeer(getBareID(peer))
&& !paintExteraCustom
&& !hidePremiumStatuses;
const auto paintExtera = paintExteraDev || paintExteraSupporter;
auto exteraWidth = 0;
if (paintExteraDev) {
exteraWidth = descriptor.exteraOfficial->width();
} else if (paintExteraSupporter) {
exteraWidth = descriptor.exteraSupporter->width();
}
const auto customEmojiSkip = (st::emojiSize
- Ui::Text::AdjustCustomEmojiSize(st::emojiSize)) / 2;
const auto exteraCustomWidth = paintExteraCustom
? descriptor.premium->width() - 4 * customEmojiSkip
: 0;
const auto verifyWidth = paintVerify ? descriptor.verified->width() : 0;
const auto verifyAfterEmojiWidth = (paintVerify && !paintExtera)
? verifyWidth
: 0;
auto result = 0;
if (paintEmoji) {
auto &rectForName = descriptor.rectForName;
const auto verifyWidth = descriptor.verified->width();
if (paintVerify) {
rectForName.setWidth(rectForName.width() - verifyWidth);
if (verifyAfterEmojiWidth) {
rectForName.setWidth(rectForName.width() - verifyAfterEmojiWidth);
}
if (paintExteraCustom) {
rectForName.setWidth(rectForName.width() - exteraCustomWidth);
}
if (paintExteraDev || paintExteraSupporter) {
if (paintExtera) {
rectForName.setWidth(rectForName.width() - exteraWidth);
}
result += drawPremiumEmojiStatus(p, descriptor);
if (!paintVerify && !paintExteraCustom && !paintExteraDev && !paintExteraSupporter) {
if (!paintVerify && !paintExteraCustom && !paintExtera) {
return result;
}
if (paintVerify) {
rectForName.setWidth(rectForName.width() + verifyWidth);
if (verifyAfterEmojiWidth) {
rectForName.setWidth(rectForName.width() + verifyAfterEmojiWidth);
}
if (paintExteraCustom) {
rectForName.setWidth(rectForName.width() + exteraCustomWidth);
}
if (paintExteraDev || paintExteraSupporter) {
if (paintExtera) {
rectForName.setWidth(rectForName.width() + exteraWidth);
}
descriptor.nameWidth += result;
@@ -228,7 +239,6 @@ int PeerBadge::drawGetWidth(Painter &p, Descriptor &&descriptor) {
if (paintExteraCustom) {
auto &rectForName = descriptor.rectForName;
const auto verifyWidth = descriptor.verified->width();
if (paintVerify) {
rectForName.setWidth(rectForName.width() - verifyWidth);
}
@@ -242,7 +252,7 @@ int PeerBadge::drawGetWidth(Painter &p, Descriptor &&descriptor) {
descriptor.nameWidth += result;
}
if (paintExteraDev || paintExteraSupporter) {
if (paintExtera) {
if (paintStar) {
auto &rectForName = descriptor.rectForName;
rectForName.setWidth(rectForName.width() - exteraWidth);
@@ -250,7 +260,11 @@ int PeerBadge::drawGetWidth(Painter &p, Descriptor &&descriptor) {
rectForName.setWidth(rectForName.width() + exteraWidth);
descriptor.nameWidth += result;
}
result += paintExteraDev ? drawExteraOfficial(p, descriptor) : drawExteraSupporter(p, descriptor);
if (paintExteraDev) {
result += drawExteraOfficial(p, descriptor);
} else {
result += drawExteraSupporter(p, descriptor);
}
return result;
}