mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Add account from settings three-dot menu.
This commit is contained in:
parent
dd0e0a10cd
commit
5cc7c2b6c6
4 changed files with 24 additions and 12 deletions
|
@ -273,6 +273,20 @@ not_null<Main::Account*> Domain::add(MTP::Environment environment) {
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Domain::addActivated(MTP::Environment environment) {
|
||||||
|
if (accounts().size() < Main::Domain::kMaxAccounts) {
|
||||||
|
activate(add(environment));
|
||||||
|
} else {
|
||||||
|
for (auto &[index, account] : accounts()) {
|
||||||
|
if (!account->sessionExists()
|
||||||
|
&& account->mtp().environment() == environment) {
|
||||||
|
activate(account.get());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Domain::watchSession(not_null<Account*> account) {
|
void Domain::watchSession(not_null<Account*> account) {
|
||||||
account->sessionValue(
|
account->sessionValue(
|
||||||
) | rpl::filter([=](Session *session) {
|
) | rpl::filter([=](Session *session) {
|
||||||
|
|
|
@ -64,6 +64,7 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] not_null<Main::Account*> add(MTP::Environment environment);
|
[[nodiscard]] not_null<Main::Account*> add(MTP::Environment environment);
|
||||||
void activate(not_null<Main::Account*> account);
|
void activate(not_null<Main::Account*> account);
|
||||||
|
void addActivated(MTP::Environment environment);
|
||||||
|
|
||||||
// Interface for Storage::Domain.
|
// Interface for Storage::Domain.
|
||||||
void accountAddedInStorage(AccountWithIndex accountWithIndex);
|
void accountAddedInStorage(AccountWithIndex accountWithIndex);
|
||||||
|
|
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "settings/settings_privacy_security.h"
|
#include "settings/settings_privacy_security.h"
|
||||||
#include "settings/settings_folders.h"
|
#include "settings/settings_folders.h"
|
||||||
#include "settings/settings_calls.h"
|
#include "settings/settings_calls.h"
|
||||||
|
#include "core/application.h"
|
||||||
#include "ui/wrap/padding_wrap.h"
|
#include "ui/wrap/padding_wrap.h"
|
||||||
#include "ui/wrap/vertical_layout.h"
|
#include "ui/wrap/vertical_layout.h"
|
||||||
#include "ui/widgets/labels.h"
|
#include "ui/widgets/labels.h"
|
||||||
|
@ -27,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "main/main_domain.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_settings.h"
|
#include "styles/style_settings.h"
|
||||||
|
|
||||||
|
@ -195,6 +197,12 @@ void FillMenu(
|
||||||
tr::lng_settings_bg_theme_create(tr::now),
|
tr::lng_settings_bg_theme_create(tr::now),
|
||||||
[=] { window->show(Box(Window::Theme::CreateBox, window)); });
|
[=] { window->show(Box(Window::Theme::CreateBox, window)); });
|
||||||
} else {
|
} else {
|
||||||
|
const auto &list = Core::App().domain().accounts();
|
||||||
|
if (list.size() < ::Main::Domain::kMaxAccounts) {
|
||||||
|
addAction(tr::lng_menu_add_account(tr::now), [=] {
|
||||||
|
Core::App().domain().addActivated(MTP::Environment{});
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!controller->session().supportMode()) {
|
if (!controller->session().supportMode()) {
|
||||||
addAction(
|
addAction(
|
||||||
tr::lng_settings_information(tr::now),
|
tr::lng_settings_information(tr::now),
|
||||||
|
|
|
@ -799,18 +799,7 @@ not_null<Ui::SlideWrap<Ui::RippleButton>*> MainMenu::setupAddAccount(
|
||||||
}, button->lifetime());
|
}, button->lifetime());
|
||||||
|
|
||||||
const auto add = [=](MTP::Environment environment) {
|
const auto add = [=](MTP::Environment environment) {
|
||||||
auto &domain = Core::App().domain();
|
Core::App().domain().addActivated(environment);
|
||||||
if (domain.accounts().size() < Main::Domain::kMaxAccounts) {
|
|
||||||
domain.activate(domain.add(environment));
|
|
||||||
} else {
|
|
||||||
for (auto &[index, account] : domain.accounts()) {
|
|
||||||
if (!account->sessionExists()
|
|
||||||
&& account->mtp().environment() == environment) {
|
|
||||||
domain.activate(account.get());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
button->setAcceptBoth(true);
|
button->setAcceptBoth(true);
|
||||||
|
|
Loading…
Add table
Reference in a new issue