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;
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
class Launcher;
|
|
|
|
} // namespace Core
|
|
|
|
|
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();
|
|
|
|
}
|
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(
|
|
|
|
std::unique_ptr<AuthSessionSettings> data);
|
|
|
|
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
|
|
|
|
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();
|
|
|
|
}
|
2017-02-23 10:59:19 +00:00
|
|
|
void authSessionCreate(UserId userId);
|
|
|
|
void authSessionDestroy();
|
2017-03-04 19:36:59 +00:00
|
|
|
base::Observable<void> &authSessionChanged() {
|
|
|
|
return _authSessionChanged;
|
|
|
|
}
|
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();
|
|
|
|
bool openLocalUrl(const QString &url);
|
2017-03-10 17:25:43 +00:00
|
|
|
|
2017-11-13 12:02:53 +00:00
|
|
|
void uploadProfilePhoto(QImage &&tosend, const PeerId &peerId);
|
2017-02-23 10:59:19 +00:00
|
|
|
void regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId);
|
|
|
|
bool isPhotoUpdating(const PeerId &peer);
|
|
|
|
void cancelPhotoUpdate(const PeerId &peer);
|
|
|
|
|
|
|
|
void selfPhotoCleared(const MTPUserProfilePhoto &result);
|
|
|
|
void chatPhotoCleared(PeerId peer, const MTPUpdates &updates);
|
|
|
|
void selfPhotoDone(const MTPphotos_Photo &result);
|
|
|
|
void chatPhotoDone(PeerId peerId, const MTPUpdates &updates);
|
2017-11-30 14:00:25 +00:00
|
|
|
bool peerPhotoFailed(PeerId peerId, const RPCError &e);
|
2017-02-23 10:59:19 +00:00
|
|
|
void peerClearPhoto(PeerId peer);
|
|
|
|
|
|
|
|
void writeUserConfigIn(TimeMs ms);
|
|
|
|
|
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
|
|
|
|
|
|
|
void checkLocalTime();
|
2017-04-15 18:48:54 +00:00
|
|
|
void setupPasscode();
|
|
|
|
void clearPasscode();
|
|
|
|
base::Observable<void> &passcodedChanged() {
|
|
|
|
return _passcodedChanged;
|
|
|
|
}
|
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
|
|
|
|
2017-08-03 13:06:29 +00:00
|
|
|
void callDelayed(int duration, base::lambda_once<void()> &&lambda) {
|
|
|
|
_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
|
|
|
signals:
|
|
|
|
void peerPhotoDone(PeerId peer);
|
|
|
|
void peerPhotoFail(PeerId peer);
|
|
|
|
|
|
|
|
public slots:
|
2017-02-25 16:44:02 +00:00
|
|
|
void onAllKeysDestroyed();
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void photoUpdated(const FullMsgId &msgId, bool silent, const MTPInputFile &file);
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2017-04-29 20:06:32 +00:00
|
|
|
friend void App::quit();
|
|
|
|
static void QuitAttempt();
|
|
|
|
void quitDelayed();
|
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
void loggedOut();
|
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
not_null<Core::Launcher*> _launcher;
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
QMap<FullMsgId, PeerId> photoUpdates;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
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
|
|
|
|
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;
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
};
|