2017-02-23 10:59:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-02-23 10:59:19 +00:00
|
|
|
*/
|
|
|
|
#include "messenger.h"
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_photo.h"
|
|
|
|
#include "data/data_document.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "data/data_session.h"
|
2017-04-29 20:06:32 +00:00
|
|
|
#include "base/timer.h"
|
2018-04-18 15:42:02 +00:00
|
|
|
#include "core/update_checker.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
|
|
|
#include "platform/platform_specific.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "mainwindow.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "dialogs/dialogs_entry.h"
|
|
|
|
#include "history/history.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "application.h"
|
|
|
|
#include "shortcuts.h"
|
|
|
|
#include "auth_session.h"
|
2017-04-29 20:06:32 +00:00
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "calls/calls_instance.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_file_parser.h"
|
2017-04-13 08:45:58 +00:00
|
|
|
#include "lang/lang_translator.h"
|
2017-04-18 15:21:03 +00:00
|
|
|
#include "lang/lang_cloud_manager.h"
|
2018-05-24 13:40:19 +00:00
|
|
|
#include "lang/lang_hardcoded.h"
|
2018-05-28 05:10:30 +00:00
|
|
|
#include "core/update_checker.h"
|
2018-03-18 08:51:14 +00:00
|
|
|
#include "passport/passport_form_controller.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "observer_peer.h"
|
2018-08-29 13:23:16 +00:00
|
|
|
#include "storage/storage_databases.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "mainwidget.h"
|
2017-08-08 09:31:48 +00:00
|
|
|
#include "mediaview.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "mtproto/dc_options.h"
|
2017-02-24 17:15:41 +00:00
|
|
|
#include "mtproto/mtp_instance.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "media/player/media_player_instance.h"
|
2018-06-04 18:18:52 +00:00
|
|
|
#include "media/media_audio.h"
|
2017-05-03 11:36:39 +00:00
|
|
|
#include "media/media_audio_track.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "window/notifications_manager.h"
|
|
|
|
#include "window/themes/window_theme.h"
|
2018-06-03 13:30:40 +00:00
|
|
|
#include "window/window_lock_widgets.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
#include "history/history_location_manager.h"
|
|
|
|
#include "ui/widgets/tooltip.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2017-12-28 13:06:06 +00:00
|
|
|
#include "ui/text_options.h"
|
2018-10-13 17:35:30 +00:00
|
|
|
#include "ui/emoji_config.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/serialize_common.h"
|
2017-04-09 18:06:06 +00:00
|
|
|
#include "window/window_controller.h"
|
2017-06-27 20:11:38 +00:00
|
|
|
#include "base/qthelp_regex.h"
|
|
|
|
#include "base/qthelp_url.h"
|
|
|
|
#include "boxes/connection_box.h"
|
|
|
|
#include "boxes/confirm_phone_box.h"
|
2018-05-24 13:40:19 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2017-06-27 20:11:38 +00:00
|
|
|
#include "boxes/share_box.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-04-29 20:06:32 +00:00
|
|
|
constexpr auto kQuitPreventTimeoutMs = 1500;
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
Messenger *SingleInstance = nullptr;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
Messenger *Messenger::InstancePointer() {
|
|
|
|
return SingleInstance;
|
|
|
|
}
|
|
|
|
|
2017-02-24 17:15:41 +00:00
|
|
|
struct Messenger::Private {
|
2017-04-06 19:02:40 +00:00
|
|
|
UserId authSessionUserId = 0;
|
2018-09-11 12:50:40 +00:00
|
|
|
QByteArray authSessionUserSerialized;
|
2018-09-11 14:36:09 +00:00
|
|
|
int32 authSessionUserStreamVersion = 0;
|
2018-01-04 10:22:53 +00:00
|
|
|
std::unique_ptr<AuthSessionSettings> storedAuthSession;
|
2017-02-24 17:15:41 +00:00
|
|
|
MTP::Instance::Config mtpConfig;
|
2017-02-25 16:44:02 +00:00
|
|
|
MTP::AuthKeysList mtpKeysToDestroy;
|
2017-04-29 20:06:32 +00:00
|
|
|
base::Timer quitTimer;
|
2017-02-24 17:15:41 +00:00
|
|
|
};
|
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
Messenger::Messenger(not_null<Core::Launcher*> launcher)
|
|
|
|
: QObject()
|
|
|
|
, _launcher(launcher)
|
2017-05-03 11:36:39 +00:00
|
|
|
, _private(std::make_unique<Private>())
|
2018-08-29 13:23:16 +00:00
|
|
|
, _databases(std::make_unique<Storage::Databases>())
|
2017-04-13 17:59:05 +00:00
|
|
|
, _langpack(std::make_unique<Lang::Instance>())
|
2017-05-12 15:27:19 +00:00
|
|
|
, _audio(std::make_unique<Media::Audio::Instance>())
|
|
|
|
, _logo(Window::LoadLogo())
|
|
|
|
, _logoNoMargin(Window::LoadLogoNoMargin()) {
|
|
|
|
Expects(!_logo.isNull());
|
|
|
|
Expects(!_logoNoMargin.isNull());
|
|
|
|
Expects(SingleInstance == nullptr);
|
2018-04-23 10:24:03 +00:00
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
SingleInstance = this;
|
|
|
|
|
2017-04-30 16:03:12 +00:00
|
|
|
Fonts::Start();
|
2017-02-23 10:59:19 +00:00
|
|
|
|
|
|
|
ThirdParty::start();
|
|
|
|
Global::start();
|
2018-04-23 10:24:03 +00:00
|
|
|
Sandbox::refreshGlobalProxy(); // Depends on Global::started().
|
2017-02-23 10:59:19 +00:00
|
|
|
|
|
|
|
startLocalStorage();
|
|
|
|
|
|
|
|
if (Local::oldSettingsVersion() < AppVersion) {
|
|
|
|
psNewVersion();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cLaunchMode() == LaunchModeAutoStart && !cAutoStart()) {
|
|
|
|
psAutoStart(false, true);
|
|
|
|
App::quit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
_translator = std::make_unique<Lang::Translator>();
|
|
|
|
QCoreApplication::instance()->installTranslator(_translator.get());
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
style::startManager();
|
|
|
|
anim::startManager();
|
2017-12-28 13:06:06 +00:00
|
|
|
Ui::InitTextOptions();
|
2018-10-13 17:35:30 +00:00
|
|
|
Ui::Emoji::Init();
|
2017-02-23 10:59:19 +00:00
|
|
|
Media::Player::start();
|
|
|
|
|
|
|
|
DEBUG_LOG(("Application Info: inited..."));
|
|
|
|
|
|
|
|
QCoreApplication::instance()->installNativeEventFilter(psNativeEventFilter());
|
|
|
|
|
|
|
|
cChangeTimeFormat(QLocale::system().timeFormat(QLocale::ShortFormat));
|
|
|
|
|
|
|
|
connect(&killDownloadSessionsTimer, SIGNAL(timeout()), this, SLOT(killDownloadSessions()));
|
|
|
|
|
|
|
|
DEBUG_LOG(("Application Info: starting app..."));
|
|
|
|
|
|
|
|
// Create mime database, so it won't be slow later.
|
|
|
|
QMimeDatabase().mimeTypeForName(qsl("text/plain"));
|
|
|
|
|
|
|
|
_window = std::make_unique<MainWindow>();
|
|
|
|
_window->init();
|
|
|
|
|
2017-09-03 19:10:50 +00:00
|
|
|
auto currentGeometry = _window->geometry();
|
2017-08-08 09:31:48 +00:00
|
|
|
_mediaView = std::make_unique<MediaView>();
|
2017-09-03 19:10:50 +00:00
|
|
|
_window->setGeometry(currentGeometry);
|
2017-08-08 09:31:48 +00:00
|
|
|
|
|
|
|
QCoreApplication::instance()->installEventFilter(this);
|
2017-02-23 10:59:19 +00:00
|
|
|
Sandbox::connect(SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onAppStateChanged(Qt::ApplicationState)));
|
|
|
|
|
|
|
|
DEBUG_LOG(("Application Info: window created..."));
|
|
|
|
|
|
|
|
Shortcuts::start();
|
|
|
|
|
|
|
|
App::initMedia();
|
|
|
|
|
|
|
|
Local::ReadMapState state = Local::readMap(QByteArray());
|
|
|
|
if (state == Local::ReadMapPassNeeded) {
|
|
|
|
Global::SetLocalPasscode(true);
|
|
|
|
Global::RefLocalPasscodeChanged().notify();
|
2018-06-07 07:44:38 +00:00
|
|
|
lockByPasscode();
|
2017-02-23 10:59:19 +00:00
|
|
|
DEBUG_LOG(("Application Info: passcode needed..."));
|
|
|
|
} else {
|
|
|
|
DEBUG_LOG(("Application Info: local map read..."));
|
2017-02-24 17:15:41 +00:00
|
|
|
startMtp();
|
2018-06-07 07:44:38 +00:00
|
|
|
DEBUG_LOG(("Application Info: MTP started..."));
|
2017-03-04 19:36:59 +00:00
|
|
|
if (AuthSession::Exists()) {
|
2017-02-23 10:59:19 +00:00
|
|
|
_window->setupMain();
|
|
|
|
} else {
|
|
|
|
_window->setupIntro();
|
|
|
|
}
|
|
|
|
}
|
2018-06-07 07:44:38 +00:00
|
|
|
DEBUG_LOG(("Application Info: showing."));
|
2017-02-23 10:59:19 +00:00
|
|
|
_window->firstShow();
|
|
|
|
|
|
|
|
if (cStartToSettings()) {
|
|
|
|
_window->showSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
_window->updateIsActive(Global::OnlineFocusTimeout());
|
|
|
|
|
|
|
|
if (!Shortcuts::errors().isEmpty()) {
|
|
|
|
const QStringList &errors(Shortcuts::errors());
|
|
|
|
for (QStringList::const_iterator i = errors.cbegin(), e = errors.cend(); i != e; ++i) {
|
|
|
|
LOG(("Shortcuts Error: %1").arg(*i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
bool Messenger::hideMediaView() {
|
|
|
|
if (_mediaView && !_mediaView->isHidden()) {
|
|
|
|
_mediaView->hide();
|
2017-08-08 09:56:10 +00:00
|
|
|
if (auto activeWindow = getActiveWindow()) {
|
|
|
|
activeWindow->reActivateWindow();
|
|
|
|
}
|
2017-08-08 09:31:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
void Messenger::showPhoto(not_null<const PhotoOpenClickHandler*> link) {
|
|
|
|
const auto item = App::histItemById(link->context());
|
|
|
|
const auto peer = link->peer();
|
|
|
|
return (!item && peer)
|
|
|
|
? showPhoto(link->photo(), peer)
|
2017-08-08 09:31:48 +00:00
|
|
|
: showPhoto(link->photo(), item);
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void Messenger::showPhoto(not_null<PhotoData*> photo, HistoryItem *item) {
|
2017-09-20 10:23:57 +00:00
|
|
|
if (_mediaView->isHidden()) Ui::hideLayer(anim::type::instant);
|
2017-08-08 09:31:48 +00:00
|
|
|
_mediaView->showPhoto(photo, item);
|
|
|
|
_mediaView->activateWindow();
|
|
|
|
_mediaView->setFocus();
|
|
|
|
}
|
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
void Messenger::showPhoto(
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
not_null<PeerData*> peer) {
|
2017-09-20 10:23:57 +00:00
|
|
|
if (_mediaView->isHidden()) Ui::hideLayer(anim::type::instant);
|
2017-08-08 09:31:48 +00:00
|
|
|
_mediaView->showPhoto(photo, peer);
|
|
|
|
_mediaView->activateWindow();
|
|
|
|
_mediaView->setFocus();
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void Messenger::showDocument(not_null<DocumentData*> document, HistoryItem *item) {
|
2017-12-10 10:26:58 +00:00
|
|
|
if (cUseExternalVideoPlayer() && document->isVideoFile()) {
|
2017-08-08 09:31:48 +00:00
|
|
|
QDesktopServices::openUrl(QUrl("file:///" + document->location(false).fname));
|
|
|
|
} else {
|
2017-09-20 10:23:57 +00:00
|
|
|
if (_mediaView->isHidden()) {
|
|
|
|
Ui::hideLayer(anim::type::instant);
|
|
|
|
}
|
2017-08-08 09:31:48 +00:00
|
|
|
_mediaView->showDocument(document, item);
|
|
|
|
_mediaView->activateWindow();
|
|
|
|
_mediaView->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerData *Messenger::ui_getPeerForMouseAction() {
|
|
|
|
if (_mediaView && !_mediaView->isHidden()) {
|
|
|
|
return _mediaView->ui_getPeerForMouseAction();
|
|
|
|
} else if (auto main = App::main()) {
|
|
|
|
return main->ui_getPeerForMouseAction();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Messenger::eventFilter(QObject *object, QEvent *e) {
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::KeyPress:
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
case QEvent::TouchBegin:
|
|
|
|
case QEvent::Wheel: {
|
|
|
|
psUserActionDone();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::ShortcutOverride: {
|
|
|
|
// handle shortcuts ourselves
|
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::Shortcut: {
|
|
|
|
DEBUG_LOG(("Shortcut event caught: %1").arg(static_cast<QShortcutEvent*>(e)->key().toString()));
|
|
|
|
if (Shortcuts::launch(static_cast<QShortcutEvent*>(e)->shortcutId())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::ApplicationActivate: {
|
|
|
|
if (object == QCoreApplication::instance()) {
|
|
|
|
psUserActionDone();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::FileOpen: {
|
|
|
|
if (object == QCoreApplication::instance()) {
|
|
|
|
auto url = QString::fromUtf8(static_cast<QFileOpenEvent*>(e)->url().toEncoded().trimmed());
|
|
|
|
if (url.startsWith(qstr("tg://"), Qt::CaseInsensitive)) {
|
|
|
|
cSetStartUrl(url.mid(0, 8192));
|
|
|
|
checkStartUrl();
|
|
|
|
}
|
2018-04-13 05:11:53 +00:00
|
|
|
if (StartUrlRequiresActivate(url)) {
|
|
|
|
_window->activate();
|
|
|
|
}
|
2017-08-08 09:31:48 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QObject::eventFilter(object, e);
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:20:28 +00:00
|
|
|
void Messenger::setCurrentProxy(
|
|
|
|
const ProxyData &proxy,
|
2018-11-05 13:58:24 +00:00
|
|
|
ProxyData::Settings settings) {
|
2018-05-18 12:20:28 +00:00
|
|
|
const auto key = [&](const ProxyData &proxy) {
|
|
|
|
if (proxy.type == ProxyData::Type::Mtproto) {
|
|
|
|
return std::make_pair(proxy.host, proxy.port);
|
|
|
|
}
|
|
|
|
return std::make_pair(QString(), uint32(0));
|
|
|
|
};
|
2018-11-05 13:58:24 +00:00
|
|
|
const auto previousKey = key(
|
|
|
|
(Global::ProxySettings() == ProxyData::Settings::Enabled
|
|
|
|
? Global::SelectedProxy()
|
|
|
|
: ProxyData()));
|
2018-05-18 12:20:28 +00:00
|
|
|
Global::SetSelectedProxy(proxy);
|
2018-11-05 13:58:24 +00:00
|
|
|
Global::SetProxySettings(settings);
|
2018-05-18 12:20:28 +00:00
|
|
|
Sandbox::refreshGlobalProxy();
|
|
|
|
if (_mtproto) {
|
|
|
|
_mtproto->restart();
|
|
|
|
if (previousKey != key(proxy)) {
|
|
|
|
_mtproto->reInitConnection(_mtproto->mainDcId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_mtprotoForKeysDestroy) {
|
|
|
|
_mtprotoForKeysDestroy->restart();
|
|
|
|
}
|
|
|
|
Global::RefConnectionTypeChanged().notify();
|
|
|
|
}
|
|
|
|
|
2018-05-24 13:40:19 +00:00
|
|
|
void Messenger::badMtprotoConfigurationError() {
|
2018-11-05 13:58:24 +00:00
|
|
|
if (Global::ProxySettings() == ProxyData::Settings::Enabled
|
|
|
|
&& !_badProxyDisableBox) {
|
|
|
|
const auto disableCallback = [=] {
|
|
|
|
setCurrentProxy(
|
|
|
|
Global::SelectedProxy(),
|
|
|
|
ProxyData::Settings::System);
|
|
|
|
};
|
2018-05-24 13:40:19 +00:00
|
|
|
_badProxyDisableBox = Ui::show(Box<InformBox>(
|
|
|
|
Lang::Hard::ProxyConfigError(),
|
2018-11-05 13:58:24 +00:00
|
|
|
disableCallback));
|
2018-05-24 13:40:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-24 17:15:41 +00:00
|
|
|
void Messenger::setMtpMainDcId(MTP::DcId mainDcId) {
|
2017-04-06 19:02:40 +00:00
|
|
|
Expects(!_mtproto);
|
2018-05-18 12:20:28 +00:00
|
|
|
|
2017-02-24 17:15:41 +00:00
|
|
|
_private->mtpConfig.mainDcId = mainDcId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::setMtpKey(MTP::DcId dcId, const MTP::AuthKey::Data &keyData) {
|
2017-04-06 19:02:40 +00:00
|
|
|
Expects(!_mtproto);
|
2018-05-18 12:20:28 +00:00
|
|
|
|
2017-02-25 16:44:02 +00:00
|
|
|
_private->mtpConfig.keys.push_back(std::make_shared<MTP::AuthKey>(MTP::AuthKey::Type::ReadFromFile, dcId, keyData));
|
2017-02-24 17:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray Messenger::serializeMtpAuthorization() const {
|
2017-02-25 16:44:02 +00:00
|
|
|
auto serialize = [this](auto mainDcId, auto &keys, auto &keysToDestroy) {
|
|
|
|
auto keysSize = [](auto &list) {
|
|
|
|
return sizeof(qint32) + list.size() * (sizeof(qint32) + MTP::AuthKey::Data().size());
|
|
|
|
};
|
|
|
|
auto writeKeys = [](QDataStream &stream, auto &keys) {
|
|
|
|
stream << qint32(keys.size());
|
|
|
|
for (auto &key : keys) {
|
|
|
|
stream << qint32(key->dcId());
|
|
|
|
key->write(stream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-24 17:15:41 +00:00
|
|
|
auto result = QByteArray();
|
2017-02-25 16:44:02 +00:00
|
|
|
auto size = sizeof(qint32) + sizeof(qint32); // userId + mainDcId
|
|
|
|
size += keysSize(keys) + keysSize(keysToDestroy);
|
2017-02-24 17:15:41 +00:00
|
|
|
result.reserve(size);
|
|
|
|
{
|
2017-04-13 17:59:05 +00:00
|
|
|
QDataStream stream(&result, QIODevice::WriteOnly);
|
2017-02-24 17:15:41 +00:00
|
|
|
stream.setVersion(QDataStream::Qt_5_1);
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
auto currentUserId = _authSession ? _authSession->userId() : 0;
|
2017-04-03 18:59:13 +00:00
|
|
|
stream << qint32(currentUserId) << qint32(mainDcId);
|
2017-02-25 16:44:02 +00:00
|
|
|
writeKeys(stream, keys);
|
|
|
|
writeKeys(stream, keysToDestroy);
|
2017-04-03 18:59:13 +00:00
|
|
|
|
|
|
|
DEBUG_LOG(("MTP Info: Keys written, userId: %1, dcId: %2").arg(currentUserId).arg(mainDcId));
|
2017-02-24 17:15:41 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
if (_mtproto) {
|
|
|
|
auto keys = _mtproto->getKeysForWrite();
|
2017-02-25 16:44:02 +00:00
|
|
|
auto keysToDestroy = _mtprotoForKeysDestroy ? _mtprotoForKeysDestroy->getKeysForWrite() : MTP::AuthKeysList();
|
|
|
|
return serialize(_mtproto->mainDcId(), keys, keysToDestroy);
|
2017-02-24 17:15:41 +00:00
|
|
|
}
|
|
|
|
auto &keys = _private->mtpConfig.keys;
|
2017-02-25 16:44:02 +00:00
|
|
|
auto &keysToDestroy = _private->mtpKeysToDestroy;
|
|
|
|
return serialize(_private->mtpConfig.mainDcId, keys, keysToDestroy);
|
2017-02-24 17:15:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-06 19:02:40 +00:00
|
|
|
void Messenger::setAuthSessionUserId(UserId userId) {
|
|
|
|
Expects(!authSession());
|
2018-09-11 14:36:09 +00:00
|
|
|
|
2017-04-06 19:02:40 +00:00
|
|
|
_private->authSessionUserId = userId;
|
|
|
|
}
|
|
|
|
|
2018-09-11 14:36:09 +00:00
|
|
|
void Messenger::setAuthSessionFromStorage(
|
|
|
|
std::unique_ptr<AuthSessionSettings> data,
|
|
|
|
QByteArray &&selfSerialized,
|
|
|
|
int32 selfStreamVersion) {
|
2017-04-06 19:02:40 +00:00
|
|
|
Expects(!authSession());
|
2018-09-11 14:36:09 +00:00
|
|
|
|
2017-04-09 18:06:06 +00:00
|
|
|
_private->storedAuthSession = std::move(data);
|
2018-09-11 14:36:09 +00:00
|
|
|
_private->authSessionUserSerialized = std::move(selfSerialized);
|
|
|
|
_private->authSessionUserStreamVersion = selfStreamVersion;
|
2017-04-06 19:02:40 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
AuthSessionSettings *Messenger::getAuthSessionSettings() {
|
2017-04-06 19:02:40 +00:00
|
|
|
if (_private->authSessionUserId) {
|
2018-01-04 10:22:53 +00:00
|
|
|
return _private->storedAuthSession
|
|
|
|
? _private->storedAuthSession.get()
|
|
|
|
: nullptr;
|
2017-08-04 14:54:32 +00:00
|
|
|
} else if (_authSession) {
|
2018-01-04 10:22:53 +00:00
|
|
|
return &_authSession->settings();
|
2017-04-06 19:02:40 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-02-24 17:15:41 +00:00
|
|
|
void Messenger::setMtpAuthorization(const QByteArray &serialized) {
|
2017-04-06 19:02:40 +00:00
|
|
|
Expects(!_mtproto);
|
2017-02-24 17:15:41 +00:00
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
QDataStream stream(serialized);
|
2017-02-24 17:15:41 +00:00
|
|
|
stream.setVersion(QDataStream::Qt_5_1);
|
|
|
|
|
2017-02-25 16:44:02 +00:00
|
|
|
auto userId = Serialize::read<qint32>(stream);
|
|
|
|
auto mainDcId = Serialize::read<qint32>(stream);
|
2017-02-24 17:15:41 +00:00
|
|
|
if (stream.status() != QDataStream::Ok) {
|
|
|
|
LOG(("MTP Error: could not read main fields from serialized mtp authorization."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-06 19:02:40 +00:00
|
|
|
setAuthSessionUserId(userId);
|
2017-02-24 17:15:41 +00:00
|
|
|
_private->mtpConfig.mainDcId = mainDcId;
|
2017-02-25 16:44:02 +00:00
|
|
|
|
|
|
|
auto readKeys = [&stream](auto &keys) {
|
|
|
|
auto count = Serialize::read<qint32>(stream);
|
2017-02-24 17:15:41 +00:00
|
|
|
if (stream.status() != QDataStream::Ok) {
|
2017-02-25 16:44:02 +00:00
|
|
|
LOG(("MTP Error: could not read keys count from serialized mtp authorization."));
|
2017-02-24 17:15:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-02-25 16:44:02 +00:00
|
|
|
keys.reserve(count);
|
|
|
|
for (auto i = 0; i != count; ++i) {
|
|
|
|
auto dcId = Serialize::read<qint32>(stream);
|
|
|
|
auto keyData = Serialize::read<MTP::AuthKey::Data>(stream);
|
|
|
|
if (stream.status() != QDataStream::Ok) {
|
|
|
|
LOG(("MTP Error: could not read key from serialized mtp authorization."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
keys.push_back(std::make_shared<MTP::AuthKey>(MTP::AuthKey::Type::ReadFromFile, dcId, keyData));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
readKeys(_private->mtpConfig.keys);
|
|
|
|
readKeys(_private->mtpKeysToDestroy);
|
|
|
|
LOG(("MTP Info: read keys, current: %1, to destroy: %2").arg(_private->mtpConfig.keys.size()).arg(_private->mtpKeysToDestroy.size()));
|
2017-02-24 17:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::startMtp() {
|
2017-04-06 19:02:40 +00:00
|
|
|
Expects(!_mtproto);
|
2018-04-23 10:24:03 +00:00
|
|
|
|
2018-05-02 19:27:03 +00:00
|
|
|
_mtproto = std::make_unique<MTP::Instance>(
|
|
|
|
_dcOptions.get(),
|
|
|
|
MTP::Instance::Mode::Normal,
|
|
|
|
base::take(_private->mtpConfig));
|
|
|
|
_mtproto->setUserPhone(cLoggedPhoneNumber());
|
2017-02-25 16:44:02 +00:00
|
|
|
_private->mtpConfig.mainDcId = _mtproto->mainDcId();
|
2017-02-24 17:15:41 +00:00
|
|
|
|
2018-05-07 17:44:33 +00:00
|
|
|
_mtproto->setStateChangedHandler([](MTP::ShiftedDcId dc, int32 state) {
|
|
|
|
if (dc == MTP::maindc()) {
|
|
|
|
Global::RefConnectionTypeChanged().notify();
|
2017-02-24 17:15:41 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
_mtproto->setSessionResetHandler([](MTP::ShiftedDcId shiftedDcId) {
|
|
|
|
if (App::main() && shiftedDcId == MTP::maindc()) {
|
|
|
|
App::main()->getDifference();
|
|
|
|
}
|
|
|
|
});
|
2017-02-25 16:44:02 +00:00
|
|
|
|
|
|
|
if (!_private->mtpKeysToDestroy.empty()) {
|
|
|
|
destroyMtpKeys(base::take(_private->mtpKeysToDestroy));
|
|
|
|
}
|
2017-04-06 19:02:40 +00:00
|
|
|
|
|
|
|
if (_private->authSessionUserId) {
|
2018-10-07 09:02:44 +00:00
|
|
|
QDataStream peekStream(_private->authSessionUserSerialized);
|
|
|
|
const auto phone = Serialize::peekUserPhone(
|
|
|
|
_private->authSessionUserStreamVersion,
|
|
|
|
peekStream);
|
|
|
|
const auto flags = MTPDuser::Flag::f_self | (phone.isEmpty()
|
|
|
|
? MTPDuser::Flag()
|
|
|
|
: MTPDuser::Flag::f_phone);
|
2018-09-11 12:50:40 +00:00
|
|
|
authSessionCreate(MTP_user(
|
2018-10-07 09:02:44 +00:00
|
|
|
MTP_flags(flags),
|
2018-09-11 12:50:40 +00:00
|
|
|
MTP_int(base::take(_private->authSessionUserId)),
|
|
|
|
MTPlong(), // access_hash
|
|
|
|
MTPstring(), // first_name
|
|
|
|
MTPstring(), // last_name
|
|
|
|
MTPstring(), // username
|
2018-10-07 09:02:44 +00:00
|
|
|
MTP_string(phone),
|
2018-09-11 12:50:40 +00:00
|
|
|
MTPUserProfilePhoto(),
|
|
|
|
MTPUserStatus(),
|
|
|
|
MTPint(), // bot_info_version
|
|
|
|
MTPstring(), // restriction_reason
|
|
|
|
MTPstring(), // bot_inline_placeholder
|
|
|
|
MTPstring())); // lang_code
|
2018-09-11 14:36:09 +00:00
|
|
|
Local::readSelf(
|
|
|
|
base::take(_private->authSessionUserSerialized),
|
|
|
|
base::take(_private->authSessionUserStreamVersion));
|
2017-04-06 19:02:40 +00:00
|
|
|
}
|
2017-04-09 18:06:06 +00:00
|
|
|
if (_private->storedAuthSession) {
|
2017-04-06 19:02:40 +00:00
|
|
|
if (_authSession) {
|
2018-01-04 10:22:53 +00:00
|
|
|
_authSession->settings().moveFrom(
|
2017-11-05 13:57:51 +00:00
|
|
|
std::move(*_private->storedAuthSession));
|
2017-04-06 19:02:40 +00:00
|
|
|
}
|
2017-04-09 18:06:06 +00:00
|
|
|
_private->storedAuthSession.reset();
|
2017-04-06 19:02:40 +00:00
|
|
|
}
|
2017-04-18 15:21:03 +00:00
|
|
|
|
2018-05-28 05:10:30 +00:00
|
|
|
_langCloudManager = std::make_unique<Lang::CloudManager>(
|
|
|
|
langpack(),
|
|
|
|
mtp());
|
2018-07-11 22:14:44 +00:00
|
|
|
if (!Core::UpdaterDisabled()) {
|
|
|
|
Core::UpdateChecker().setMtproto(mtp());
|
|
|
|
}
|
2018-09-11 14:36:09 +00:00
|
|
|
|
|
|
|
if (_authSession) {
|
|
|
|
// Skip all pending self updates so that we won't Local::writeSelf.
|
|
|
|
Notify::peerUpdatedSendDelayed();
|
|
|
|
}
|
2017-02-25 16:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::destroyMtpKeys(MTP::AuthKeysList &&keys) {
|
|
|
|
if (keys.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_mtprotoForKeysDestroy) {
|
|
|
|
_mtprotoForKeysDestroy->addKeysForDestroy(std::move(keys));
|
|
|
|
Local::writeMtpData();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto destroyConfig = MTP::Instance::Config();
|
|
|
|
destroyConfig.mainDcId = MTP::Instance::Config::kNoneMainDc;
|
|
|
|
destroyConfig.keys = std::move(keys);
|
|
|
|
_mtprotoForKeysDestroy = std::make_unique<MTP::Instance>(_dcOptions.get(), MTP::Instance::Mode::KeysDestroyer, std::move(destroyConfig));
|
|
|
|
connect(_mtprotoForKeysDestroy.get(), SIGNAL(allKeysDestroyed()), this, SLOT(onAllKeysDestroyed()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::onAllKeysDestroyed() {
|
|
|
|
LOG(("MTP Info: all keys scheduled for destroy are destroyed."));
|
|
|
|
_mtprotoForKeysDestroy.reset();
|
|
|
|
Local::writeMtpData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::suggestMainDcId(MTP::DcId mainDcId) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(_mtproto != nullptr);
|
2017-02-25 16:44:02 +00:00
|
|
|
|
|
|
|
_mtproto->suggestMainDcId(mainDcId);
|
|
|
|
if (_private->mtpConfig.mainDcId != MTP::Instance::Config::kNotSetMainDc) {
|
|
|
|
_private->mtpConfig.mainDcId = mainDcId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::destroyStaleAuthorizationKeys() {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(_mtproto != nullptr);
|
2017-02-25 16:44:02 +00:00
|
|
|
|
2018-06-04 18:18:52 +00:00
|
|
|
for (const auto &key : _mtproto->getKeysForWrite()) {
|
2017-02-25 17:15:30 +00:00
|
|
|
// Disable this for now.
|
2017-02-28 16:08:30 +00:00
|
|
|
if (key->type() == MTP::AuthKey::Type::ReadFromFile) {
|
2017-02-25 16:44:02 +00:00
|
|
|
_private->mtpKeysToDestroy = _mtproto->getKeysForWrite();
|
2018-06-04 18:18:52 +00:00
|
|
|
LOG(("MTP Info: destroying stale keys, count: %1"
|
|
|
|
).arg(_private->mtpKeysToDestroy.size()));
|
|
|
|
resetAuthorizationKeys();
|
2017-02-25 16:44:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-02-24 17:15:41 +00:00
|
|
|
}
|
|
|
|
|
2018-06-04 18:18:52 +00:00
|
|
|
void Messenger::resetAuthorizationKeys() {
|
|
|
|
_mtproto.reset();
|
|
|
|
startMtp();
|
|
|
|
Local::writeMtpData();
|
|
|
|
}
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void Messenger::startLocalStorage() {
|
|
|
|
_dcOptions = std::make_unique<MTP::DcOptions>();
|
|
|
|
_dcOptions->constructFromBuiltIn();
|
|
|
|
Local::start();
|
2017-02-24 17:15:41 +00:00
|
|
|
subscribe(_dcOptions->changed(), [this](const MTP::DcOptions::Ids &ids) {
|
2017-02-23 10:59:19 +00:00
|
|
|
Local::writeSettings();
|
2017-02-24 17:15:41 +00:00
|
|
|
if (auto instance = mtp()) {
|
|
|
|
for (auto id : ids) {
|
|
|
|
instance->restart(id);
|
|
|
|
}
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
});
|
2018-10-07 11:45:46 +00:00
|
|
|
subscribe(authSessionChanged(), [=] {
|
|
|
|
InvokeQueued(this, [=] {
|
2018-09-11 12:50:40 +00:00
|
|
|
const auto phone = AuthSession::Exists()
|
|
|
|
? Auth().user()->phone()
|
2018-05-02 19:27:03 +00:00
|
|
|
: QString();
|
|
|
|
if (cLoggedPhoneNumber() != phone) {
|
|
|
|
cSetLoggedPhoneNumber(phone);
|
|
|
|
if (_mtproto) {
|
|
|
|
_mtproto->setUserPhone(phone);
|
|
|
|
}
|
|
|
|
Local::writeSettings();
|
|
|
|
}
|
2018-09-11 12:50:40 +00:00
|
|
|
if (_mtproto) {
|
|
|
|
_mtproto->requestConfig();
|
|
|
|
}
|
2018-10-24 08:28:11 +00:00
|
|
|
Platform::SetApplicationIcon(Window::CreateIcon());
|
2018-05-02 19:27:03 +00:00
|
|
|
});
|
|
|
|
});
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 16:11:35 +00:00
|
|
|
void Messenger::killDownloadSessionsStart(MTP::DcId dcId) {
|
|
|
|
if (killDownloadSessionTimes.constFind(dcId) == killDownloadSessionTimes.cend()) {
|
|
|
|
killDownloadSessionTimes.insert(dcId, getms() + MTPAckSendWaiting + MTPKillFileSessionTimeout);
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
if (!killDownloadSessionsTimer.isActive()) {
|
|
|
|
killDownloadSessionsTimer.start(MTPAckSendWaiting + MTPKillFileSessionTimeout + 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-23 16:11:35 +00:00
|
|
|
void Messenger::killDownloadSessionsStop(MTP::DcId dcId) {
|
|
|
|
killDownloadSessionTimes.remove(dcId);
|
2017-02-23 10:59:19 +00:00
|
|
|
if (killDownloadSessionTimes.isEmpty() && killDownloadSessionsTimer.isActive()) {
|
|
|
|
killDownloadSessionsTimer.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-04 18:18:52 +00:00
|
|
|
void Messenger::forceLogOut(const TextWithEntities &explanation) {
|
|
|
|
const auto box = Ui::show(Box<InformBox>(
|
|
|
|
explanation,
|
|
|
|
lang(lng_passcode_logout)));
|
2018-06-06 11:51:27 +00:00
|
|
|
box->setCloseByEscape(false);
|
|
|
|
box->setCloseByOutsideClick(false);
|
2018-06-04 18:18:52 +00:00
|
|
|
connect(box, &QObject::destroyed, [=] {
|
2018-06-06 11:51:27 +00:00
|
|
|
crl::on_main(this, [=] {
|
|
|
|
if (AuthSession::Exists()) {
|
|
|
|
resetAuthorizationKeys();
|
|
|
|
loggedOut();
|
|
|
|
}
|
2018-06-04 18:18:52 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void Messenger::checkLocalTime() {
|
2018-08-08 20:11:28 +00:00
|
|
|
const auto updated = checkms();
|
|
|
|
if (App::main()) App::main()->checkLastUpdate(updated);
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::onAppStateChanged(Qt::ApplicationState state) {
|
|
|
|
if (state == Qt::ApplicationActive) {
|
|
|
|
handleAppActivated();
|
|
|
|
} else {
|
|
|
|
handleAppDeactivated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::handleAppActivated() {
|
|
|
|
checkLocalTime();
|
|
|
|
if (_window) {
|
|
|
|
_window->updateIsActive(Global::OnlineFocusTimeout());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::handleAppDeactivated() {
|
|
|
|
if (_window) {
|
|
|
|
_window->updateIsActive(Global::OfflineBlurTimeout());
|
|
|
|
}
|
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::call_handleUnreadCounterUpdate() {
|
|
|
|
Global::RefUnreadCounterUpdate().notify(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::call_handleDelayedPeerUpdates() {
|
|
|
|
Notify::peerUpdatedSendDelayed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::call_handleObservables() {
|
|
|
|
base::HandleObservables();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::killDownloadSessions() {
|
|
|
|
auto ms = getms(), left = static_cast<TimeMs>(MTPAckSendWaiting) + MTPKillFileSessionTimeout;
|
|
|
|
for (auto i = killDownloadSessionTimes.begin(); i != killDownloadSessionTimes.end(); ) {
|
|
|
|
if (i.value() <= ms) {
|
2017-03-23 16:11:35 +00:00
|
|
|
for (int j = 0; j < MTP::kDownloadSessionsCount; ++j) {
|
2017-02-25 16:44:02 +00:00
|
|
|
MTP::stopSession(MTP::downloadDcId(i.key(), j));
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
i = killDownloadSessionTimes.erase(i);
|
|
|
|
} else {
|
|
|
|
if (i.value() - ms < left) {
|
|
|
|
left = i.value() - ms;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!killDownloadSessionTimes.isEmpty()) {
|
|
|
|
killDownloadSessionsTimer.start(left);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::onSwitchDebugMode() {
|
2018-06-05 13:32:26 +00:00
|
|
|
if (Logs::DebugEnabled()) {
|
|
|
|
Logs::SetDebugEnabled(false);
|
2018-09-27 13:36:27 +00:00
|
|
|
Sandbox::WriteDebugModeSetting();
|
2017-02-23 10:59:19 +00:00
|
|
|
App::restart();
|
|
|
|
} else {
|
2018-06-05 13:32:26 +00:00
|
|
|
Logs::SetDebugEnabled(true);
|
2018-09-27 13:36:27 +00:00
|
|
|
Sandbox::WriteDebugModeSetting();
|
2017-02-23 10:59:19 +00:00
|
|
|
DEBUG_LOG(("Debug logs started."));
|
|
|
|
Ui::hideLayer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::onSwitchWorkMode() {
|
|
|
|
Global::SetDialogsModeEnabled(!Global::DialogsModeEnabled());
|
|
|
|
Global::SetDialogsMode(Dialogs::Mode::All);
|
|
|
|
Local::writeUserSettings();
|
|
|
|
App::restart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::onSwitchTestMode() {
|
|
|
|
if (cTestMode()) {
|
|
|
|
QFile(cWorkingDir() + qsl("tdata/withtestmode")).remove();
|
|
|
|
cSetTestMode(false);
|
|
|
|
} else {
|
|
|
|
QFile f(cWorkingDir() + qsl("tdata/withtestmode"));
|
|
|
|
if (f.open(QIODevice::WriteOnly)) {
|
|
|
|
f.write("1");
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
cSetTestMode(true);
|
|
|
|
}
|
|
|
|
App::restart();
|
|
|
|
}
|
|
|
|
|
2018-09-11 12:50:40 +00:00
|
|
|
void Messenger::authSessionCreate(const MTPUser &user) {
|
2017-04-06 19:02:40 +00:00
|
|
|
Expects(_mtproto != nullptr);
|
2018-06-03 13:30:40 +00:00
|
|
|
|
2018-09-11 12:50:40 +00:00
|
|
|
_authSession = std::make_unique<AuthSession>(user);
|
2017-04-09 18:06:06 +00:00
|
|
|
authSessionChanged().notify(true);
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::authSessionDestroy() {
|
2018-06-03 13:30:40 +00:00
|
|
|
unlockTerms();
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
_authSession.reset();
|
2017-04-09 18:06:06 +00:00
|
|
|
_private->storedAuthSession.reset();
|
2017-04-06 19:02:40 +00:00
|
|
|
_private->authSessionUserId = 0;
|
2018-09-11 12:50:40 +00:00
|
|
|
_private->authSessionUserSerialized = {};
|
2017-04-09 18:06:06 +00:00
|
|
|
authSessionChanged().notify(true);
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 17:25:43 +00:00
|
|
|
void Messenger::setInternalLinkDomain(const QString &domain) const {
|
|
|
|
// This domain should start with 'http[s]://' and end with '/', like 'https://t.me/'.
|
|
|
|
auto validate = [](auto &domain) {
|
|
|
|
auto prefixes = {
|
|
|
|
qstr("https://"),
|
|
|
|
qstr("http://"),
|
|
|
|
};
|
|
|
|
for (auto &prefix : prefixes) {
|
|
|
|
if (domain.startsWith(prefix, Qt::CaseInsensitive)) {
|
|
|
|
return domain.endsWith('/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
if (validate(domain) && domain != Global::InternalLinksDomain()) {
|
|
|
|
Global::SetInternalLinksDomain(domain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Messenger::createInternalLink(const QString &query) const {
|
|
|
|
auto result = createInternalLinkFull(query);
|
|
|
|
auto prefixes = {
|
|
|
|
qstr("https://"),
|
|
|
|
qstr("http://"),
|
|
|
|
};
|
|
|
|
for (auto &prefix : prefixes) {
|
|
|
|
if (result.startsWith(prefix, Qt::CaseInsensitive)) {
|
|
|
|
return result.mid(prefix.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG(("Warning: bad internal url '%1'").arg(result));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Messenger::createInternalLinkFull(const QString &query) const {
|
|
|
|
return Global::InternalLinksDomain() + query;
|
|
|
|
}
|
|
|
|
|
2017-06-27 20:11:38 +00:00
|
|
|
void Messenger::checkStartUrl() {
|
2018-06-03 13:30:40 +00:00
|
|
|
if (!cStartUrl().isEmpty() && !locked()) {
|
2017-06-27 20:11:38 +00:00
|
|
|
auto url = cStartUrl();
|
|
|
|
cSetStartUrl(QString());
|
2018-07-09 18:13:48 +00:00
|
|
|
if (!openLocalUrl(url, {})) {
|
2017-06-27 20:11:38 +00:00
|
|
|
cSetStartUrl(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-09 18:13:48 +00:00
|
|
|
bool Messenger::openLocalUrl(const QString &url, QVariant context) {
|
2017-06-27 20:11:38 +00:00
|
|
|
auto urlTrimmed = url.trimmed();
|
|
|
|
if (urlTrimmed.size() > 8192) urlTrimmed = urlTrimmed.mid(0, 8192);
|
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
const auto protocol = qstr("tg://");
|
|
|
|
if (!urlTrimmed.startsWith(protocol, Qt::CaseInsensitive) || locked()) {
|
2017-06-27 20:11:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-06-03 13:30:40 +00:00
|
|
|
auto command = urlTrimmed.midRef(protocol.size());
|
2017-06-27 20:11:38 +00:00
|
|
|
|
2018-04-06 18:47:29 +00:00
|
|
|
const auto showPassportForm = [](const QMap<QString, QString> ¶ms) {
|
2018-05-15 13:35:59 +00:00
|
|
|
const auto botId = params.value("bot_id", QString()).toInt();
|
|
|
|
const auto scope = params.value("scope", QString());
|
|
|
|
const auto callback = params.value("callback_url", QString());
|
|
|
|
const auto publicKey = params.value("public_key", QString());
|
2018-08-17 11:01:23 +00:00
|
|
|
const auto nonce = params.value(
|
|
|
|
Passport::NonceNameByScope(scope),
|
|
|
|
QString());
|
2018-05-15 13:35:59 +00:00
|
|
|
const auto errors = params.value("errors", QString());
|
|
|
|
if (const auto window = App::wnd()) {
|
|
|
|
if (const auto controller = window->controller()) {
|
|
|
|
controller->showPassportForm(Passport::FormRequest(
|
|
|
|
botId,
|
|
|
|
scope,
|
|
|
|
callback,
|
|
|
|
publicKey,
|
2018-08-17 11:01:23 +00:00
|
|
|
nonce,
|
2018-05-15 13:35:59 +00:00
|
|
|
errors));
|
|
|
|
return true;
|
2018-04-06 18:47:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2017-06-27 20:11:38 +00:00
|
|
|
using namespace qthelp;
|
|
|
|
auto matchOptions = RegExOption::CaseInsensitive;
|
|
|
|
if (auto joinChatMatch = regex_match(qsl("^join/?\\?invite=([a-zA-Z0-9\\.\\_\\-]+)(&|$)"), command, matchOptions)) {
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
main->joinGroupByHash(joinChatMatch->captured(1));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (auto stickerSetMatch = regex_match(qsl("^addstickers/?\\?set=([a-zA-Z0-9\\.\\_]+)(&|$)"), command, matchOptions)) {
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
main->stickersBox(MTP_inputStickerSetShortName(MTP_string(stickerSetMatch->captured(1))));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (auto shareUrlMatch = regex_match(qsl("^msg_url/?\\?(.+)(#|$)"), command, matchOptions)) {
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
auto params = url_parse_params(shareUrlMatch->captured(1), UrlParamNameTransform::ToLower);
|
|
|
|
auto url = params.value(qsl("url"));
|
|
|
|
if (!url.isEmpty()) {
|
|
|
|
main->shareUrlLayer(url, params.value("text"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (auto confirmPhoneMatch = regex_match(qsl("^confirmphone/?\\?(.+)(#|$)"), command, matchOptions)) {
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
auto params = url_parse_params(confirmPhoneMatch->captured(1), UrlParamNameTransform::ToLower);
|
|
|
|
auto phone = params.value(qsl("phone"));
|
|
|
|
auto hash = params.value(qsl("hash"));
|
|
|
|
if (!phone.isEmpty() && !hash.isEmpty()) {
|
|
|
|
ConfirmPhoneBox::start(phone, hash);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (auto usernameMatch = regex_match(qsl("^resolve/?\\?(.+)(#|$)"), command, matchOptions)) {
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
auto params = url_parse_params(usernameMatch->captured(1), UrlParamNameTransform::ToLower);
|
|
|
|
auto domain = params.value(qsl("domain"));
|
2018-04-06 18:47:29 +00:00
|
|
|
if (domain == qsl("telegrampassport")) {
|
|
|
|
return showPassportForm(params);
|
|
|
|
} else if (regex_match(qsl("^[a-zA-Z0-9\\.\\_]+$"), domain, matchOptions)) {
|
2017-06-27 20:11:38 +00:00
|
|
|
auto start = qsl("start");
|
|
|
|
auto startToken = params.value(start);
|
|
|
|
if (startToken.isEmpty()) {
|
|
|
|
start = qsl("startgroup");
|
|
|
|
startToken = params.value(start);
|
|
|
|
if (startToken.isEmpty()) {
|
|
|
|
start = QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto post = (start == qsl("startgroup")) ? ShowAtProfileMsgId : ShowAtUnreadMsgId;
|
|
|
|
auto postParam = params.value(qsl("post"));
|
|
|
|
if (auto postId = postParam.toInt()) {
|
|
|
|
post = postId;
|
|
|
|
}
|
|
|
|
auto gameParam = params.value(qsl("game"));
|
|
|
|
if (!gameParam.isEmpty() && regex_match(qsl("^[a-zA-Z0-9\\.\\_]+$"), gameParam, matchOptions)) {
|
|
|
|
startToken = gameParam;
|
|
|
|
post = ShowAtGameShareMsgId;
|
|
|
|
}
|
2018-07-09 18:13:48 +00:00
|
|
|
const auto clickFromMessageId = context.value<FullMsgId>();
|
|
|
|
main->openPeerByName(
|
|
|
|
domain,
|
|
|
|
post,
|
|
|
|
startToken,
|
|
|
|
clickFromMessageId);
|
2017-06-27 20:11:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (auto shareGameScoreMatch = regex_match(qsl("^share_game_score/?\\?(.+)(#|$)"), command, matchOptions)) {
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
auto params = url_parse_params(shareGameScoreMatch->captured(1), UrlParamNameTransform::ToLower);
|
|
|
|
ShareGameScoreByHash(params.value(qsl("hash")));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (auto socksMatch = regex_match(qsl("^socks/?\\?(.+)(#|$)"), command, matchOptions)) {
|
|
|
|
auto params = url_parse_params(socksMatch->captured(1), UrlParamNameTransform::ToLower);
|
2018-05-11 14:03:53 +00:00
|
|
|
ProxiesBoxController::ShowApplyConfirmation(ProxyData::Type::Socks5, params);
|
2018-04-27 16:16:50 +00:00
|
|
|
return true;
|
|
|
|
} else if (auto proxyMatch = regex_match(qsl("^proxy/?\\?(.+)(#|$)"), command, matchOptions)) {
|
|
|
|
auto params = url_parse_params(proxyMatch->captured(1), UrlParamNameTransform::ToLower);
|
2018-05-11 14:03:53 +00:00
|
|
|
ProxiesBoxController::ShowApplyConfirmation(ProxyData::Type::Mtproto, params);
|
2017-06-27 20:11:38 +00:00
|
|
|
return true;
|
2018-04-06 18:47:29 +00:00
|
|
|
} else if (auto authMatch = regex_match(qsl("^passport/?\\?(.+)(#|$)"), command, matchOptions)) {
|
|
|
|
return showPassportForm(url_parse_params(
|
2018-03-18 08:51:14 +00:00
|
|
|
authMatch->captured(1),
|
2018-04-06 18:47:29 +00:00
|
|
|
UrlParamNameTransform::ToLower));
|
2018-04-18 15:42:02 +00:00
|
|
|
} else if (auto unknownMatch = regex_match(qsl("^([^\\?]+)(\\?|#|$)"), command, matchOptions)) {
|
|
|
|
if (_authSession) {
|
|
|
|
const auto request = unknownMatch->captured(1);
|
|
|
|
const auto callback = [=](const MTPDhelp_deepLinkInfo &result) {
|
|
|
|
const auto text = TextWithEntities{
|
|
|
|
qs(result.vmessage),
|
|
|
|
(result.has_entities()
|
|
|
|
? TextUtilities::EntitiesFromMTP(result.ventities.v)
|
|
|
|
: EntitiesInText())
|
|
|
|
};
|
|
|
|
if (result.is_update_app()) {
|
|
|
|
const auto box = std::make_shared<QPointer<BoxContent>>();
|
2018-08-03 21:48:00 +00:00
|
|
|
const auto callback = [=] {
|
|
|
|
Core::UpdateApplication();
|
|
|
|
if (*box) (*box)->closeBox();
|
|
|
|
};
|
2018-04-18 15:42:02 +00:00
|
|
|
*box = Ui::show(Box<ConfirmBox>(
|
|
|
|
text,
|
|
|
|
lang(lng_menu_update),
|
2018-08-03 21:48:00 +00:00
|
|
|
callback));
|
2018-04-18 15:42:02 +00:00
|
|
|
} else {
|
|
|
|
Ui::show(Box<InformBox>(text));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
_authSession->api().requestDeepLinkInfo(request, callback);
|
|
|
|
}
|
2017-06-27 20:11:38 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
void Messenger::lockByPasscode() {
|
|
|
|
_passcodeLock = true;
|
|
|
|
_window->setupPasscodeLock();
|
2017-04-15 18:48:54 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
void Messenger::unlockPasscode() {
|
2018-06-07 07:44:38 +00:00
|
|
|
clearPasscodeLock();
|
2018-06-03 13:30:40 +00:00
|
|
|
_window->clearPasscodeLock();
|
2018-06-07 07:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::clearPasscodeLock() {
|
|
|
|
cSetPasscodeBadTries(0);
|
2018-06-03 13:30:40 +00:00
|
|
|
_passcodeLock = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Messenger::passcodeLocked() const {
|
|
|
|
return _passcodeLock.current();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> Messenger::passcodeLockChanges() const {
|
|
|
|
return _passcodeLock.changes();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> Messenger::passcodeLockValue() const {
|
|
|
|
return _passcodeLock.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::lockByTerms(const Window::TermsLock &data) {
|
|
|
|
if (!_termsLock || *_termsLock != data) {
|
|
|
|
_termsLock = std::make_unique<Window::TermsLock>(data);
|
|
|
|
_termsLockChanges.fire(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::unlockTerms() {
|
|
|
|
if (_termsLock) {
|
|
|
|
_termsLock = nullptr;
|
|
|
|
_termsLockChanges.fire(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<Window::TermsLock> Messenger::termsLocked() const {
|
|
|
|
return _termsLock ? base::make_optional(*_termsLock) : std::nullopt;
|
2018-06-03 13:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> Messenger::termsLockChanges() const {
|
|
|
|
return _termsLockChanges.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> Messenger::termsLockValue() const {
|
|
|
|
return rpl::single(
|
|
|
|
_termsLock != nullptr
|
|
|
|
) | rpl::then(termsLockChanges());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::termsDeleteNow() {
|
|
|
|
MTP::send(MTPaccount_DeleteAccount(MTP_string("Decline ToS update")));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Messenger::locked() const {
|
|
|
|
return passcodeLocked() || termsLocked();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> Messenger::lockChanges() const {
|
|
|
|
return lockValue() | rpl::skip(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> Messenger::lockValue() const {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
return rpl::combine(
|
|
|
|
passcodeLockValue(),
|
|
|
|
termsLockValue(),
|
|
|
|
_1 || _2);
|
2017-04-15 18:48:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-03 11:36:39 +00:00
|
|
|
Messenger::~Messenger() {
|
|
|
|
Expects(SingleInstance == this);
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
_window.reset();
|
2017-08-08 09:31:48 +00:00
|
|
|
_mediaView.reset();
|
2017-02-25 16:44:02 +00:00
|
|
|
|
|
|
|
// Some MTP requests can be cancelled from data clearing.
|
|
|
|
App::clearHistories();
|
2017-03-04 19:36:59 +00:00
|
|
|
authSessionDestroy();
|
2017-02-25 16:44:02 +00:00
|
|
|
|
2017-05-30 09:31:40 +00:00
|
|
|
// The langpack manager should be destroyed before MTProto instance,
|
|
|
|
// because it is MTP::Sender and it may have pending requests.
|
|
|
|
_langCloudManager.reset();
|
|
|
|
|
2017-02-24 17:15:41 +00:00
|
|
|
_mtproto.reset();
|
2017-02-25 16:44:02 +00:00
|
|
|
_mtprotoForKeysDestroy.reset();
|
2017-02-23 10:59:19 +00:00
|
|
|
|
|
|
|
Shortcuts::finish();
|
|
|
|
|
2018-10-13 17:35:30 +00:00
|
|
|
Ui::Emoji::Clear();
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
anim::stopManager();
|
|
|
|
|
|
|
|
stopWebLoadManager();
|
|
|
|
App::deinitMedia();
|
|
|
|
|
|
|
|
Window::Theme::Unload();
|
|
|
|
|
|
|
|
Media::Player::finish();
|
|
|
|
style::stopManager();
|
|
|
|
|
|
|
|
Local::finish();
|
|
|
|
Global::finish();
|
|
|
|
ThirdParty::finish();
|
2017-05-03 11:36:39 +00:00
|
|
|
|
|
|
|
SingleInstance = nullptr;
|
2017-02-23 10:59:19 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 09:56:10 +00:00
|
|
|
MainWindow *Messenger::getActiveWindow() const {
|
2017-02-23 10:59:19 +00:00
|
|
|
return _window.get();
|
|
|
|
}
|
2017-04-19 20:25:48 +00:00
|
|
|
|
2017-08-08 09:56:10 +00:00
|
|
|
bool Messenger::closeActiveWindow() {
|
|
|
|
if (hideMediaView()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (auto activeWindow = getActiveWindow()) {
|
|
|
|
if (!activeWindow->hideNoQuit()) {
|
|
|
|
activeWindow->close();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Messenger::minimizeActiveWindow() {
|
|
|
|
hideMediaView();
|
|
|
|
if (auto activeWindow = getActiveWindow()) {
|
|
|
|
if (Global::WorkMode().value() == dbiwmTrayOnly) {
|
|
|
|
activeWindow->minimizeToTray();
|
|
|
|
} else {
|
|
|
|
activeWindow->setWindowState(Qt::WindowMinimized);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
QWidget *Messenger::getFileDialogParent() {
|
|
|
|
return (_mediaView && _mediaView->isVisible()) ? (QWidget*)_mediaView.get() : (QWidget*)getActiveWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::checkMediaViewActivation() {
|
|
|
|
if (_mediaView && !_mediaView->isHidden()) {
|
|
|
|
_mediaView->activateWindow();
|
|
|
|
Sandbox::setActiveWindow(_mediaView.get());
|
|
|
|
_mediaView->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-04 18:18:52 +00:00
|
|
|
void Messenger::logOut() {
|
|
|
|
if (_mtproto) {
|
|
|
|
_mtproto->logout(::rpcDone([=] {
|
|
|
|
loggedOut();
|
|
|
|
}), ::rpcFail([=] {
|
|
|
|
loggedOut();
|
|
|
|
return true;
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
// We log out because we've forgotten passcode.
|
|
|
|
// So we just start mtproto from scratch.
|
|
|
|
startMtp();
|
|
|
|
loggedOut();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
void Messenger::loggedOut() {
|
2018-06-04 18:18:52 +00:00
|
|
|
if (Global::LocalPasscode()) {
|
|
|
|
Global::SetLocalPasscode(false);
|
|
|
|
Global::RefLocalPasscodeChanged().notify();
|
|
|
|
}
|
2018-06-07 07:44:38 +00:00
|
|
|
clearPasscodeLock();
|
2018-06-04 18:18:52 +00:00
|
|
|
Media::Player::mixer()->stopAndClear();
|
|
|
|
if (const auto w = getActiveWindow()) {
|
|
|
|
w->tempDirDelete(Local::ClearManagerAll);
|
|
|
|
w->setupIntro();
|
|
|
|
}
|
|
|
|
App::histories().clear();
|
2018-08-27 11:35:58 +00:00
|
|
|
if (const auto session = authSession()) {
|
|
|
|
session->data().cache().close();
|
|
|
|
session->data().cache().clear();
|
|
|
|
}
|
2018-06-04 18:18:52 +00:00
|
|
|
authSessionDestroy();
|
2017-08-08 09:31:48 +00:00
|
|
|
if (_mediaView) {
|
|
|
|
hideMediaView();
|
|
|
|
_mediaView->clearData();
|
|
|
|
}
|
2018-06-04 18:18:52 +00:00
|
|
|
Local::reset();
|
|
|
|
|
|
|
|
cSetOtherOnline(0);
|
2018-10-11 15:54:57 +00:00
|
|
|
Images::ClearRemote();
|
2017-08-08 09:31:48 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 20:25:48 +00:00
|
|
|
QPoint Messenger::getPointForCallPanelCenter() const {
|
2017-08-08 09:56:10 +00:00
|
|
|
if (auto activeWindow = getActiveWindow()) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(activeWindow->windowHandle() != nullptr);
|
2017-08-08 09:56:10 +00:00
|
|
|
if (activeWindow->isActive()) {
|
|
|
|
return activeWindow->geometry().center();
|
|
|
|
}
|
|
|
|
return activeWindow->windowHandle()->screen()->geometry().center();
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
2017-08-08 09:56:10 +00:00
|
|
|
return QApplication::desktop()->screenGeometry().center();
|
2017-04-19 20:25:48 +00:00
|
|
|
}
|
2017-04-29 20:06:32 +00:00
|
|
|
|
2017-11-21 10:27:37 +00:00
|
|
|
// macOS Qt bug workaround, sometimes no leaveEvent() gets to the nested widgets.
|
|
|
|
void Messenger::registerLeaveSubscription(QWidget *widget) {
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
if (auto topLevel = widget->window()) {
|
|
|
|
if (topLevel == _window.get()) {
|
2017-11-30 18:04:13 +00:00
|
|
|
auto weak = make_weak(widget);
|
2017-12-22 07:05:20 +00:00
|
|
|
auto subscription = _window->leaveEvents(
|
|
|
|
) | rpl::start_with_next([weak] {
|
|
|
|
if (const auto window = weak.data()) {
|
|
|
|
QEvent ev(QEvent::Leave);
|
|
|
|
QGuiApplication::sendEvent(window, &ev);
|
|
|
|
}
|
|
|
|
});
|
2017-11-30 18:04:13 +00:00
|
|
|
_leaveSubscriptions.emplace_back(weak, std::move(subscription));
|
2017-11-21 10:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // Q_OS_MAC
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::unregisterLeaveSubscription(QWidget *widget) {
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
_leaveSubscriptions = std::move(
|
|
|
|
_leaveSubscriptions
|
|
|
|
) | ranges::action::remove_if([&](const LeaveSubscription &subscription) {
|
|
|
|
auto pointer = subscription.pointer.data();
|
|
|
|
return !pointer || (pointer == widget);
|
|
|
|
});
|
|
|
|
#endif // Q_OS_MAC
|
|
|
|
}
|
|
|
|
|
2017-04-29 20:06:32 +00:00
|
|
|
void Messenger::QuitAttempt() {
|
|
|
|
auto prevents = false;
|
|
|
|
if (!Sandbox::isSavingSession() && AuthSession::Exists()) {
|
2017-08-04 14:54:32 +00:00
|
|
|
if (Auth().api().isQuitPrevent()) {
|
2017-04-29 20:06:32 +00:00
|
|
|
prevents = true;
|
|
|
|
}
|
2017-08-04 14:54:32 +00:00
|
|
|
if (Auth().calls().isQuitPrevent()) {
|
2017-04-29 20:06:32 +00:00
|
|
|
prevents = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (prevents) {
|
|
|
|
Instance().quitDelayed();
|
|
|
|
} else {
|
|
|
|
QCoreApplication::quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::quitPreventFinished() {
|
|
|
|
if (App::quitting()) {
|
|
|
|
QuitAttempt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Messenger::quitDelayed() {
|
|
|
|
if (!_private->quitTimer.isActive()) {
|
|
|
|
_private->quitTimer.setCallback([] { QCoreApplication::quit(); });
|
|
|
|
_private->quitTimer.callOnce(kQuitPreventTimeoutMs);
|
|
|
|
}
|
|
|
|
}
|