Add subscribed-to-premium toast.

This commit is contained in:
John Preston 2022-06-07 12:41:10 +04:00
parent 00bea8d1ee
commit a6bc6c877e
3 changed files with 31 additions and 0 deletions

View file

@ -1701,6 +1701,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_premium_summary_bottom_about" = "While the free version of Telegram already gives its users more than any other messaging application, **Telegram Premium** pushes its capabilities even further.\n\n**Telegram Premium** is a paid option, because most Premium Features require additional expenses from Telegram to third parties such as data center providers and server manufacturers. Contributions from **Telegram Premium** users allow us to cover such costs and also help Telegram stay free for everyone.";
"lng_premium_summary_button" = "Subscribe for {cost} per month";
"lng_premium_success" = "You've successfully subscribed to Telegram Premium!";
"lng_accounts_limit_title" = "Limit Reached";
"lng_accounts_limit1#one" = "You have reached the limit of **{count}** connected accounts.";
"lng_accounts_limit1#other" = "You have reached the limit of **{count}** connected accounts.";

View file

@ -40,6 +40,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_changes.h"
#include "data/data_group_call.h"
#include "data/data_chat_filters.h"
#include "data/data_peer_values.h"
#include "passport/passport_form_controller.h"
#include "chat_helpers/tabbed_selector.h"
#include "chat_helpers/emoji_interactions.h"
@ -665,6 +666,7 @@ SessionController::SessionController(
crl::on_main(this, [=] {
activateFirstChatsFilter();
setupPremiumToast();
});
}
@ -817,6 +819,30 @@ void SessionController::closeFolder() {
_openedFolder = nullptr;
}
void SessionController::setupPremiumToast() {
rpl::combine(
Data::AmPremiumValue(&session()),
session().changes().peerUpdates(
Data::PeerUpdate::Flag::FullInfo
)
) | rpl::filter([=] {
return session().user()->isFullLoaded();
}) | rpl::map([=](bool premium, const auto&) {
return premium;
}) | rpl::distinct_until_changed() | rpl::skip(
1
) | rpl::filter([=](bool premium) {
return premium;
}) | rpl::start_with_next([=] {
Ui::Toast::Show(
Window::Show(this).toastParent(),
{
.text = tr::lng_premium_success(tr::now),
.st = &st::defaultToast,
});
}, _lifetime);
}
const rpl::variable<Data::Folder*> &SessionController::openedFolder() const {
return _openedFolder;
}

View file

@ -540,6 +540,7 @@ private:
void resetFakeUnreadWhileOpened();
void checkInvitePeek();
void setupPremiumToast();
void pushDefaultChatBackground();
void cacheChatTheme(
@ -616,8 +617,10 @@ public:
[[nodiscard]] not_null<QWidget*> toastParent() const override;
[[nodiscard]] bool valid() const override;
operator bool() const override;
private:
const base::weak_ptr<Controller> _window;
};
} // namespace Window