More auto-switching between accounts.

This commit is contained in:
John Preston 2020-06-26 15:48:28 +04:00
parent 6960e4808a
commit 6068dc418d
2 changed files with 86 additions and 77 deletions

View file

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwidget.h" #include "mainwidget.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "main/main_domain.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "boxes/url_auth_box.h" #include "boxes/url_auth_box.h"
#include "ui/layers/layer_widget.h" #include "ui/layers/layer_widget.h"
@ -32,26 +33,43 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_history.h" #include "styles/style_history.h"
#include "data/data_session.h" #include "data/data_session.h"
namespace {
[[nodiscard]] MainWidget *CheckMainWidget(not_null<Main::Session*> session) {
if (const auto m = App::main()) { // multi good
if (&m->session() == session) {
return m;
}
}
if (&Core::App().domain().active() != &session->account()) {
Core::App().domain().activate(&session->account());
}
if (const auto m = App::main()) { // multi good
if (&m->session() == session) {
return m;
}
}
return nullptr;
}
} // namespace
namespace App { namespace App {
void sendBotCommand( void sendBotCommand(
not_null<PeerData*> peer, not_null<PeerData*> peer,
UserData *bot, UserData *bot,
const QString &cmd, MsgId replyTo) { const QString &cmd, MsgId replyTo) {
if (const auto m = App::main()) { // multi good if (const auto m = CheckMainWidget(&peer->session())) {
if (&m->session() == &peer->session()) {
m->sendBotCommand(peer, bot, cmd, replyTo); m->sendBotCommand(peer, bot, cmd, replyTo);
} }
} }
}
void hideSingleUseKeyboard(not_null<const HistoryItem*> message) { void hideSingleUseKeyboard(not_null<const HistoryItem*> message) {
if (const auto m = App::main()) { // multi good if (const auto m = CheckMainWidget(&message->history()->session())) {
if (&m->session() == &message->history()->session()) {
m->hideSingleUseKeyboard(message->history()->peer, message->id); m->hideSingleUseKeyboard(message->history()->peer, message->id);
} }
} }
}
bool insertBotCommand(const QString &cmd) { bool insertBotCommand(const QString &cmd) {
if (const auto m = App::main()) { // multi good if (const auto m = App::main()) { // multi good
@ -88,11 +106,9 @@ void activateBotCommand(
case ButtonType::Callback: case ButtonType::Callback:
case ButtonType::Game: { case ButtonType::Game: {
if (const auto m = App::main()) { // multi good if (const auto m = CheckMainWidget(&msg->history()->session())) {
if (&m->session() == &msg->history()->session()) {
m->app_sendBotCallback(button, msg, row, column); m->app_sendBotCallback(button, msg, row, column);
} }
}
} break; } break;
case ButtonType::Buy: { case ButtonType::Buy: {
@ -145,18 +161,15 @@ void activateBotCommand(
chosen |= PollData::Flag::Quiz; chosen |= PollData::Flag::Quiz;
} }
} }
if (const auto m = App::main()) { // multi good if (const auto m = CheckMainWidget(&msg->history()->session())) {
if (&m->session() == &msg->history()->session()) {
Window::PeerMenuCreatePoll(m->controller(), msg->history()->peer, chosen, disabled); Window::PeerMenuCreatePoll(m->controller(), msg->history()->peer, chosen, disabled);
} }
}
} break; } break;
case ButtonType::SwitchInlineSame: case ButtonType::SwitchInlineSame:
case ButtonType::SwitchInline: { case ButtonType::SwitchInline: {
const auto session = &msg->history()->session(); const auto session = &msg->history()->session();
if (const auto m = App::main()) { // multi good if (const auto m = CheckMainWidget(session)) {
if (&m->session() == session) {
if (const auto bot = msg->getMessageBot()) { if (const auto bot = msg->getMessageBot()) {
const auto fastSwitchDone = [&] { const auto fastSwitchDone = [&] {
auto samePeer = (button->type == ButtonType::SwitchInlineSame); auto samePeer = (button->type == ButtonType::SwitchInlineSame);
@ -175,7 +188,6 @@ void activateBotCommand(
} }
} }
} }
}
} break; } break;
case ButtonType::Auth: case ButtonType::Auth:
@ -185,8 +197,10 @@ void activateBotCommand(
} }
void searchByHashtag(const QString &tag, PeerData *inPeer) { void searchByHashtag(const QString &tag, PeerData *inPeer) {
if (const auto m = App::main()) { // multi good const auto m = inPeer
if (!inPeer || &m->session() == &inPeer->session()) { ? CheckMainWidget(&inPeer->session())
: App::main(); // multi good
if (m) {
if (m->controller()->openedFolder().current()) { if (m->controller()->openedFolder().current()) {
m->controller()->closeFolder(); m->controller()->closeFolder();
} }
@ -199,7 +213,6 @@ void searchByHashtag(const QString &tag, PeerData *inPeer) {
: Dialogs::Key()); : Dialogs::Key());
} }
} }
}
void showSettings() { void showSettings() {
if (auto w = App::wnd()) { if (auto w = App::wnd()) {
@ -218,6 +231,14 @@ void showPeerProfile(not_null<PeerData*> peer) {
controller->showPeerInfo(peer); controller->showPeerInfo(peer);
} }
} }
if (&Core::App().domain().active() != &peer->session().account()) {
Core::App().domain().activate(&peer->session().account());
}
if (const auto controller = window->sessionController()) {
if (&controller->session() == &peer->session()) {
controller->showPeerInfo(peer);
}
}
} }
} }
@ -226,15 +247,13 @@ void showPeerProfile(not_null<const History*> history) {
} }
void showChatsList(not_null<Main::Session*> session) { void showChatsList(not_null<Main::Session*> session) {
if (const auto m = App::main()) { // multi good if (const auto m = CheckMainWidget(session)) {
if (&m->session() == session) {
m->ui_showPeerHistory( m->ui_showPeerHistory(
0, 0,
Window::SectionShow::Way::ClearStack, Window::SectionShow::Way::ClearStack,
0); 0);
} }
} }
}
void showPeerHistoryAtItem(not_null<const HistoryItem*> item) { void showPeerHistoryAtItem(not_null<const HistoryItem*> item) {
showPeerHistory(item->history()->peer, item->id); showPeerHistory(item->history()->peer, item->id);
@ -245,15 +264,13 @@ void showPeerHistory(not_null<const History*> history, MsgId msgId) {
} }
void showPeerHistory(not_null<const PeerData*> peer, MsgId msgId) { void showPeerHistory(not_null<const PeerData*> peer, MsgId msgId) {
if (const auto m = App::main()) { // multi good if (const auto m = CheckMainWidget(&peer->session())) {
if (&m->session() == &peer->session()) {
m->ui_showPeerHistory( m->ui_showPeerHistory(
peer->id, peer->id,
Window::SectionShow::Way::ClearStack, Window::SectionShow::Way::ClearStack,
msgId); msgId);
} }
} }
}
PeerData *getPeerForMouseAction() { PeerData *getPeerForMouseAction() {
return Core::App().ui_getPeerForMouseAction(); return Core::App().ui_getPeerForMouseAction();
@ -273,40 +290,34 @@ bool skipPaintEvent(QWidget *widget, QPaintEvent *event) {
namespace Notify { namespace Notify {
void replyMarkupUpdated(not_null<const HistoryItem*> item) { void replyMarkupUpdated(not_null<const HistoryItem*> item) {
if (const auto m = App::main()) { // multi good if (const auto m = CheckMainWidget(&item->history()->session())) {
if (&m->session() == &item->history()->session()) {
m->notify_replyMarkupUpdated(item); m->notify_replyMarkupUpdated(item);
} }
} }
}
void inlineKeyboardMoved( void inlineKeyboardMoved(
not_null<const HistoryItem*> item, not_null<const HistoryItem*> item,
int oldKeyboardTop, int oldKeyboardTop,
int newKeyboardTop) { int newKeyboardTop) {
if (const auto m = App::main()) { // multi good if (const auto m = CheckMainWidget(&item->history()->session())) {
if (&m->session() == &item->history()->session()) {
m->notify_inlineKeyboardMoved( m->notify_inlineKeyboardMoved(
item, item,
oldKeyboardTop, oldKeyboardTop,
newKeyboardTop); newKeyboardTop);
} }
} }
}
bool switchInlineBotButtonReceived( bool switchInlineBotButtonReceived(
not_null<Main::Session*> session, not_null<Main::Session*> session,
const QString &query, const QString &query,
UserData *samePeerBot, UserData *samePeerBot,
MsgId samePeerReplyTo) { MsgId samePeerReplyTo) {
if (const auto m = App::main()) { // multi good if (const auto m = CheckMainWidget(session)) {
if (session == &m->session()) {
return m->notify_switchInlineBotButtonReceived( return m->notify_switchInlineBotButtonReceived(
query, query,
samePeerBot, samePeerBot,
samePeerReplyTo); samePeerReplyTo);
} }
}
return false; return false;
} }

View file

@ -1219,7 +1219,6 @@ void OverlayWidget::onToMessage() {
} }
if (const auto item = _session->data().message(_msgid)) { if (const auto item = _session->data().message(_msgid)) {
close(); close();
Core::App().domain().activate(&_session->account());
Ui::showPeerHistoryAtItem(item); Ui::showPeerHistoryAtItem(item);
} }
} }
@ -3852,7 +3851,6 @@ void OverlayWidget::mouseReleaseEvent(QMouseEvent *e) {
if (_over == OverName && _down == OverName) { if (_over == OverName && _down == OverName) {
if (_from) { if (_from) {
close(); close();
Core::App().domain().activate(&_from->account());
Ui::showPeerProfile(_from); Ui::showPeerProfile(_from);
} }
} else if (_over == OverDate && _down == OverDate) { } else if (_over == OverDate && _down == OverDate) {