[Improvement] Increase account limit

This commit is contained in:
Eric Kotato 2022-09-11 02:22:41 +03:00 committed by Eric Kotato
parent 328cec5487
commit 06e6f48559
9 changed files with 58 additions and 21 deletions

View file

@ -116,6 +116,8 @@
"ktg_channel_status_not_in": "not subscribed",
"ktg_group_status_owner": "is owner",
"ktg_group_status_admin": "is admin",
"ktg_too_many_accounts_warning": "Warning! Using too many accounts at the same time is not recommended due to higher memory comsumption and possible crashes because of it.\n\nYou sure you want to add a new account?",
"ktg_account_add_anyway": "Add anyway",
"ktg_forward_go_to_chat": "Go to chat",
"ktg_settings_forward": "Forward",
"ktg_settings_forward_retain_selection": "Retain selection after forward",
@ -174,5 +176,13 @@
"ktg_settings_view_profile_on_top_about": "This option also enables \"Add \"View Profile\"\" from TDesktop's experimental settings.",
"ktg_settings_emoji_sidebar": "Enable emoji sidebar",
"ktg_settings_emoji_sidebar_right_click": "Emoji sidebar on right click",
"ktg_premium_double_limits_about_accounts": {
"zero": "Connect {count} accounts with different mobile numbers in official apps",
"one": "Connect {count} account with different mobile numbers in official apps",
"two": "Connect {count} accounts with different mobile numbers in official apps",
"few": "Connect {count} accounts with different mobile numbers in official apps",
"many": "Connect {count} accounts with different mobile numbers in official apps",
"other": "Connect {count} accounts with different mobile numbers in official apps"
},
"dummy_last_string": ""
}

View file

@ -1054,6 +1054,7 @@ void FileSizeLimitBox(
});
}
/*
void AccountsLimitBox(
not_null<Ui::GenericBox*> box,
not_null<Main::Session*> session) {
@ -1180,7 +1181,7 @@ void AccountsLimitBox(
box->addSkip(st::premiumAccountsPadding.bottom());
}
}
*/
QString LimitsPremiumRef(const QString &addition) {
return "double_limits__" + addition;
}

View file

@ -78,8 +78,10 @@ void FileSizeLimitBox(
not_null<Main::Session*> session,
uint64 fileSizeBytes,
const style::PremiumLimits *stOverride = nullptr);
/*
void AccountsLimitBox(
not_null<Ui::GenericBox*> box,
not_null<Main::Session*> session);
*/
[[nodiscard]] QString LimitsPremiumRef(const QString &addition);

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "boxes/premium_preview_box.h"
#include "kotato/kotato_lang.h"
#include "chat_helpers/stickers_lottie.h"
#include "chat_helpers/stickers_emoji_pack.h"
#include "data/data_file_origin.h"
@ -1509,10 +1510,11 @@ void DoubledLimitsPreviewBox(
: (QString::number(nextMax) + QChar('+'));
entries.push_back({
tr::lng_premium_double_limits_subtitle_accounts(),
tr::lng_premium_double_limits_about_accounts(
lt_count,
rpl::single(float64(Main::Domain::kPremiumMaxAccounts)),
Ui::Text::RichLangValue),
rpl::single(Ui::Text::RichLangValue(
ktr("ktg_premium_double_limits_about_accounts",
float64(Main::Domain::kPremiumMaxAccounts),
{ "count", QString::number(Main::Domain::kPremiumMaxAccounts)})
)),
Main::Domain::kMaxAccounts,
Main::Domain::kPremiumMaxAccounts,
till,

View file

@ -332,6 +332,7 @@ void Application::run() {
showAccount(account);
}, _lifetime);
/*
(
_domain->activeValue(
) | rpl::to_empty | rpl::filter([=] {
@ -356,6 +357,7 @@ void Application::run() {
}
}
}, _lifetime);
*/
QCoreApplication::instance()->installEventFilter(this);

View file

@ -499,6 +499,7 @@ void Domain::scheduleWriteAccounts() {
}
int Domain::maxAccounts() const {
/*
const auto premiumCount = ranges::count_if(accounts(), [](
const Main::Domain::AccountWithIndex &d) {
return d.account->sessionExists()
@ -506,6 +507,8 @@ int Domain::maxAccounts() const {
|| d.account->session().isTestMode());
});
return std::min(int(premiumCount) + kMaxAccounts, kPremiumMaxAccounts);
*/
return kMaxAccounts;
}
rpl::producer<int> Domain::maxAccountsChanges() const {

View file

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/timer.h"
#include "base/weak_ptr.h"
#include "base/build_config.h"
namespace Storage {
class Domain;
@ -31,8 +32,13 @@ public:
std::unique_ptr<Account> account;
};
static constexpr auto kMaxAccounts = 3;
static constexpr auto kMaxAccountsWarn = 3;
static constexpr auto kPremiumMaxAccounts = 6;
#ifdef ARCH_CPU_64_BITS
static constexpr auto kMaxAccounts = 100;
#else
static constexpr auto kMaxAccounts = 10;
#endif
explicit Domain(const QString &dataName);
~Domain();

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "settings/settings_information.h"
#include "kotato/kotato_lang.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/vertical_layout_reorder.h"
#include "ui/wrap/padding_wrap.h"
@ -883,23 +884,21 @@ not_null<Ui::SlideWrap<Ui::SettingsButton>*> AccountsList::setupAdd() {
using Environment = MTP::Environment;
const auto add = [=](Environment environment, bool newWindow = false) {
auto &domain = _controller->session().domain();
auto found = false;
for (const auto &[index, account] : domain.accounts()) {
const auto raw = account.get();
if (!raw->sessionExists()
&& raw->mtp().environment() == environment) {
found = true;
}
}
if (!found && domain.accounts().size() >= domain.maxAccounts()) {
_controller->show(
Box(AccountsLimitBox, &_controller->session()));
} else if (newWindow) {
domain.addActivated(environment, true);
} else {
const auto sure = [=] {
_controller->window().preventOrInvoke([=] {
_controller->session().domain().addActivated(environment);
});
};
if (domain.accounts().size() >= Main::Domain::kMaxAccountsWarn) {
_controller->show(
Ui::MakeConfirmBox({
.text = ktr("ktg_too_many_accounts_warning"),
.confirmed = sure,
.confirmText = ktr("ktg_account_add_anyway"),
}),
Ui::LayerOption::KeepOther);
} else {
sure();
}
};

View file

@ -686,10 +686,22 @@ rpl::producer<QString> Main::title() {
void Main::fillTopBarMenu(const Ui::Menu::MenuCallback &addAction) {
const auto &list = Core::App().domain().accounts();
if (list.size() < Core::App().domain().maxAccounts()) {
if (list.size() < ::Main::Domain::kMaxAccountsWarn) {
addAction(tr::lng_menu_add_account(tr::now), [=] {
Core::App().domain().addActivated(MTP::Environment{});
}, &st::menuIconAddAccount);
} else if (list.size() < Core::App().domain().maxAccounts()) {
addAction(tr::lng_menu_add_account(tr::now), [=] {
_controller->show(
Ui::MakeConfirmBox({
.text = ktr("ktg_too_many_accounts_warning"),
.confirmed = [=] {
Core::App().domain().addActivated(MTP::Environment{});
},
.confirmText = ktr("ktg_account_add_anyway"),
}),
Ui::LayerOption::KeepOther);
}, &st::menuIconAddAccount);
}
if (!_controller->session().supportMode()) {
addAction(