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
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "base/observer.h"
|
2017-06-26 17:38:16 +00:00
|
|
|
#include "mtproto/auth_key.h"
|
2017-08-03 13:06:29 +00:00
|
|
|
#include "base/timer.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
class AuthSession;
|
2018-01-04 10:22:53 +00:00
|
|
|
class AuthSessionSettings;
|
2017-12-11 14:45:29 +00:00
|
|
|
class MainWidget;
|
|
|
|
class FileUploader;
|
|
|
|
class Translator;
|
|
|
|
class MediaView;
|
2018-05-24 13:40:19 +00:00
|
|
|
class BoxContent;
|
2017-12-11 14:45:29 +00:00
|
|
|
|
2018-08-29 13:23:16 +00:00
|
|
|
namespace Storage {
|
|
|
|
class Databases;
|
|
|
|
} // namespace Storage
|
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
namespace Core {
|
|
|
|
class Launcher;
|
2018-11-29 12:52:00 +00:00
|
|
|
struct LocalUrlHandler;
|
2017-12-11 14:45:29 +00:00
|
|
|
} // namespace Core
|
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
namespace Window {
|
|
|
|
struct TermsLock;
|
|
|
|
} // namespace Window
|
|
|
|
|
2017-04-29 20:06:32 +00:00
|
|
|
namespace App {
|
|
|
|
void quit();
|
|
|
|
} // namespace App
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
namespace MTP {
|
|
|
|
class DcOptions;
|
2017-02-24 17:15:41 +00:00
|
|
|
class Instance;
|
2017-06-26 17:38:16 +00:00
|
|
|
class AuthKey;
|
|
|
|
using AuthKeyPtr = std::shared_ptr<AuthKey>;
|
|
|
|
using AuthKeysList = std::vector<AuthKeyPtr>;
|
2017-02-23 10:59:19 +00:00
|
|
|
} // namespace MTP
|
|
|
|
|
2017-05-03 11:36:39 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace Audio {
|
|
|
|
class Instance;
|
|
|
|
} // namespace Audio
|
|
|
|
} // namespace Media
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
namespace Lang {
|
2017-04-13 17:59:05 +00:00
|
|
|
class Instance;
|
2017-04-13 08:45:58 +00:00
|
|
|
class Translator;
|
2017-04-18 15:21:03 +00:00
|
|
|
class CloudManager;
|
2017-04-13 08:45:58 +00:00
|
|
|
} // namespace Lang
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
class Messenger final : public QObject, public RPCSender, private base::Subscriber {
|
2017-02-23 10:59:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-12-11 14:45:29 +00:00
|
|
|
Messenger(not_null<Core::Launcher*> launcher);
|
2017-02-23 10:59:19 +00:00
|
|
|
|
|
|
|
Messenger(const Messenger &other) = delete;
|
|
|
|
Messenger &operator=(const Messenger &other) = delete;
|
|
|
|
|
|
|
|
~Messenger();
|
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
not_null<Core::Launcher*> launcher() const {
|
|
|
|
return _launcher;
|
|
|
|
}
|
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
// Windows interface.
|
2017-08-08 09:56:10 +00:00
|
|
|
MainWindow *getActiveWindow() const;
|
|
|
|
bool closeActiveWindow();
|
|
|
|
bool minimizeActiveWindow();
|
2017-08-08 09:31:48 +00:00
|
|
|
QWidget *getFileDialogParent();
|
|
|
|
QWidget *getGlobalShortcutParent() {
|
|
|
|
return &_globalShortcutParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// MediaView interface.
|
|
|
|
void checkMediaViewActivation();
|
|
|
|
bool hideMediaView();
|
2017-12-15 16:25:47 +00:00
|
|
|
void showPhoto(not_null<const PhotoOpenClickHandler*> link);
|
2017-08-17 08:31:24 +00:00
|
|
|
void showPhoto(not_null<PhotoData*> photo, HistoryItem *item);
|
2017-12-15 16:25:47 +00:00
|
|
|
void showPhoto(not_null<PhotoData*> photo, not_null<PeerData*> item);
|
2017-08-17 08:31:24 +00:00
|
|
|
void showDocument(not_null<DocumentData*> document, HistoryItem *item);
|
2017-08-08 09:31:48 +00:00
|
|
|
PeerData *ui_getPeerForMouseAction();
|
|
|
|
|
2017-04-19 20:25:48 +00:00
|
|
|
QPoint getPointForCallPanelCenter() const;
|
2017-05-12 15:27:19 +00:00
|
|
|
QImage logo() const {
|
|
|
|
return _logo;
|
|
|
|
}
|
|
|
|
QImage logoNoMargin() const {
|
|
|
|
return _logoNoMargin;
|
|
|
|
}
|
2017-02-23 10:59:19 +00:00
|
|
|
|
|
|
|
static Messenger *InstancePointer();
|
|
|
|
static Messenger &Instance() {
|
|
|
|
auto result = InstancePointer();
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(result != nullptr);
|
2017-02-23 10:59:19 +00:00
|
|
|
return *result;
|
|
|
|
}
|
|
|
|
|
2017-05-03 11:36:39 +00:00
|
|
|
// MTProto components.
|
2017-02-23 10:59:19 +00:00
|
|
|
MTP::DcOptions *dcOptions() {
|
|
|
|
return _dcOptions.get();
|
|
|
|
}
|
2018-11-05 13:58:24 +00:00
|
|
|
void setCurrentProxy(
|
|
|
|
const ProxyData &proxy,
|
|
|
|
ProxyData::Settings settings);
|
2018-05-24 13:40:19 +00:00
|
|
|
void badMtprotoConfigurationError();
|
2017-02-24 17:15:41 +00:00
|
|
|
|
2017-04-06 19:02:40 +00:00
|
|
|
// Set from legacy storage.
|
2017-02-24 17:15:41 +00:00
|
|
|
void setMtpMainDcId(MTP::DcId mainDcId);
|
|
|
|
void setMtpKey(MTP::DcId dcId, const MTP::AuthKey::Data &keyData);
|
2017-04-06 19:02:40 +00:00
|
|
|
void setAuthSessionUserId(UserId userId);
|
2018-01-04 10:22:53 +00:00
|
|
|
void setAuthSessionFromStorage(
|
2018-09-11 14:36:09 +00:00
|
|
|
std::unique_ptr<AuthSessionSettings> data,
|
|
|
|
QByteArray &&selfSerialized,
|
|
|
|
int32 selfStreamVersion);
|
2018-01-04 10:22:53 +00:00
|
|
|
AuthSessionSettings *getAuthSessionSettings();
|
2017-04-06 19:02:40 +00:00
|
|
|
|
|
|
|
// Serialization.
|
2017-02-24 17:15:41 +00:00
|
|
|
QByteArray serializeMtpAuthorization() const;
|
|
|
|
void setMtpAuthorization(const QByteArray &serialized);
|
2017-04-06 19:02:40 +00:00
|
|
|
|
2017-02-24 17:15:41 +00:00
|
|
|
void startMtp();
|
|
|
|
MTP::Instance *mtp() {
|
|
|
|
return _mtproto.get();
|
|
|
|
}
|
2017-02-25 16:44:02 +00:00
|
|
|
void suggestMainDcId(MTP::DcId mainDcId);
|
|
|
|
void destroyStaleAuthorizationKeys();
|
2017-02-24 17:15:41 +00:00
|
|
|
|
2018-08-29 13:23:16 +00:00
|
|
|
// Databases
|
|
|
|
Storage::Databases &databases() {
|
|
|
|
return *_databases;
|
|
|
|
}
|
|
|
|
|
2017-05-03 11:36:39 +00:00
|
|
|
// AuthSession component.
|
2017-02-23 10:59:19 +00:00
|
|
|
AuthSession *authSession() {
|
|
|
|
return _authSession.get();
|
|
|
|
}
|
2017-04-13 17:59:05 +00:00
|
|
|
Lang::Instance &langpack() {
|
|
|
|
return *_langpack;
|
|
|
|
}
|
2017-04-18 15:21:03 +00:00
|
|
|
Lang::CloudManager *langCloudManager() {
|
|
|
|
return _langCloudManager.get();
|
|
|
|
}
|
2018-09-11 12:50:40 +00:00
|
|
|
void authSessionCreate(const MTPUser &user);
|
2017-03-04 19:36:59 +00:00
|
|
|
base::Observable<void> &authSessionChanged() {
|
|
|
|
return _authSessionChanged;
|
|
|
|
}
|
2018-12-04 10:32:06 +00:00
|
|
|
int unreadBadge() const;
|
|
|
|
bool unreadBadgeMuted() const;
|
2018-06-04 18:18:52 +00:00
|
|
|
void logOut();
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2017-05-03 11:36:39 +00:00
|
|
|
// Media component.
|
|
|
|
Media::Audio::Instance &audio() {
|
|
|
|
return *_audio;
|
|
|
|
}
|
|
|
|
|
2017-06-27 20:11:38 +00:00
|
|
|
// Internal links.
|
2017-03-10 17:25:43 +00:00
|
|
|
void setInternalLinkDomain(const QString &domain) const;
|
|
|
|
QString createInternalLink(const QString &query) const;
|
|
|
|
QString createInternalLinkFull(const QString &query) const;
|
2017-06-27 20:11:38 +00:00
|
|
|
void checkStartUrl();
|
2018-07-09 18:13:48 +00:00
|
|
|
bool openLocalUrl(const QString &url, QVariant context);
|
2017-03-10 17:25:43 +00:00
|
|
|
|
2017-03-23 16:11:35 +00:00
|
|
|
void killDownloadSessionsStart(MTP::DcId dcId);
|
|
|
|
void killDownloadSessionsStop(MTP::DcId dcId);
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2018-06-04 18:18:52 +00:00
|
|
|
void forceLogOut(const TextWithEntities &explanation);
|
2017-02-23 10:59:19 +00:00
|
|
|
void checkLocalTime();
|
2018-06-03 13:30:40 +00:00
|
|
|
void lockByPasscode();
|
|
|
|
void unlockPasscode();
|
|
|
|
[[nodiscard]] bool passcodeLocked() const;
|
|
|
|
rpl::producer<bool> passcodeLockChanges() const;
|
|
|
|
rpl::producer<bool> passcodeLockValue() const;
|
|
|
|
|
|
|
|
void lockByTerms(const Window::TermsLock &data);
|
|
|
|
void unlockTerms();
|
2018-09-21 16:28:46 +00:00
|
|
|
[[nodiscard]] std::optional<Window::TermsLock> termsLocked() const;
|
2018-06-03 13:30:40 +00:00
|
|
|
rpl::producer<bool> termsLockChanges() const;
|
|
|
|
rpl::producer<bool> termsLockValue() const;
|
|
|
|
void termsDeleteNow();
|
|
|
|
|
|
|
|
[[nodiscard]] bool locked() const;
|
|
|
|
rpl::producer<bool> lockChanges() const;
|
|
|
|
rpl::producer<bool> lockValue() const;
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2017-11-21 10:27:37 +00:00
|
|
|
void registerLeaveSubscription(QWidget *widget);
|
|
|
|
void unregisterLeaveSubscription(QWidget *widget);
|
|
|
|
|
2017-04-29 20:06:32 +00:00
|
|
|
void quitPreventFinished();
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void handleAppActivated();
|
|
|
|
void handleAppDeactivated();
|
|
|
|
|
2017-04-06 16:49:42 +00:00
|
|
|
void call_handleUnreadCounterUpdate();
|
|
|
|
void call_handleDelayedPeerUpdates();
|
|
|
|
void call_handleObservables();
|
2017-02-25 16:44:02 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void callDelayed(int duration, FnMut<void()> &&lambda) {
|
2017-08-03 13:06:29 +00:00
|
|
|
_callDelayedTimer.call(duration, std::move(lambda));
|
|
|
|
}
|
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
protected:
|
|
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
public slots:
|
2017-02-25 16:44:02 +00:00
|
|
|
void onAllKeysDestroyed();
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void onSwitchDebugMode();
|
|
|
|
void onSwitchWorkMode();
|
|
|
|
void onSwitchTestMode();
|
|
|
|
|
|
|
|
void killDownloadSessions();
|
|
|
|
void onAppStateChanged(Qt::ApplicationState state);
|
|
|
|
|
|
|
|
private:
|
2017-02-25 16:44:02 +00:00
|
|
|
void destroyMtpKeys(MTP::AuthKeysList &&keys);
|
2017-02-23 10:59:19 +00:00
|
|
|
void startLocalStorage();
|
2018-11-16 12:15:14 +00:00
|
|
|
void startShortcuts();
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2017-04-29 20:06:32 +00:00
|
|
|
friend void App::quit();
|
|
|
|
static void QuitAttempt();
|
|
|
|
void quitDelayed();
|
|
|
|
|
2018-06-04 18:18:52 +00:00
|
|
|
void resetAuthorizationKeys();
|
|
|
|
void authSessionDestroy();
|
2018-06-07 07:44:38 +00:00
|
|
|
void clearPasscodeLock();
|
2017-08-08 09:31:48 +00:00
|
|
|
void loggedOut();
|
|
|
|
|
2018-11-26 11:55:02 +00:00
|
|
|
void fillLocalUrlHandlers();
|
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
not_null<Core::Launcher*> _launcher;
|
|
|
|
|
2017-03-23 16:11:35 +00:00
|
|
|
QMap<MTP::DcId, TimeMs> killDownloadSessionTimes;
|
2017-02-23 10:59:19 +00:00
|
|
|
SingleTimer killDownloadSessionsTimer;
|
|
|
|
|
2017-02-24 17:15:41 +00:00
|
|
|
// Some fields are just moved from the declaration.
|
|
|
|
struct Private;
|
|
|
|
const std::unique_ptr<Private> _private;
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
QWidget _globalShortcutParent;
|
|
|
|
|
2018-08-29 13:23:16 +00:00
|
|
|
std::unique_ptr<Storage::Databases> _databases;
|
2017-02-23 10:59:19 +00:00
|
|
|
std::unique_ptr<MainWindow> _window;
|
2017-08-08 09:31:48 +00:00
|
|
|
std::unique_ptr<MediaView> _mediaView;
|
2017-04-13 17:59:05 +00:00
|
|
|
std::unique_ptr<Lang::Instance> _langpack;
|
2017-04-18 15:21:03 +00:00
|
|
|
std::unique_ptr<Lang::CloudManager> _langCloudManager;
|
2017-04-13 08:45:58 +00:00
|
|
|
std::unique_ptr<Lang::Translator> _translator;
|
2017-02-23 10:59:19 +00:00
|
|
|
std::unique_ptr<MTP::DcOptions> _dcOptions;
|
2017-02-24 17:15:41 +00:00
|
|
|
std::unique_ptr<MTP::Instance> _mtproto;
|
2017-02-25 16:44:02 +00:00
|
|
|
std::unique_ptr<MTP::Instance> _mtprotoForKeysDestroy;
|
2017-02-23 10:59:19 +00:00
|
|
|
std::unique_ptr<AuthSession> _authSession;
|
2017-03-04 19:36:59 +00:00
|
|
|
base::Observable<void> _authSessionChanged;
|
2017-04-15 18:48:54 +00:00
|
|
|
base::Observable<void> _passcodedChanged;
|
2018-05-24 13:40:19 +00:00
|
|
|
QPointer<BoxContent> _badProxyDisableBox;
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2017-05-03 11:36:39 +00:00
|
|
|
std::unique_ptr<Media::Audio::Instance> _audio;
|
2017-05-12 15:27:19 +00:00
|
|
|
QImage _logo;
|
|
|
|
QImage _logoNoMargin;
|
2017-05-03 11:36:39 +00:00
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
rpl::variable<bool> _passcodeLock;
|
|
|
|
rpl::event_stream<bool> _termsLockChanges;
|
|
|
|
std::unique_ptr<Window::TermsLock> _termsLock;
|
|
|
|
|
2017-08-03 13:06:29 +00:00
|
|
|
base::DelayedCallTimer _callDelayedTimer;
|
|
|
|
|
2017-11-21 10:27:37 +00:00
|
|
|
struct LeaveSubscription {
|
2017-12-22 07:05:20 +00:00
|
|
|
LeaveSubscription(
|
|
|
|
QPointer<QWidget> pointer,
|
|
|
|
rpl::lifetime &&subscription)
|
2017-11-21 10:27:37 +00:00
|
|
|
: pointer(pointer), subscription(std::move(subscription)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointer<QWidget> pointer;
|
|
|
|
rpl::lifetime subscription;
|
|
|
|
};
|
|
|
|
std::vector<LeaveSubscription> _leaveSubscriptions;
|
|
|
|
|
2018-11-16 12:15:14 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
};
|