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 "apiwrap.h"
#include "main/main_session.h"
#include "main/main_domain.h"
#include "boxes/confirm_box.h"
#include "boxes/url_auth_box.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 "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 {
void sendBotCommand(
not_null<PeerData*> peer,
UserData *bot,
const QString &cmd, MsgId replyTo) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &peer->session()) {
if (const auto m = CheckMainWidget(&peer->session())) {
m->sendBotCommand(peer, bot, cmd, replyTo);
}
}
}
void hideSingleUseKeyboard(not_null<const HistoryItem*> message) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &message->history()->session()) {
if (const auto m = CheckMainWidget(&message->history()->session())) {
m->hideSingleUseKeyboard(message->history()->peer, message->id);
}
}
}
bool insertBotCommand(const QString &cmd) {
if (const auto m = App::main()) { // multi good
@ -88,11 +106,9 @@ void activateBotCommand(
case ButtonType::Callback:
case ButtonType::Game: {
if (const auto m = App::main()) { // multi good
if (&m->session() == &msg->history()->session()) {
if (const auto m = CheckMainWidget(&msg->history()->session())) {
m->app_sendBotCallback(button, msg, row, column);
}
}
} break;
case ButtonType::Buy: {
@ -145,18 +161,15 @@ void activateBotCommand(
chosen |= PollData::Flag::Quiz;
}
}
if (const auto m = App::main()) { // multi good
if (&m->session() == &msg->history()->session()) {
if (const auto m = CheckMainWidget(&msg->history()->session())) {
Window::PeerMenuCreatePoll(m->controller(), msg->history()->peer, chosen, disabled);
}
}
} break;
case ButtonType::SwitchInlineSame:
case ButtonType::SwitchInline: {
const auto session = &msg->history()->session();
if (const auto m = App::main()) { // multi good
if (&m->session() == session) {
if (const auto m = CheckMainWidget(session)) {
if (const auto bot = msg->getMessageBot()) {
const auto fastSwitchDone = [&] {
auto samePeer = (button->type == ButtonType::SwitchInlineSame);
@ -175,7 +188,6 @@ void activateBotCommand(
}
}
}
}
} break;
case ButtonType::Auth:
@ -185,8 +197,10 @@ void activateBotCommand(
}
void searchByHashtag(const QString &tag, PeerData *inPeer) {
if (const auto m = App::main()) { // multi good
if (!inPeer || &m->session() == &inPeer->session()) {
const auto m = inPeer
? CheckMainWidget(&inPeer->session())
: App::main(); // multi good
if (m) {
if (m->controller()->openedFolder().current()) {
m->controller()->closeFolder();
}
@ -199,7 +213,6 @@ void searchByHashtag(const QString &tag, PeerData *inPeer) {
: Dialogs::Key());
}
}
}
void showSettings() {
if (auto w = App::wnd()) {
@ -218,6 +231,14 @@ void showPeerProfile(not_null<PeerData*> 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) {
if (const auto m = App::main()) { // multi good
if (&m->session() == session) {
if (const auto m = CheckMainWidget(session)) {
m->ui_showPeerHistory(
0,
Window::SectionShow::Way::ClearStack,
0);
}
}
}
void showPeerHistoryAtItem(not_null<const HistoryItem*> item) {
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) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &peer->session()) {
if (const auto m = CheckMainWidget(&peer->session())) {
m->ui_showPeerHistory(
peer->id,
Window::SectionShow::Way::ClearStack,
msgId);
}
}
}
PeerData *getPeerForMouseAction() {
return Core::App().ui_getPeerForMouseAction();
@ -273,40 +290,34 @@ bool skipPaintEvent(QWidget *widget, QPaintEvent *event) {
namespace Notify {
void replyMarkupUpdated(not_null<const HistoryItem*> item) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &item->history()->session()) {
if (const auto m = CheckMainWidget(&item->history()->session())) {
m->notify_replyMarkupUpdated(item);
}
}
}
void inlineKeyboardMoved(
not_null<const HistoryItem*> item,
int oldKeyboardTop,
int newKeyboardTop) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &item->history()->session()) {
if (const auto m = CheckMainWidget(&item->history()->session())) {
m->notify_inlineKeyboardMoved(
item,
oldKeyboardTop,
newKeyboardTop);
}
}
}
bool switchInlineBotButtonReceived(
not_null<Main::Session*> session,
const QString &query,
UserData *samePeerBot,
MsgId samePeerReplyTo) {
if (const auto m = App::main()) { // multi good
if (session == &m->session()) {
if (const auto m = CheckMainWidget(session)) {
return m->notify_switchInlineBotButtonReceived(
query,
samePeerBot,
samePeerReplyTo);
}
}
return false;
}

View file

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