mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Improved processing of premium accounts limits.
This commit is contained in:
parent
6c48abb562
commit
1d7e901b7a
5 changed files with 79 additions and 43 deletions
|
@ -1699,8 +1699,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_premium_summary_button" = "Subscribe for {cost} per month";
|
"lng_premium_summary_button" = "Subscribe for {cost} per month";
|
||||||
|
|
||||||
"lng_accounts_limit_title" = "Limit Reached";
|
"lng_accounts_limit_title" = "Limit Reached";
|
||||||
"lng_accounts_limit1#one" = "You have reached the limit of **{count}** connected accounts. You can free one space by subscribing to **Telegram Premium** with on of these connected accounts:";
|
"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. You can free one space by subscribing to **Telegram Premium** with on of these connected accounts:";
|
"lng_accounts_limit1#other" = "You have reached the limit of **{count}** connected accounts.";
|
||||||
|
"lng_accounts_limit2" = "You can free one space by subscribing to **Telegram Premium** with on of these connected accounts:";
|
||||||
|
|
||||||
"lng_group_about_header" = "You have created a group.";
|
"lng_group_about_header" = "You have created a group.";
|
||||||
"lng_group_about_text" = "Groups can have:";
|
"lng_group_about_text" = "Groups can have:";
|
||||||
|
|
|
@ -887,18 +887,25 @@ void FileSizeLimitBox(
|
||||||
void AccountsLimitBox(
|
void AccountsLimitBox(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
not_null<Main::Session*> session) {
|
not_null<Main::Session*> session) {
|
||||||
const auto premium = session->premium();
|
|
||||||
|
|
||||||
const auto defaultLimit = Main::Domain::kMaxAccounts;
|
const auto defaultLimit = Main::Domain::kMaxAccounts;
|
||||||
const auto premiumLimit = Main::Domain::kPremiumMaxAccounts;
|
const auto premiumLimit = Main::Domain::kPremiumMaxAccounts;
|
||||||
|
|
||||||
const auto accounts = session->domain().orderedAccounts();
|
const auto accounts = session->domain().orderedAccounts();
|
||||||
const auto current = int(accounts.size());
|
const auto current = int(accounts.size());
|
||||||
|
|
||||||
auto text = tr::lng_accounts_limit1(
|
auto text = rpl::combine(
|
||||||
lt_count,
|
tr::lng_accounts_limit1(
|
||||||
rpl::single<float64>(premiumLimit),
|
lt_count,
|
||||||
Ui::Text::RichLangValue);
|
rpl::single<float64>(current),
|
||||||
|
Ui::Text::RichLangValue),
|
||||||
|
((current > premiumLimit)
|
||||||
|
? rpl::single(TextWithEntities())
|
||||||
|
: tr::lng_accounts_limit2(Ui::Text::RichLangValue))
|
||||||
|
) | rpl::map([](TextWithEntities &&a, TextWithEntities &&b) {
|
||||||
|
return b.text.isEmpty()
|
||||||
|
? a
|
||||||
|
: a.append(QChar(' ')).append(std::move(b));
|
||||||
|
});
|
||||||
|
|
||||||
box->setWidth(st::boxWideWidth);
|
box->setWidth(st::boxWideWidth);
|
||||||
|
|
||||||
|
@ -911,7 +918,7 @@ void AccountsLimitBox(
|
||||||
BoxShowFinishes(box),
|
BoxShowFinishes(box),
|
||||||
0,
|
0,
|
||||||
current,
|
current,
|
||||||
(current == premiumLimit) ? premiumLimit : (current * 2),
|
(current > defaultLimit) ? current : (defaultLimit * 2),
|
||||||
std::nullopt,
|
std::nullopt,
|
||||||
&st::premiumIconAccounts);
|
&st::premiumIconAccounts);
|
||||||
Settings::AddSkip(top, st::premiumLineTextSkip);
|
Settings::AddSkip(top, st::premiumLineTextSkip);
|
||||||
|
@ -930,37 +937,38 @@ void AccountsLimitBox(
|
||||||
padding);
|
padding);
|
||||||
|
|
||||||
|
|
||||||
if (premium) {
|
if (current > premiumLimit) {
|
||||||
|
// Probably an unreachable state.
|
||||||
box->addButton(tr::lng_box_ok(), [=] {
|
box->addButton(tr::lng_box_ok(), [=] {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
});
|
});
|
||||||
} else {
|
return;
|
||||||
auto switchingLifetime = std::make_shared<rpl::lifetime>();
|
|
||||||
box->addButton(tr::lng_continue(), [=]() mutable {
|
|
||||||
const auto ref = QString();
|
|
||||||
|
|
||||||
const auto wasAccount = &session->account();
|
|
||||||
const auto nowAccount = accounts[group->value()];
|
|
||||||
if (wasAccount == nowAccount) {
|
|
||||||
Settings::ShowPremium(session, ref);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*switchingLifetime) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*switchingLifetime = session->domain().activeSessionChanges(
|
|
||||||
) | rpl::start_with_next([=](Main::Session *session) mutable {
|
|
||||||
if (session) {
|
|
||||||
Settings::ShowPremium(session, ref);
|
|
||||||
}
|
|
||||||
if (switchingLifetime) {
|
|
||||||
base::take(switchingLifetime)->destroy();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
session->domain().activate(nowAccount);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
auto switchingLifetime = std::make_shared<rpl::lifetime>();
|
||||||
|
box->addButton(tr::lng_continue(), [=]() mutable {
|
||||||
|
const auto ref = QString();
|
||||||
|
|
||||||
|
const auto wasAccount = &session->account();
|
||||||
|
const auto nowAccount = accounts[group->value()];
|
||||||
|
if (wasAccount == nowAccount) {
|
||||||
|
Settings::ShowPremium(session, ref);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*switchingLifetime) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*switchingLifetime = session->domain().activeSessionChanges(
|
||||||
|
) | rpl::start_with_next([=](Main::Session *session) mutable {
|
||||||
|
if (session) {
|
||||||
|
Settings::ShowPremium(session, ref);
|
||||||
|
}
|
||||||
|
if (switchingLifetime) {
|
||||||
|
base::take(switchingLifetime)->destroy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
session->domain().activate(nowAccount);
|
||||||
|
});
|
||||||
|
|
||||||
box->addButton(tr::lng_cancel(), [=] {
|
box->addButton(tr::lng_cancel(), [=] {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
|
@ -970,10 +978,12 @@ void AccountsLimitBox(
|
||||||
|
|
||||||
auto &&entries = ranges::views::all(
|
auto &&entries = ranges::views::all(
|
||||||
accounts
|
accounts
|
||||||
) | ranges::views::transform([&](not_null<Main::Account*> account) {
|
) | ranges::views::filter([&](not_null<Main::Account*> account) {
|
||||||
|
return account->sessionExists() && !account->session().premium();
|
||||||
|
}) | ranges::views::transform([&](not_null<Main::Account*> account) {
|
||||||
const auto user = account->session().user();
|
const auto user = account->session().user();
|
||||||
return Args::Entry{ user->name, PaintUserpicCallback(user, false) };
|
return Args::Entry{ user->name, PaintUserpicCallback(user, false) };
|
||||||
});
|
}) | ranges::views::take(defaultLimit);
|
||||||
|
|
||||||
auto args = Args{
|
auto args = Args{
|
||||||
.group = group,
|
.group = group,
|
||||||
|
|
|
@ -85,8 +85,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/qthelp_regex.h"
|
#include "base/qthelp_regex.h"
|
||||||
#include "base/qthelp_url.h"
|
#include "base/qthelp_url.h"
|
||||||
#include "boxes/connection_box.h"
|
#include "boxes/connection_box.h"
|
||||||
|
#include "boxes/premium_limits_box.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "boxes/share_box.h"
|
|
||||||
|
|
||||||
#include <QtCore/QMimeDatabase>
|
#include <QtCore/QMimeDatabase>
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
|
@ -285,6 +285,31 @@ void Application::run() {
|
||||||
_primaryWindow->showAccount(account);
|
_primaryWindow->showAccount(account);
|
||||||
}, _primaryWindow->widget()->lifetime());
|
}, _primaryWindow->widget()->lifetime());
|
||||||
|
|
||||||
|
(
|
||||||
|
_domain->activeValue(
|
||||||
|
) | rpl::to_empty | rpl::filter([=] {
|
||||||
|
return _domain->started();
|
||||||
|
}) | rpl::take(1)
|
||||||
|
) | rpl::then(
|
||||||
|
_domain->accountsChanges()
|
||||||
|
) | rpl::map([=] {
|
||||||
|
return (_domain->accounts().size() > Main::Domain::kMaxAccounts)
|
||||||
|
? _domain->activeChanges()
|
||||||
|
: rpl::never<not_null<Main::Account*>>();
|
||||||
|
}) | rpl::flatten_latest(
|
||||||
|
) | rpl::start_with_next([=](not_null<Main::Account*> account) {
|
||||||
|
const auto ordered = _domain->orderedAccounts();
|
||||||
|
const auto it = ranges::find(ordered, account);
|
||||||
|
if (it != end(ordered)) {
|
||||||
|
const auto index = std::distance(begin(ordered), it);
|
||||||
|
if ((index + 1) > _domain->maxAccounts()) {
|
||||||
|
_primaryWindow->show(Box(
|
||||||
|
AccountsLimitBox,
|
||||||
|
&account->session()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, _primaryWindow->widget()->lifetime());
|
||||||
|
|
||||||
QCoreApplication::instance()->installEventFilter(this);
|
QCoreApplication::instance()->installEventFilter(this);
|
||||||
|
|
||||||
appDeactivatedValue(
|
appDeactivatedValue(
|
||||||
|
|
|
@ -467,11 +467,11 @@ void Domain::scheduleWriteAccounts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int Domain::maxAccounts() const {
|
int Domain::maxAccounts() const {
|
||||||
const auto isAnyPreimium = ranges::any_of(accounts(), [](
|
const auto premiumCount = ranges::count_if(accounts(), [](
|
||||||
const Main::Domain::AccountWithIndex &d) {
|
const Main::Domain::AccountWithIndex &d) {
|
||||||
return d.account->session().premium();
|
return d.account->sessionExists() && d.account->session().premium();
|
||||||
});
|
});
|
||||||
return isAnyPreimium ? kPremiumMaxAccounts : kMaxAccounts;
|
return std::min(int(premiumCount) + kMaxAccounts, kPremiumMaxAccounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<int> Domain::maxAccountsChanges() const {
|
rpl::producer<int> Domain::maxAccountsChanges() const {
|
||||||
|
|
|
@ -31,7 +31,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr auto kMaxAccounts = 3;
|
static constexpr auto kMaxAccounts = 3;
|
||||||
static constexpr auto kPremiumMaxAccounts = 4;
|
static constexpr auto kPremiumMaxAccounts = 6;
|
||||||
|
|
||||||
explicit Domain(const QString &dataName);
|
explicit Domain(const QString &dataName);
|
||||||
~Domain();
|
~Domain();
|
||||||
|
|
Loading…
Add table
Reference in a new issue