2017-02-23 09:32:28 +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 09:32:28 +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 09:32:28 +00:00
|
|
|
*/
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2017-02-23 09:32:28 +00:00
|
|
|
|
2017-04-06 19:02:40 +00:00
|
|
|
#include "apiwrap.h"
|
2023-11-23 08:46:55 +00:00
|
|
|
#include "api/api_peer_colors.h"
|
2020-06-11 09:41:03 +00:00
|
|
|
#include "api/api_updates.h"
|
2021-07-31 14:11:53 +00:00
|
|
|
#include "api/api_user_privacy.h"
|
2019-06-05 20:41:51 +00:00
|
|
|
#include "main/main_account.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "main/main_domain.h"
|
2020-06-18 12:47:09 +00:00
|
|
|
#include "main/main_session_settings.h"
|
2022-06-07 05:48:33 +00:00
|
|
|
#include "main/main_app_config.h"
|
2021-11-09 12:10:51 +00:00
|
|
|
#include "main/session/send_as_peers.h"
|
2020-06-17 09:36:25 +00:00
|
|
|
#include "mtproto/mtproto_config.h"
|
2019-08-23 13:52:59 +00:00
|
|
|
#include "chat_helpers/stickers_emoji_pack.h"
|
2020-03-04 09:21:19 +00:00
|
|
|
#include "chat_helpers/stickers_dice_pack.h"
|
2022-07-13 17:12:40 +00:00
|
|
|
#include "chat_helpers/stickers_gift_box_pack.h"
|
2023-01-17 15:47:58 +00:00
|
|
|
#include "history/history.h"
|
|
|
|
#include "history/history_item.h"
|
2022-03-29 09:00:10 +00:00
|
|
|
#include "inline_bots/bot_attach_web_view.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "storage/file_download.h"
|
2019-12-05 08:32:33 +00:00
|
|
|
#include "storage/download_manager_mtproto.h"
|
2017-08-04 14:54:32 +00:00
|
|
|
#include "storage/file_upload.h"
|
2020-06-09 16:57:05 +00:00
|
|
|
#include "storage/storage_account.h"
|
2017-09-04 11:40:02 +00:00
|
|
|
#include "storage/storage_facade.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2020-06-12 12:12:34 +00:00
|
|
|
#include "data/data_changes.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2022-02-21 15:40:20 +00:00
|
|
|
#include "data/data_download_manager.h"
|
2020-06-24 12:52:06 +00:00
|
|
|
#include "data/stickers/data_stickers.h"
|
2020-06-11 09:41:03 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2022-01-26 09:41:27 +00:00
|
|
|
#include "window/window_controller.h"
|
2020-06-24 07:56:16 +00:00
|
|
|
#include "window/window_lock_widgets.h"
|
2021-03-31 17:15:49 +00:00
|
|
|
#include "base/unixtime.h"
|
2017-04-19 09:44:07 +00:00
|
|
|
#include "calls/calls_instance.h"
|
2018-11-15 15:36:04 +00:00
|
|
|
#include "support/support_helper.h"
|
2022-01-26 09:41:27 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "core/application.h"
|
2022-01-16 09:23:53 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2022-01-26 09:41:27 +00:00
|
|
|
#include "ui/layers/generic_box.h"
|
|
|
|
#include "styles/style_layers.h"
|
2017-04-15 18:48:54 +00:00
|
|
|
|
2020-02-07 22:42:01 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_SPELLCHECK
|
|
|
|
#include "chat_helpers/spellchecker_common.h"
|
|
|
|
#endif // TDESKTOP_DISABLE_SPELLCHECK
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
namespace Main {
|
2017-04-15 18:48:54 +00:00
|
|
|
namespace {
|
|
|
|
|
2021-03-31 17:15:49 +00:00
|
|
|
constexpr auto kTmpPasswordReserveTime = TimeId(10);
|
2017-04-15 18:48:54 +00:00
|
|
|
|
2020-06-17 09:36:25 +00:00
|
|
|
[[nodiscard]] QString ValidatedInternalLinksDomain(
|
2020-06-18 18:04:16 +00:00
|
|
|
not_null<const Session*> session) {
|
2020-06-17 09:36:25 +00:00
|
|
|
// This domain should start with 'http[s]://' and end with '/'.
|
|
|
|
// Like 'https://telegram.me/' or 'https://t.me/'.
|
|
|
|
const auto &domain = session->serverConfig().internalLinksDomain;
|
|
|
|
const auto prefixes = {
|
2022-11-26 21:20:17 +00:00
|
|
|
u"https://"_q,
|
|
|
|
u"http://"_q,
|
2020-06-17 09:36:25 +00:00
|
|
|
};
|
|
|
|
for (const auto &prefix : prefixes) {
|
|
|
|
if (domain.startsWith(prefix, Qt::CaseInsensitive)) {
|
|
|
|
return domain.endsWith('/')
|
|
|
|
? domain
|
|
|
|
: MTP::ConfigFields().internalLinksDomain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return MTP::ConfigFields().internalLinksDomain;
|
|
|
|
}
|
|
|
|
|
2017-04-15 18:48:54 +00:00
|
|
|
} // namespace
|
2017-02-23 09:32:28 +00:00
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Session::Session(
|
2020-06-18 18:04:16 +00:00
|
|
|
not_null<Account*> account,
|
2019-10-02 10:46:02 +00:00
|
|
|
const MTPUser &user,
|
2020-06-18 12:47:09 +00:00
|
|
|
std::unique_ptr<SessionSettings> settings)
|
2019-06-05 20:41:51 +00:00
|
|
|
: _account(account)
|
2019-10-02 10:46:02 +00:00
|
|
|
, _settings(std::move(settings))
|
2021-10-12 12:50:18 +00:00
|
|
|
, _changes(std::make_unique<Data::Changes>(this))
|
2017-06-05 13:33:45 +00:00
|
|
|
, _api(std::make_unique<ApiWrap>(this))
|
2020-06-11 09:41:03 +00:00
|
|
|
, _updates(std::make_unique<Api::Updates>(this))
|
2020-07-06 09:58:18 +00:00
|
|
|
, _sendProgressManager(std::make_unique<Api::SendProgressManager>(this))
|
2019-12-05 08:32:33 +00:00
|
|
|
, _downloader(std::make_unique<Storage::DownloadManagerMtproto>(_api.get()))
|
2019-04-12 10:50:41 +00:00
|
|
|
, _uploader(std::make_unique<Storage::Uploader>(_api.get()))
|
2017-09-04 11:40:02 +00:00
|
|
|
, _storage(std::make_unique<Storage::Facade>())
|
2018-02-18 13:26:28 +00:00
|
|
|
, _data(std::make_unique<Data::Session>(this))
|
2021-12-01 14:51:18 +00:00
|
|
|
, _userId(user.c_user().vid())
|
2019-01-18 12:27:37 +00:00
|
|
|
, _user(_data->processUser(user))
|
2019-08-01 14:13:02 +00:00
|
|
|
, _emojiStickersPack(std::make_unique<Stickers::EmojiPack>(this))
|
2020-04-06 09:07:49 +00:00
|
|
|
, _diceStickersPacks(std::make_unique<Stickers::DicePacks>(this))
|
2022-07-13 17:12:40 +00:00
|
|
|
, _giftBoxStickersPacks(std::make_unique<Stickers::GiftBoxPack>(this))
|
2021-11-09 12:10:51 +00:00
|
|
|
, _sendAsPeers(std::make_unique<SendAsPeers>(this))
|
2022-03-29 09:00:10 +00:00
|
|
|
, _attachWebView(std::make_unique<InlineBots::AttachWebView>(this))
|
2020-06-18 12:47:09 +00:00
|
|
|
, _supportHelper(Support::Helper::Create(this))
|
|
|
|
, _saveSettingsTimer([=] { saveSettings(); }) {
|
|
|
|
Expects(_settings != nullptr);
|
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
_api->requestTermsUpdate();
|
2018-09-11 12:50:40 +00:00
|
|
|
_api->requestFullPeer(_user);
|
2018-05-15 16:38:27 +00:00
|
|
|
|
2020-06-17 09:36:25 +00:00
|
|
|
_api->instance().setUserPhone(_user->phone());
|
2020-06-15 16:25:02 +00:00
|
|
|
|
2020-06-23 09:20:38 +00:00
|
|
|
// Load current userpic and keep it loaded.
|
2020-06-24 12:52:06 +00:00
|
|
|
_user->loadUserpic();
|
2020-06-23 09:20:38 +00:00
|
|
|
changes().peerFlagsValue(
|
|
|
|
_user,
|
|
|
|
Data::PeerUpdate::Flag::Photo
|
|
|
|
) | rpl::start_with_next([=] {
|
2022-12-05 12:18:10 +00:00
|
|
|
auto view = Ui::PeerUserpicView{ .cloud = _selfUserpicView };
|
|
|
|
[[maybe_unused]] const auto image = _user->userpicCloudImage(view);
|
|
|
|
_selfUserpicView = view.cloud;
|
2020-06-23 09:20:38 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2018-09-11 14:36:09 +00:00
|
|
|
crl::on_main(this, [=] {
|
2020-06-12 12:12:34 +00:00
|
|
|
using Flag = Data::PeerUpdate::Flag;
|
|
|
|
changes().peerUpdates(
|
|
|
|
_user,
|
|
|
|
Flag::Name
|
|
|
|
| Flag::Username
|
|
|
|
| Flag::Photo
|
|
|
|
| Flag::About
|
|
|
|
| Flag::PhoneNumber
|
2020-06-15 16:25:02 +00:00
|
|
|
) | rpl::start_with_next([=](const Data::PeerUpdate &update) {
|
2020-06-12 12:12:34 +00:00
|
|
|
local().writeSelf();
|
2020-06-15 16:25:02 +00:00
|
|
|
|
|
|
|
if (update.flags & Flag::PhoneNumber) {
|
|
|
|
const auto phone = _user->phone();
|
2020-06-17 09:36:25 +00:00
|
|
|
_api->instance().setUserPhone(phone);
|
2020-06-15 16:25:02 +00:00
|
|
|
if (!phone.isEmpty()) {
|
2020-06-17 09:36:25 +00:00
|
|
|
_api->instance().requestConfig();
|
2020-06-15 16:25:02 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-12 12:12:34 +00:00
|
|
|
}, _lifetime);
|
2019-10-02 10:46:02 +00:00
|
|
|
|
2022-06-16 08:30:31 +00:00
|
|
|
#ifndef OS_MAC_STORE
|
2022-06-08 12:53:16 +00:00
|
|
|
_account->appConfig().value(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_premiumPossible = !_account->appConfig().get<bool>(
|
|
|
|
"premium_purchase_blocked",
|
|
|
|
true);
|
|
|
|
}, _lifetime);
|
2022-06-16 08:30:31 +00:00
|
|
|
#endif // OS_MAC_STORE
|
2022-06-08 12:53:16 +00:00
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
if (_settings->hadLegacyCallsPeerToPeerNobody()) {
|
2021-07-31 14:11:53 +00:00
|
|
|
api().userPrivacy().save(
|
|
|
|
Api::UserPrivacy::Key::CallsPeer2Peer,
|
|
|
|
Api::UserPrivacy::Rule{
|
|
|
|
.option = Api::UserPrivacy::Option::Nobody
|
|
|
|
});
|
2019-10-02 10:46:02 +00:00
|
|
|
saveSettingsDelayed();
|
|
|
|
}
|
2020-06-24 12:52:06 +00:00
|
|
|
|
2020-07-06 12:26:43 +00:00
|
|
|
// Storage::Account uses Main::Account::session() in those methods.
|
|
|
|
// So they can't be called during Main::Session construction.
|
2020-06-24 12:52:06 +00:00
|
|
|
local().readInstalledStickers();
|
2021-03-25 11:05:33 +00:00
|
|
|
local().readInstalledMasks();
|
2022-07-08 18:07:14 +00:00
|
|
|
local().readInstalledCustomEmoji();
|
2020-06-24 12:52:06 +00:00
|
|
|
local().readFeaturedStickers();
|
2022-07-22 13:08:10 +00:00
|
|
|
local().readFeaturedCustomEmoji();
|
2020-06-24 12:52:06 +00:00
|
|
|
local().readRecentStickers();
|
2021-03-25 11:05:33 +00:00
|
|
|
local().readRecentMasks();
|
2020-06-24 12:52:06 +00:00
|
|
|
local().readFavedStickers();
|
|
|
|
local().readSavedGifs();
|
2022-07-26 14:45:41 +00:00
|
|
|
data().stickers().notifyUpdated(Data::StickersType::Stickers);
|
|
|
|
data().stickers().notifyUpdated(Data::StickersType::Masks);
|
|
|
|
data().stickers().notifyUpdated(Data::StickersType::Emoji);
|
2020-06-24 12:52:06 +00:00
|
|
|
data().stickers().notifySavedGifsUpdated();
|
2018-09-11 14:36:09 +00:00
|
|
|
});
|
|
|
|
|
2020-02-07 22:42:01 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_SPELLCHECK
|
|
|
|
Spellchecker::Start(this);
|
|
|
|
#endif // TDESKTOP_DISABLE_SPELLCHECK
|
2020-06-24 12:52:06 +00:00
|
|
|
|
|
|
|
_api->requestNotifySettings(MTP_inputNotifyUsers());
|
|
|
|
_api->requestNotifySettings(MTP_inputNotifyChats());
|
|
|
|
_api->requestNotifySettings(MTP_inputNotifyBroadcasts());
|
2022-02-21 15:40:20 +00:00
|
|
|
|
|
|
|
Core::App().downloadManager().trackSession(this);
|
2017-02-23 09:32:28 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 17:15:49 +00:00
|
|
|
void Session::setTmpPassword(const QByteArray &password, TimeId validUntil) {
|
|
|
|
if (_tmpPassword.isEmpty() || validUntil > _tmpPasswordValidUntil) {
|
|
|
|
_tmpPassword = password;
|
|
|
|
_tmpPasswordValidUntil = validUntil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray Session::validTmpPassword() const {
|
|
|
|
return (_tmpPasswordValidUntil
|
|
|
|
>= base::unixtime::now() + kTmpPasswordReserveTime)
|
|
|
|
? _tmpPassword
|
|
|
|
: QByteArray();
|
|
|
|
}
|
|
|
|
|
2020-06-26 10:36:22 +00:00
|
|
|
// Can be called only right before ~Session.
|
|
|
|
void Session::finishLogout() {
|
|
|
|
unlockTerms();
|
|
|
|
data().clear();
|
|
|
|
data().clearLocalStorage();
|
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Session::~Session() {
|
2020-06-24 07:56:16 +00:00
|
|
|
unlockTerms();
|
2020-06-16 09:40:43 +00:00
|
|
|
data().clear();
|
2019-06-05 20:41:51 +00:00
|
|
|
ClickHandler::clearActive();
|
|
|
|
ClickHandler::unpressed();
|
|
|
|
}
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
Account &Session::account() const {
|
2019-06-05 20:41:51 +00:00
|
|
|
return *_account;
|
|
|
|
}
|
|
|
|
|
2020-06-09 16:57:05 +00:00
|
|
|
Storage::Account &Session::local() const {
|
|
|
|
return _account->local();
|
|
|
|
}
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
Domain &Session::domain() const {
|
|
|
|
return _account->domain();
|
|
|
|
}
|
|
|
|
|
|
|
|
Storage::Domain &Session::domainLocal() const {
|
|
|
|
return _account->domainLocal();
|
|
|
|
}
|
|
|
|
|
2020-07-01 08:03:34 +00:00
|
|
|
void Session::notifyDownloaderTaskFinished() {
|
|
|
|
downloader().notifyTaskFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> Session::downloaderTaskFinished() const {
|
2017-08-04 14:54:32 +00:00
|
|
|
return downloader().taskFinished();
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 14:57:01 +00:00
|
|
|
bool Session::premium() const {
|
|
|
|
return _user->isPremium();
|
|
|
|
}
|
|
|
|
|
2022-06-07 05:48:33 +00:00
|
|
|
bool Session::premiumPossible() const {
|
2022-06-08 12:53:16 +00:00
|
|
|
return premium() || _premiumPossible.current();
|
|
|
|
}
|
|
|
|
|
2022-06-20 07:13:39 +00:00
|
|
|
bool Session::premiumBadgesShown() const {
|
|
|
|
return supportMode() || premiumPossible();
|
|
|
|
}
|
|
|
|
|
2022-06-08 12:53:16 +00:00
|
|
|
rpl::producer<bool> Session::premiumPossibleValue() const {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
auto premium = _user->flagsValue(
|
|
|
|
) | rpl::filter([=](UserData::Flags::Change change) {
|
|
|
|
return (change.diff & UserDataFlag::Premium);
|
|
|
|
}) | rpl::map([=] {
|
|
|
|
return _user->isPremium();
|
|
|
|
});
|
|
|
|
return rpl::combine(
|
|
|
|
std::move(premium),
|
|
|
|
_premiumPossible.value(),
|
|
|
|
_1 || _2);
|
2022-06-07 05:48:33 +00:00
|
|
|
}
|
|
|
|
|
2022-07-15 16:56:25 +00:00
|
|
|
bool Session::isTestMode() const {
|
|
|
|
return mtp().isTestMode();
|
|
|
|
}
|
|
|
|
|
2020-06-24 09:05:56 +00:00
|
|
|
uint64 Session::uniqueId() const {
|
2020-06-24 09:32:07 +00:00
|
|
|
// See also Account::willHaveSessionUniqueId.
|
2021-04-01 21:04:10 +00:00
|
|
|
return userId().bare
|
2022-07-15 16:56:25 +00:00
|
|
|
| (isTestMode() ? 0x0100'0000'0000'0000ULL : 0ULL);
|
2020-06-24 09:05:56 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
UserId Session::userId() const {
|
2021-12-01 14:51:18 +00:00
|
|
|
return _userId;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
PeerId Session::userPeerId() const {
|
2021-12-01 14:51:18 +00:00
|
|
|
return _userId;
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-19 19:04:40 +00:00
|
|
|
bool Session::validateSelf(UserId id) {
|
|
|
|
if (id != userId()) {
|
2017-03-04 19:36:59 +00:00
|
|
|
LOG(("Auth Error: wrong self user received."));
|
2019-07-24 08:46:23 +00:00
|
|
|
crl::on_main(this, [=] { _account->logOut(); });
|
2017-03-04 19:36:59 +00:00
|
|
|
return false;
|
2017-02-23 09:32:28 +00:00
|
|
|
}
|
2017-03-04 19:36:59 +00:00
|
|
|
return true;
|
2017-02-23 09:32:28 +00:00
|
|
|
}
|
2017-03-04 19:36:59 +00:00
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
void Session::saveSettings() {
|
|
|
|
local().writeSessionSettings();
|
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
void Session::saveSettingsDelayed(crl::time delay) {
|
2019-08-23 13:52:59 +00:00
|
|
|
_saveSettingsTimer.callOnce(delay);
|
2017-04-09 18:06:06 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
void Session::saveSettingsNowIfNeeded() {
|
|
|
|
if (_saveSettingsTimer.isActive()) {
|
|
|
|
_saveSettingsTimer.cancel();
|
|
|
|
saveSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
MTP::DcId Session::mainDcId() const {
|
2020-06-17 09:36:25 +00:00
|
|
|
return _account->mtp().mainDcId();
|
2020-06-11 16:09:46 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 09:36:25 +00:00
|
|
|
MTP::Instance &Session::mtp() const {
|
2019-07-24 08:46:23 +00:00
|
|
|
return _account->mtp();
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:36:25 +00:00
|
|
|
const MTP::ConfigFields &Session::serverConfig() const {
|
|
|
|
return _account->mtp().configValues();
|
|
|
|
}
|
|
|
|
|
2020-06-24 07:56:16 +00:00
|
|
|
void Session::lockByTerms(const Window::TermsLock &data) {
|
|
|
|
if (!_termsLock || *_termsLock != data) {
|
|
|
|
_termsLock = std::make_unique<Window::TermsLock>(data);
|
|
|
|
_termsLockChanges.fire(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unlockTerms() {
|
|
|
|
if (_termsLock) {
|
|
|
|
_termsLock = nullptr;
|
|
|
|
_termsLockChanges.fire(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
void Session::termsDeleteNow() {
|
2019-03-27 08:37:25 +00:00
|
|
|
api().request(MTPaccount_DeleteAccount(
|
2022-07-01 09:04:21 +00:00
|
|
|
MTP_flags(0),
|
|
|
|
MTP_string("Decline ToS update"),
|
|
|
|
MTPInputCheckPasswordSRP()
|
2019-03-27 08:37:25 +00:00
|
|
|
)).send();
|
|
|
|
}
|
|
|
|
|
2020-06-24 07:56:16 +00:00
|
|
|
std::optional<Window::TermsLock> Session::termsLocked() const {
|
|
|
|
return _termsLock ? base::make_optional(*_termsLock) : std::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> Session::termsLockChanges() const {
|
|
|
|
return _termsLockChanges.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> Session::termsLockValue() const {
|
|
|
|
return rpl::single(
|
|
|
|
_termsLock != nullptr
|
|
|
|
) | rpl::then(termsLockChanges());
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:36:25 +00:00
|
|
|
QString Session::createInternalLink(const QString &query) const {
|
2022-01-16 20:25:08 +00:00
|
|
|
return createInternalLink(TextWithEntities{ .text = query }).text;
|
2022-01-16 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Session::createInternalLinkFull(const QString &query) const {
|
2022-01-16 20:25:08 +00:00
|
|
|
return createInternalLinkFull(TextWithEntities{ .text = query }).text;
|
2022-01-16 09:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TextWithEntities Session::createInternalLink(
|
|
|
|
const TextWithEntities &query) const {
|
|
|
|
const auto result = createInternalLinkFull(query);
|
|
|
|
const auto prefixes = {
|
2022-11-26 21:20:17 +00:00
|
|
|
u"https://"_q,
|
|
|
|
u"http://"_q,
|
2020-06-17 09:36:25 +00:00
|
|
|
};
|
|
|
|
for (auto &prefix : prefixes) {
|
2022-01-16 09:23:53 +00:00
|
|
|
if (result.text.startsWith(prefix, Qt::CaseInsensitive)) {
|
|
|
|
return Ui::Text::Mid(result, prefix.size());
|
2020-06-17 09:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-16 09:23:53 +00:00
|
|
|
LOG(("Warning: bad internal url '%1'").arg(result.text));
|
2020-06-17 09:36:25 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-01-16 09:23:53 +00:00
|
|
|
TextWithEntities Session::createInternalLinkFull(
|
|
|
|
TextWithEntities query) const {
|
|
|
|
return TextWithEntities::Simple(ValidatedInternalLinksDomain(this))
|
|
|
|
.append(std::move(query));
|
2020-06-17 09:36:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
bool Session::supportMode() const {
|
2018-11-15 15:36:04 +00:00
|
|
|
return (_supportHelper != nullptr);
|
2018-10-02 20:39:54 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Support::Helper &Session::supportHelper() const {
|
2018-10-02 20:39:54 +00:00
|
|
|
Expects(supportMode());
|
|
|
|
|
2018-11-15 15:36:04 +00:00
|
|
|
return *_supportHelper;
|
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Support::Templates& Session::supportTemplates() const {
|
2018-11-15 15:36:04 +00:00
|
|
|
return supportHelper().templates();
|
2018-09-28 11:56:21 +00:00
|
|
|
}
|
2019-07-24 11:45:24 +00:00
|
|
|
|
2020-06-11 09:41:03 +00:00
|
|
|
void Session::addWindow(not_null<Window::SessionController*> controller) {
|
|
|
|
_windows.emplace(controller);
|
|
|
|
controller->lifetime().add([=] {
|
|
|
|
_windows.remove(controller);
|
|
|
|
});
|
|
|
|
updates().addActiveChat(controller->activeChatChanges(
|
2022-11-11 06:23:23 +00:00
|
|
|
) | rpl::map([=](Dialogs::Key chat) {
|
2020-06-11 09:41:03 +00:00
|
|
|
return chat.peer();
|
|
|
|
}) | rpl::distinct_until_changed());
|
|
|
|
}
|
|
|
|
|
2022-01-26 09:41:27 +00:00
|
|
|
bool Session::uploadsInProgress() const {
|
|
|
|
return !!_uploader->currentUploadId();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::uploadsStopWithConfirmation(Fn<void()> done) {
|
|
|
|
const auto id = _uploader->currentUploadId();
|
2023-01-17 15:47:58 +00:00
|
|
|
const auto message = data().message(id);
|
|
|
|
const auto exists = (message != nullptr);
|
|
|
|
const auto window = message
|
|
|
|
? Core::App().windowFor(message->history()->peer)
|
|
|
|
: Core::App().activePrimaryWindow();
|
2022-01-26 09:41:27 +00:00
|
|
|
auto box = Box([=](not_null<Ui::GenericBox*> box) {
|
2022-01-27 13:20:39 +00:00
|
|
|
box->addRow(
|
2022-01-26 09:41:27 +00:00
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
box.get(),
|
|
|
|
tr::lng_upload_sure_stop(),
|
|
|
|
st::boxLabel),
|
|
|
|
st::boxPadding + QMargins(0, 0, 0, st::boxPadding.bottom()));
|
|
|
|
box->setStyle(st::defaultBox);
|
|
|
|
box->addButton(tr::lng_selected_upload_stop(), [=] {
|
|
|
|
box->closeBox();
|
|
|
|
|
|
|
|
uploadsStop();
|
|
|
|
if (done) {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
}, st::attentionBoxButton);
|
|
|
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
|
|
|
if (exists) {
|
|
|
|
box->addLeftButton(tr::lng_upload_show_file(), [=] {
|
|
|
|
box->closeBox();
|
|
|
|
|
|
|
|
if (const auto item = data().message(id)) {
|
|
|
|
if (const auto window = tryResolveWindow()) {
|
2022-10-28 12:30:59 +00:00
|
|
|
window->showMessage(item);
|
2022-01-26 09:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
window->show(std::move(box));
|
2022-01-26 11:50:10 +00:00
|
|
|
window->activate();
|
2022-01-26 09:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::uploadsStop() {
|
|
|
|
_uploader->cancelAll();
|
|
|
|
}
|
|
|
|
|
2020-06-11 09:41:03 +00:00
|
|
|
auto Session::windows() const
|
|
|
|
-> const base::flat_set<not_null<Window::SessionController*>> & {
|
|
|
|
return _windows;
|
|
|
|
}
|
|
|
|
|
2022-01-26 09:41:27 +00:00
|
|
|
Window::SessionController *Session::tryResolveWindow() const {
|
|
|
|
if (_windows.empty()) {
|
|
|
|
domain().activate(_account);
|
|
|
|
if (_windows.empty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2022-11-30 06:31:33 +00:00
|
|
|
for (const auto &window : _windows) {
|
|
|
|
if (window->isPrimary()) {
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
}
|
2022-01-26 09:41:27 +00:00
|
|
|
return _windows.front();
|
|
|
|
}
|
|
|
|
|
2023-11-23 08:46:55 +00:00
|
|
|
auto Session::colorIndicesValue()
|
2023-10-26 19:40:53 +00:00
|
|
|
-> rpl::producer<Ui::ColorIndicesCompressed> {
|
2023-11-23 08:46:55 +00:00
|
|
|
return api().peerColors().indicesValue();
|
2023-10-26 19:40:53 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
} // namespace Main
|