Use Main::Session in download/upload.

This commit is contained in:
John Preston 2020-06-08 19:17:33 +04:00
parent 3878a1b212
commit 4b354b0928
47 changed files with 572 additions and 220 deletions

View File

@ -28,7 +28,11 @@ void UrlAuthBox::Activate(
int row, int row,
int column) { int column) {
const auto itemId = message->fullId(); const auto itemId = message->fullId();
const auto button = HistoryMessageMarkupButton::Get(itemId, row, column); const auto button = HistoryMessageMarkupButton::Get(
&message->history()->owner(),
itemId,
row,
column);
if (button->requestId || !IsServerMsgId(itemId.msg)) { if (button->requestId || !IsServerMsgId(itemId.msg)) {
return; return;
} }
@ -43,10 +47,13 @@ void UrlAuthBox::Activate(
MTP_int(buttonId) MTP_int(buttonId)
)).done([=](const MTPUrlAuthResult &result) { )).done([=](const MTPUrlAuthResult &result) {
const auto button = HistoryMessageMarkupButton::Get( const auto button = HistoryMessageMarkupButton::Get(
&session->data(),
itemId, itemId,
row, row,
column); column);
if (!button) return; if (!button) {
return;
}
button->requestId = 0; button->requestId = 0;
result.match([&](const MTPDurlAuthResultAccepted &data) { result.match([&](const MTPDurlAuthResultAccepted &data) {
@ -58,6 +65,7 @@ void UrlAuthBox::Activate(
}); });
}).fail([=](const RPCError &error) { }).fail([=](const RPCError &error) {
const auto button = HistoryMessageMarkupButton::Get( const auto button = HistoryMessageMarkupButton::Get(
&session->data(),
itemId, itemId,
row, row,
column); column);
@ -74,7 +82,11 @@ void UrlAuthBox::Request(
int row, int row,
int column) { int column) {
const auto itemId = message->fullId(); const auto itemId = message->fullId();
const auto button = HistoryMessageMarkupButton::Get(itemId, row, column); const auto button = HistoryMessageMarkupButton::Get(
&message->history()->owner(),
itemId,
row,
column);
if (button->requestId || !IsServerMsgId(itemId.msg)) { if (button->requestId || !IsServerMsgId(itemId.msg)) {
return; return;
} }

View File

@ -108,21 +108,27 @@ bool Set::thumbnailFailed() const {
} }
void Set::loadThumbnail() { void Set::loadThumbnail() {
auto &file = _thumbnail;
const auto origin = Data::FileOriginStickerSet(id, access);
const auto fromCloud = LoadFromCloudOrLocal;
const auto cacheTag = Data::kImageCacheTag;
const auto autoLoading = false; const auto autoLoading = false;
Data::LoadCloudFile(file, origin, fromCloud, autoLoading, cacheTag, [=] { const auto finalCheck = [=] {
if (const auto active = activeThumbnailView()) { if (const auto active = activeThumbnailView()) {
return !active->image() && active->content().isEmpty(); return !active->image() && active->content().isEmpty();
} }
return true; return true;
}, [=](QByteArray result) { };
const auto done = [=](QByteArray result) {
if (const auto active = activeThumbnailView()) { if (const auto active = activeThumbnailView()) {
active->set(&_owner->session(), std::move(result)); active->set(&_owner->session(), std::move(result));
} }
}); };
Data::LoadCloudFile(
&_owner->session(),
_thumbnail,
Data::FileOriginStickerSet(id, access),
LoadFromCloudOrLocal,
autoLoading,
Data::kImageCacheTag,
finalCheck,
done);
} }
const ImageLocation &Set::thumbnailLocation() const { const ImageLocation &Set::thumbnailLocation() const {

View File

@ -157,13 +157,15 @@ void ShowInFolder(const QString &filepath) {
}); });
} }
QString DefaultDownloadPath() { QString DefaultDownloadPathFolder(not_null<Main::Session*> session) {
return session->supportMode() ? u"Tsupport Desktop"_q : AppName.utf16();
}
QString DefaultDownloadPath(not_null<Main::Session*> session) {
return QStandardPaths::writableLocation( return QStandardPaths::writableLocation(
QStandardPaths::DownloadLocation) QStandardPaths::DownloadLocation)
+ '/' + '/'
+ (Main::Session::Exists() && Auth().supportMode() + DefaultDownloadPathFolder(session)
? "Tsupport Desktop"_cs
: AppName).utf16()
+ '/'; + '/';
} }

View File

@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/observer.h" #include "base/observer.h"
namespace Main {
class Session;
} // namespace Main
// legacy // legacy
bool filedialogGetSaveFile( bool filedialogGetSaveFile(
QString &file, QString &file,
@ -36,7 +40,9 @@ void OpenWith(const QString &filepath, QPoint menuPosition);
void Launch(const QString &filepath); void Launch(const QString &filepath);
void ShowInFolder(const QString &filepath); void ShowInFolder(const QString &filepath);
[[nodiscard]] QString DefaultDownloadPath(); [[nodiscard]] QString DefaultDownloadPathFolder(
not_null<Main::Session*> session);
[[nodiscard]] QString DefaultDownloadPath(not_null<Main::Session*> session);
namespace internal { namespace internal {

View File

@ -45,7 +45,8 @@ void MegagroupInfo::setLocation(const ChannelLocation &location) {
ChannelData::ChannelData(not_null<Data::Session*> owner, PeerId id) ChannelData::ChannelData(not_null<Data::Session*> owner, PeerId id)
: PeerData(owner, id) : PeerData(owner, id)
, inputChannel(MTP_inputChannel(MTP_int(bareId()), MTP_long(0))) { , inputChannel(MTP_inputChannel(MTP_int(bareId()), MTP_long(0)))
, _ptsWaiter(&owner->session()) {
Data::PeerFlagValue( Data::PeerFlagValue(
this, this,
MTPDchannel::Flag::f_megagroup MTPDchannel::Flag::f_megagroup

View File

@ -103,16 +103,26 @@ void CloudImage::load(not_null<Main::Session*> session, FileOrigin origin) {
const auto fromCloud = LoadFromCloudOrLocal; const auto fromCloud = LoadFromCloudOrLocal;
const auto cacheTag = kImageCacheTag; const auto cacheTag = kImageCacheTag;
const auto autoLoading = false; const auto autoLoading = false;
LoadCloudFile(_file, origin, fromCloud, autoLoading, cacheTag, [=] { const auto finalCheck = [=] {
if (const auto active = activeView()) { if (const auto active = activeView()) {
return !active->image(); return !active->image();
} }
return true; return true;
}, [=](QImage result) { };
const auto done = [=](QImage result) {
if (const auto active = activeView()) { if (const auto active = activeView()) {
active->set(session, std::move(result)); active->set(session, std::move(result));
} }
}); };
LoadCloudFile(
session,
_file,
origin,
LoadFromCloudOrLocal,
autoLoading,
kImageCacheTag,
finalCheck,
done);
} }
const ImageLocation &CloudImage::location() const { const ImageLocation &CloudImage::location() const {
@ -191,6 +201,7 @@ void UpdateCloudFile(
} }
void LoadCloudFile( void LoadCloudFile(
not_null<Main::Session*> session,
CloudFile &file, CloudFile &file,
FileOrigin origin, FileOrigin origin,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
@ -212,6 +223,7 @@ void LoadCloudFile(
} }
file.flags &= ~CloudFile::Flag::Cancelled; file.flags &= ~CloudFile::Flag::Cancelled;
file.loader = CreateFileLoader( file.loader = CreateFileLoader(
session,
file.location.file(), file.location.file(),
origin, origin,
QString(), QString(),
@ -256,6 +268,7 @@ void LoadCloudFile(
} }
void LoadCloudFile( void LoadCloudFile(
not_null<Main::Session*> session,
CloudFile &file, CloudFile &file,
FileOrigin origin, FileOrigin origin,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
@ -276,6 +289,7 @@ void LoadCloudFile(
} }
}; };
LoadCloudFile( LoadCloudFile(
session,
file, file,
origin, origin,
fromCloud, fromCloud,
@ -288,6 +302,7 @@ void LoadCloudFile(
} }
void LoadCloudFile( void LoadCloudFile(
not_null<Main::Session*> session,
CloudFile &file, CloudFile &file,
FileOrigin origin, FileOrigin origin,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
@ -308,6 +323,7 @@ void LoadCloudFile(
} }
}; };
LoadCloudFile( LoadCloudFile(
session,
file, file,
origin, origin,
fromCloud, fromCloud,

View File

@ -96,6 +96,7 @@ void UpdateCloudFile(
Fn<void(QImage)> usePreloaded = nullptr); Fn<void(QImage)> usePreloaded = nullptr);
void LoadCloudFile( void LoadCloudFile(
not_null<Main::Session*> session,
CloudFile &file, CloudFile &file,
FileOrigin origin, FileOrigin origin,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
@ -107,6 +108,7 @@ void LoadCloudFile(
Fn<void()> progress = nullptr); Fn<void()> progress = nullptr);
void LoadCloudFile( void LoadCloudFile(
not_null<Main::Session*> session,
CloudFile &file, CloudFile &file,
FileOrigin origin, FileOrigin origin,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,

View File

@ -123,6 +123,7 @@ bool fileIsImage(const QString &name, const QString &mime) {
} }
QString FileNameUnsafe( QString FileNameUnsafe(
not_null<Main::Session*> session,
const QString &title, const QString &title,
const QString &filter, const QString &filter,
const QString &prefix, const QString &prefix,
@ -176,7 +177,7 @@ QString FileNameUnsafe(
QString path; QString path;
if (Global::DownloadPath().isEmpty()) { if (Global::DownloadPath().isEmpty()) {
path = File::DefaultDownloadPath(); path = File::DefaultDownloadPath(session);
} else if (Global::DownloadPath() == qsl("tmp")) { } else if (Global::DownloadPath() == qsl("tmp")) {
path = cTempDir(); path = cTempDir();
} else { } else {
@ -210,6 +211,7 @@ QString FileNameUnsafe(
} }
QString FileNameForSave( QString FileNameForSave(
not_null<Main::Session*> session,
const QString &title, const QString &title,
const QString &filter, const QString &filter,
const QString &prefix, const QString &prefix,
@ -217,6 +219,7 @@ QString FileNameForSave(
bool savingAs, bool savingAs,
const QDir &dir) { const QDir &dir) {
const auto result = FileNameUnsafe( const auto result = FileNameUnsafe(
session,
title, title,
filter, filter,
prefix, prefix,
@ -285,7 +288,14 @@ QString DocumentFileNameForSave(
prefix = qsl("doc"); prefix = qsl("doc");
} }
return FileNameForSave(caption, filter, prefix, name, forceSavingAs, dir); return FileNameForSave(
&data->session(),
caption,
filter,
prefix,
name,
forceSavingAs,
dir);
} }
DocumentClickHandler::DocumentClickHandler( DocumentClickHandler::DocumentClickHandler(
@ -655,20 +665,27 @@ bool DocumentData::thumbnailFailed() const {
} }
void DocumentData::loadThumbnail(Data::FileOrigin origin) { void DocumentData::loadThumbnail(Data::FileOrigin origin) {
auto &file = _thumbnail;
const auto fromCloud = LoadFromCloudOrLocal;
const auto cacheTag = Data::kImageCacheTag;
const auto autoLoading = false; const auto autoLoading = false;
Data::LoadCloudFile(file, origin, fromCloud, autoLoading, cacheTag, [=] { const auto finalCheck = [=] {
if (const auto active = activeMediaView()) { if (const auto active = activeMediaView()) {
return !active->thumbnail(); return !active->thumbnail();
} }
return true; return true;
}, [=](QImage result) { };
const auto done = [=](QImage result) {
if (const auto active = activeMediaView()) { if (const auto active = activeMediaView()) {
active->setThumbnail(std::move(result)); active->setThumbnail(std::move(result));
} }
}); };
Data::LoadCloudFile(
&session(),
_thumbnail,
origin,
LoadFromCloudOrLocal,
autoLoading,
Data::kImageCacheTag,
finalCheck,
done);
} }
const ImageLocation &DocumentData::thumbnailLocation() const { const ImageLocation &DocumentData::thumbnailLocation() const {
@ -692,20 +709,27 @@ bool DocumentData::videoThumbnailFailed() const {
} }
void DocumentData::loadVideoThumbnail(Data::FileOrigin origin) { void DocumentData::loadVideoThumbnail(Data::FileOrigin origin) {
auto &file = _videoThumbnail;
const auto fromCloud = LoadFromCloudOrLocal;
const auto cacheTag = Data::kAnimationCacheTag;
const auto autoLoading = false; const auto autoLoading = false;
Data::LoadCloudFile(file, origin, fromCloud, autoLoading, cacheTag, [=] { const auto finalCheck = [=] {
if (const auto active = activeMediaView()) { if (const auto active = activeMediaView()) {
return active->videoThumbnailContent().isEmpty(); return active->videoThumbnailContent().isEmpty();
} }
return true; return true;
}, [=](QByteArray result) { };
const auto done = [=](QByteArray result) {
if (const auto active = activeMediaView()) { if (const auto active = activeMediaView()) {
active->setVideoThumbnail(std::move(result)); active->setVideoThumbnail(std::move(result));
} }
}); };
Data::LoadCloudFile(
&session(),
_videoThumbnail,
origin,
LoadFromCloudOrLocal,
autoLoading,
Data::kAnimationCacheTag,
finalCheck,
done);
} }
const ImageLocation &DocumentData::videoThumbnailLocation() const { const ImageLocation &DocumentData::videoThumbnailLocation() const {
@ -957,6 +981,7 @@ void DocumentData::save(
auto reader = owner().streaming().sharedReader(this, origin, true); auto reader = owner().streaming().sharedReader(this, origin, true);
if (reader) { if (reader) {
_loader = std::make_unique<Storage::StreamedFileDownloader>( _loader = std::make_unique<Storage::StreamedFileDownloader>(
&session(),
id, id,
_dc, _dc,
origin, origin,
@ -972,6 +997,7 @@ void DocumentData::save(
cacheTag()); cacheTag());
} else if (hasWebLocation()) { } else if (hasWebLocation()) {
_loader = std::make_unique<mtpFileLoader>( _loader = std::make_unique<mtpFileLoader>(
&session(),
_urlLocation, _urlLocation,
size, size,
fromCloud, fromCloud,
@ -979,6 +1005,7 @@ void DocumentData::save(
cacheTag()); cacheTag());
} else if (!_access && !_url.isEmpty()) { } else if (!_access && !_url.isEmpty()) {
_loader = std::make_unique<webFileLoader>( _loader = std::make_unique<webFileLoader>(
&session(),
_url, _url,
toFile, toFile,
fromCloud, fromCloud,
@ -986,6 +1013,7 @@ void DocumentData::save(
cacheTag()); cacheTag());
} else { } else {
_loader = std::make_unique<mtpFileLoader>( _loader = std::make_unique<mtpFileLoader>(
&session(),
StorageFileLocation( StorageFileLocation(
_dc, _dc,
session().userId(), session().userId(),

View File

@ -432,6 +432,7 @@ private:
}; };
QString FileNameForSave( QString FileNameForSave(
not_null<Main::Session*> session,
const QString &title, const QString &title,
const QString &filter, const QString &filter,
const QString &prefix, const QString &prefix,

View File

@ -233,32 +233,44 @@ void PhotoData::load(
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
bool autoLoading) { bool autoLoading) {
const auto index = validSizeIndex(size); const auto index = validSizeIndex(size);
auto &image = _images[index];
// Could've changed, if the requested size didn't have a location. // Could've changed, if the requested size didn't have a location.
const auto loadingSize = static_cast<PhotoSize>(index); const auto loadingSize = static_cast<PhotoSize>(index);
const auto cacheTag = Data::kImageCacheTag; const auto finalCheck = [=] {
Data::LoadCloudFile(image, origin, fromCloud, autoLoading, cacheTag, [=] {
if (const auto active = activeMediaView()) { if (const auto active = activeMediaView()) {
return !active->image(size); return !active->image(size);
} }
return true; return true;
}, [=](QImage result) { };
const auto done = [=](QImage result) {
if (const auto active = activeMediaView()) { if (const auto active = activeMediaView()) {
active->set(loadingSize, std::move(result)); active->set(loadingSize, std::move(result));
} }
if (loadingSize == PhotoSize::Large) { if (loadingSize == PhotoSize::Large) {
_owner->photoLoadDone(this); _owner->photoLoadDone(this);
} }
}, [=](bool started) { };
const auto fail = [=](bool started) {
if (loadingSize == PhotoSize::Large) { if (loadingSize == PhotoSize::Large) {
_owner->photoLoadFail(this, started); _owner->photoLoadFail(this, started);
} }
}, [=] { };
const auto progress = [=] {
if (loadingSize == PhotoSize::Large) { if (loadingSize == PhotoSize::Large) {
_owner->photoLoadProgress(this); _owner->photoLoadProgress(this);
} }
}); };
Data::LoadCloudFile(
&session(),
_images[index],
origin,
fromCloud,
autoLoading,
Data::kImageCacheTag,
finalCheck,
done,
fail,
progress);
if (size == PhotoSize::Large) { if (size == PhotoSize::Large) {
_owner->notifyPhotoLayoutChanged(this); _owner->notifyPhotoLayoutChanged(this);

View File

@ -12,8 +12,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "apiwrap.h" #include "apiwrap.h"
#include "app.h" #include "app.h"
PtsWaiter::PtsWaiter(not_null<Main::Session*> session) : _session(session) {
}
uint64 PtsWaiter::ptsKey(PtsSkippedQueue queue, int32 pts) { uint64 PtsWaiter::ptsKey(PtsSkippedQueue queue, int32 pts) {
return _queue.insert(uint64(uint32(pts)) << 32 | (++_skippedKey), queue).key(); return _queue.emplace(
uint64(uint32(pts)) << 32 | (++_skippedKey),
queue
).first->first;
} }
void PtsWaiter::setWaitingForSkipped(ChannelData *channel, int32 ms) { void PtsWaiter::setWaitingForSkipped(ChannelData *channel, int32 ms) {
@ -47,17 +53,25 @@ void PtsWaiter::checkForWaiting(ChannelData *channel) {
} }
void PtsWaiter::applySkippedUpdates(ChannelData *channel) { void PtsWaiter::applySkippedUpdates(ChannelData *channel) {
if (!_waitingForSkipped) return; if (!_waitingForSkipped) {
return;
}
setWaitingForSkipped(channel, -1); setWaitingForSkipped(channel, -1);
if (_queue.isEmpty()) return; if (_queue.empty()) {
return;
}
++_applySkippedLevel; ++_applySkippedLevel;
for (auto i = _queue.cbegin(), e = _queue.cend(); i != e; ++i) { for (auto i = _queue.cbegin(), e = _queue.cend(); i != e; ++i) {
switch (i.value()) { switch (i->second) {
case SkippedUpdate: Auth().api().applyUpdateNoPtsCheck(_updateQueue.value(i.key())); break; case SkippedUpdate: {
case SkippedUpdates: Auth().api().applyUpdatesNoPtsCheck(_updatesQueue.value(i.key())); break; _session->api().applyUpdateNoPtsCheck(_updateQueue[i->first]);
} break;
case SkippedUpdates: {
_session->api().applyUpdatesNoPtsCheck(_updatesQueue[i->first]);
} break;
} }
} }
--_applySkippedLevel; --_applySkippedLevel;
@ -71,7 +85,11 @@ void PtsWaiter::clearSkippedUpdates() {
_applySkippedLevel = 0; _applySkippedLevel = 0;
} }
bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdates &updates) { bool PtsWaiter::updated(
ChannelData *channel,
int32 pts,
int32 count,
const MTPUpdates &updates) {
if (_requesting || _applySkippedLevel) { if (_requesting || _applySkippedLevel) {
return true; return true;
} else if (pts <= _good && count > 0) { } else if (pts <= _good && count > 0) {
@ -79,11 +97,15 @@ bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPU
} else if (check(channel, pts, count)) { } else if (check(channel, pts, count)) {
return true; return true;
} }
_updatesQueue.insert(ptsKey(SkippedUpdates, pts), updates); _updatesQueue.emplace(ptsKey(SkippedUpdates, pts), updates);
return false; return false;
} }
bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPUpdate &update) { bool PtsWaiter::updated(
ChannelData *channel,
int32 pts,
int32 count,
const MTPUpdate &update) {
if (_requesting || _applySkippedLevel) { if (_requesting || _applySkippedLevel) {
return true; return true;
} else if (pts <= _good && count > 0) { } else if (pts <= _good && count > 0) {
@ -91,7 +113,7 @@ bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count, const MTPU
} else if (check(channel, pts, count)) { } else if (check(channel, pts, count)) {
return true; return true;
} }
_updateQueue.insert(ptsKey(SkippedUpdate, pts), update); _updateQueue.emplace(ptsKey(SkippedUpdate, pts), update);
return false; return false;
} }
@ -104,35 +126,46 @@ bool PtsWaiter::updated(ChannelData *channel, int32 pts, int32 count) {
return check(channel, pts, count); return check(channel, pts, count);
} }
bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count, const MTPUpdates &updates) { bool PtsWaiter::updateAndApply(
ChannelData *channel,
int32 pts,
int32 count,
const MTPUpdates &updates) {
if (!updated(channel, pts, count, updates)) { if (!updated(channel, pts, count, updates)) {
return false; return false;
} }
if (!_waitingForSkipped || _queue.isEmpty()) { if (!_waitingForSkipped || _queue.empty()) {
// Optimization - no need to put in queue and back. // Optimization - no need to put in queue and back.
Auth().api().applyUpdatesNoPtsCheck(updates); _session->api().applyUpdatesNoPtsCheck(updates);
} else { } else {
_updatesQueue.insert(ptsKey(SkippedUpdates, pts), updates); _updatesQueue.emplace(ptsKey(SkippedUpdates, pts), updates);
applySkippedUpdates(channel); applySkippedUpdates(channel);
} }
return true; return true;
} }
bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count, const MTPUpdate &update) { bool PtsWaiter::updateAndApply(
ChannelData *channel,
int32 pts,
int32 count,
const MTPUpdate &update) {
if (!updated(channel, pts, count, update)) { if (!updated(channel, pts, count, update)) {
return false; return false;
} }
if (!_waitingForSkipped || _queue.isEmpty()) { if (!_waitingForSkipped || _queue.empty()) {
// Optimization - no need to put in queue and back. // Optimization - no need to put in queue and back.
Auth().api().applyUpdateNoPtsCheck(update); _session->api().applyUpdateNoPtsCheck(update);
} else { } else {
_updateQueue.insert(ptsKey(SkippedUpdate, pts), update); _updateQueue.emplace(ptsKey(SkippedUpdate, pts), update);
applySkippedUpdates(channel); applySkippedUpdates(channel);
} }
return true; return true;
} }
bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count) { bool PtsWaiter::updateAndApply(
ChannelData *channel,
int32 pts,
int32 count) {
if (!updated(channel, pts, count)) { if (!updated(channel, pts, count)) {
return false; return false;
} }

View File

@ -7,6 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
namespace Main {
class Session;
} // namespace Main
enum PtsSkippedQueue { enum PtsSkippedQueue {
SkippedUpdate, SkippedUpdate,
SkippedUpdates, SkippedUpdates,
@ -14,7 +18,7 @@ enum PtsSkippedQueue {
class PtsWaiter { class PtsWaiter {
public: public:
PtsWaiter() = default; explicit PtsWaiter(not_null<Main::Session*> session);
// 1s wait for skipped seq or pts in updates. // 1s wait for skipped seq or pts in updates.
static constexpr auto kWaitForSkippedTimeout = 1000; static constexpr auto kWaitForSkippedTimeout = 1000;
@ -84,9 +88,10 @@ private:
uint64 ptsKey(PtsSkippedQueue queue, int32 pts); uint64 ptsKey(PtsSkippedQueue queue, int32 pts);
void checkForWaiting(ChannelData *channel); void checkForWaiting(ChannelData *channel);
QMap<uint64, PtsSkippedQueue> _queue; const not_null<Main::Session*> _session;
QMap<uint64, MTPUpdate> _updateQueue; base::flat_map<uint64, PtsSkippedQueue> _queue;
QMap<uint64, MTPUpdates> _updatesQueue; base::flat_map<uint64, MTPUpdate> _updateQueue;
base::flat_map<uint64, MTPUpdates> _updatesQueue;
int32 _good = 0; int32 _good = 0;
int32 _last = 0; int32 _last = 0;
int32 _count = 0; int32 _count = 0;

View File

@ -906,6 +906,7 @@ void Session::startExport(const MTPInputPeer &singlePeer) {
} }
_export = std::make_unique<Export::Controller>(singlePeer); _export = std::make_unique<Export::Controller>(singlePeer);
_exportPanel = std::make_unique<Export::View::PanelController>( _exportPanel = std::make_unique<Export::View::PanelController>(
&session(),
_export.get()); _export.get());
_exportViewChanges.fire(_exportPanel.get()); _exportViewChanges.fire(_exportPanel.get());
@ -944,9 +945,9 @@ void Session::suggestStartExport() {
_session, _session,
[=] { suggestStartExport(); }); [=] { suggestStartExport(); });
} else if (_export) { } else if (_export) {
Export::View::ClearSuggestStart(); Export::View::ClearSuggestStart(&session());
} else { } else {
_exportSuggestion = Export::View::SuggestStart(); _exportSuggestion = Export::View::SuggestStart(&session());
} }
} }

View File

@ -170,23 +170,28 @@ rpl::producer<SparseIdsMergedSlice> SharedMediaMergedViewer(
std::move(createSimpleViewer)); std::move(createSimpleViewer));
} }
SharedMediaWithLastSlice::SharedMediaWithLastSlice(Key key) SharedMediaWithLastSlice::SharedMediaWithLastSlice(
not_null<Main::Session*> session,
Key key)
: SharedMediaWithLastSlice( : SharedMediaWithLastSlice(
session,
key, key,
SparseIdsMergedSlice(ViewerKey(key)), SparseIdsMergedSlice(ViewerKey(key)),
EndingSlice(key)) { EndingSlice(key)) {
} }
SharedMediaWithLastSlice::SharedMediaWithLastSlice( SharedMediaWithLastSlice::SharedMediaWithLastSlice(
not_null<Main::Session*> session,
Key key, Key key,
SparseIdsMergedSlice slice, SparseIdsMergedSlice slice,
std::optional<SparseIdsMergedSlice> ending) std::optional<SparseIdsMergedSlice> ending)
: _key(key) : _session(session)
, _key(key)
, _slice(std::move(slice)) , _slice(std::move(slice))
, _ending(std::move(ending)) , _ending(std::move(ending))
, _lastPhotoId(LastPeerPhotoId(key.peerId)) , _lastPhotoId(LastPeerPhotoId(session, key.peerId))
, _isolatedLastPhoto(_key.type == Type::ChatPhoto , _isolatedLastPhoto(_key.type == Type::ChatPhoto
? IsLastIsolated(_slice, _ending, _lastPhotoId) ? IsLastIsolated(session, _slice, _ending, _lastPhotoId)
: false) { : false) {
} }
@ -296,7 +301,7 @@ SharedMediaWithLastSlice::Value SharedMediaWithLastSlice::operator[](int index)
} }
return (index < _slice.size()) return (index < _slice.size())
? Value(_slice[index]) ? Value(_slice[index])
: Value(Auth().data().photo(*_lastPhotoId)); : Value(_session->data().photo(*_lastPhotoId));
} }
std::optional<int> SharedMediaWithLastSlice::distance( std::optional<int> SharedMediaWithLastSlice::distance(
@ -315,8 +320,9 @@ void SharedMediaWithLastSlice::reverse() {
} }
std::optional<PhotoId> SharedMediaWithLastSlice::LastPeerPhotoId( std::optional<PhotoId> SharedMediaWithLastSlice::LastPeerPhotoId(
not_null<Main::Session*> session,
PeerId peerId) { PeerId peerId) {
if (const auto peer = Auth().data().peerLoaded(peerId)) { if (const auto peer = session->data().peerLoaded(peerId)) {
return peer->userpicPhotoUnknown() return peer->userpicPhotoUnknown()
? std::nullopt ? std::nullopt
: base::make_optional(peer->userpicPhotoId()); : base::make_optional(peer->userpicPhotoId());
@ -325,6 +331,7 @@ std::optional<PhotoId> SharedMediaWithLastSlice::LastPeerPhotoId(
} }
std::optional<bool> SharedMediaWithLastSlice::IsLastIsolated( std::optional<bool> SharedMediaWithLastSlice::IsLastIsolated(
not_null<Main::Session*> session,
const SparseIdsMergedSlice &slice, const SparseIdsMergedSlice &slice,
const std::optional<SparseIdsMergedSlice> &ending, const std::optional<SparseIdsMergedSlice> &ending,
std::optional<PhotoId> lastPeerPhotoId) { std::optional<PhotoId> lastPeerPhotoId) {
@ -334,7 +341,7 @@ std::optional<bool> SharedMediaWithLastSlice::IsLastIsolated(
return false; return false;
} }
return LastFullMsgId(ending ? *ending : slice) return LastFullMsgId(ending ? *ending : slice)
| [](FullMsgId msgId) { return Auth().data().message(msgId); } | [&](FullMsgId msgId) { return session->data().message(msgId); }
| [](HistoryItem *item) { return item ? item->media() : nullptr; } | [](HistoryItem *item) { return item ? item->media() : nullptr; }
| [](Data::Media *media) { return media ? media->photo() : nullptr; } | [](Data::Media *media) { return media ? media->photo() : nullptr; }
| [](PhotoData *photo) { return photo ? photo->id : 0; } | [](PhotoData *photo) { return photo ? photo->id : 0; }
@ -367,6 +374,7 @@ rpl::producer<SharedMediaWithLastSlice> SharedMediaWithLastViewer(
limitAfter limitAfter
) | rpl::start_with_next([=](SparseIdsMergedSlice &&update) { ) | rpl::start_with_next([=](SparseIdsMergedSlice &&update) {
consumer.put_next(SharedMediaWithLastSlice( consumer.put_next(SharedMediaWithLastSlice(
session,
key, key,
std::move(update), std::move(update),
std::nullopt)); std::nullopt));
@ -391,6 +399,7 @@ rpl::producer<SharedMediaWithLastSlice> SharedMediaWithLastViewer(
SparseIdsMergedSlice &&viewer, SparseIdsMergedSlice &&viewer,
SparseIdsMergedSlice &&ending) { SparseIdsMergedSlice &&ending) {
consumer.put_next(SharedMediaWithLastSlice( consumer.put_next(SharedMediaWithLastSlice(
session,
key, key,
std::move(viewer), std::move(viewer),
std::move(ending))); std::move(ending)));

View File

@ -97,8 +97,11 @@ public:
}; };
SharedMediaWithLastSlice(Key key);
SharedMediaWithLastSlice( SharedMediaWithLastSlice(
not_null<Main::Session*> session,
Key key);
SharedMediaWithLastSlice(
not_null<Main::Session*> session,
Key key, Key key,
SparseIdsMergedSlice slice, SparseIdsMergedSlice slice,
std::optional<SparseIdsMergedSlice> ending); std::optional<SparseIdsMergedSlice> ending);
@ -137,8 +140,11 @@ private:
: std::nullopt; : std::nullopt;
} }
static std::optional<PhotoId> LastPeerPhotoId(PeerId peerId); static std::optional<PhotoId> LastPeerPhotoId(
not_null<Main::Session*> session,
PeerId peerId);
static std::optional<bool> IsLastIsolated( static std::optional<bool> IsLastIsolated(
not_null<Main::Session*> session,
const SparseIdsMergedSlice &slice, const SparseIdsMergedSlice &slice,
const std::optional<SparseIdsMergedSlice> &ending, const std::optional<SparseIdsMergedSlice> &ending,
std::optional<PhotoId> lastPeerPhotoId); std::optional<PhotoId> lastPeerPhotoId);
@ -175,6 +181,7 @@ private:
std::optional<int> skippedAfterImpl() const; std::optional<int> skippedAfterImpl() const;
std::optional<int> indexOfImpl(Value fullId) const; std::optional<int> indexOfImpl(Value fullId) const;
not_null<Main::Session*> _session;
Key _key; Key _key;
SparseIdsMergedSlice _slice; SparseIdsMergedSlice _slice;
std::optional<SparseIdsMergedSlice> _ending; std::optional<SparseIdsMergedSlice> _ending;

View File

@ -32,14 +32,18 @@ constexpr auto kSaveSettingsTimeout = crl::time(1000);
class SuggestBox : public Ui::BoxContent { class SuggestBox : public Ui::BoxContent {
public: public:
SuggestBox(QWidget*); SuggestBox(QWidget*, not_null<Main::Session*> session);
protected: protected:
void prepare() override; void prepare() override;
private:
const not_null<Main::Session*> _session;
}; };
SuggestBox::SuggestBox(QWidget*) { SuggestBox::SuggestBox(QWidget*, not_null<Main::Session*> session)
: _session(session) {
} }
void SuggestBox::prepare() { void SuggestBox::prepare() {
@ -47,7 +51,7 @@ void SuggestBox::prepare() {
addButton(tr::lng_box_ok(), [=] { addButton(tr::lng_box_ok(), [=] {
closeBox(); closeBox();
Auth().data().startExport(Local::ReadExportSettings().singlePeer); _session->data().startExport(Local::ReadExportSettings().singlePeer);
}); });
addButton(tr::lng_export_suggest_cancel(), [=] { closeBox(); }); addButton(tr::lng_export_suggest_cancel(), [=] { closeBox(); });
setCloseByOutsideClick(false); setCloseByOutsideClick(false);
@ -85,13 +89,15 @@ Environment PrepareEnvironment() {
return result; return result;
} }
QPointer<Ui::BoxContent> SuggestStart() { QPointer<Ui::BoxContent> SuggestStart(not_null<Main::Session*> session) {
ClearSuggestStart(); ClearSuggestStart(session);
return Ui::show(Box<SuggestBox>(), Ui::LayerOption::KeepOther).data(); return Ui::show(
Box<SuggestBox>(session),
Ui::LayerOption::KeepOther).data();
} }
void ClearSuggestStart() { void ClearSuggestStart(not_null<Main::Session*> session) {
Auth().data().clearExportSuggestion(); session->data().clearExportSuggestion();
auto settings = Local::ReadExportSettings(); auto settings = Local::ReadExportSettings();
if (settings.availableAt) { if (settings.availableAt) {
@ -100,33 +106,36 @@ void ClearSuggestStart() {
} }
} }
bool IsDefaultPath(const QString &path) { bool IsDefaultPath(not_null<Main::Session*> session, const QString &path) {
const auto check = [](const QString &value) { const auto check = [](const QString &value) {
const auto result = value.endsWith('/') const auto result = value.endsWith('/')
? value.mid(0, value.size() - 1) ? value.mid(0, value.size() - 1)
: value; : value;
return Platform::IsWindows() ? result.toLower() : result; return Platform::IsWindows() ? result.toLower() : result;
}; };
return (check(path) == check(File::DefaultDownloadPath())); return (check(path) == check(File::DefaultDownloadPath(session)));
} }
void ResolveSettings(Settings &settings) { void ResolveSettings(not_null<Main::Session*> session, Settings &settings) {
if (settings.path.isEmpty()) { if (settings.path.isEmpty()) {
settings.path = File::DefaultDownloadPath(); settings.path = File::DefaultDownloadPath(session);
settings.forceSubPath = true; settings.forceSubPath = true;
} else { } else {
settings.forceSubPath = IsDefaultPath(settings.path); settings.forceSubPath = IsDefaultPath(session, settings.path);
} }
if (!settings.onlySinglePeer()) { if (!settings.onlySinglePeer()) {
settings.singlePeerFrom = settings.singlePeerTill = 0; settings.singlePeerFrom = settings.singlePeerTill = 0;
} }
} }
PanelController::PanelController(not_null<Controller*> process) PanelController::PanelController(
: _process(process) not_null<Main::Session*> session,
not_null<Controller*> process)
: _session(session)
, _process(process)
, _settings(std::make_unique<Settings>(Local::ReadExportSettings())) , _settings(std::make_unique<Settings>(Local::ReadExportSettings()))
, _saveSettingsTimer([=] { saveSettings(); }) { , _saveSettingsTimer([=] { saveSettings(); }) {
ResolveSettings(*_settings); ResolveSettings(session, *_settings);
_process->state( _process->state(
) | rpl::start_with_next([=](State &&state) { ) | rpl::start_with_next([=](State &&state) {
@ -165,6 +174,7 @@ void PanelController::createPanel() {
void PanelController::showSettings() { void PanelController::showSettings() {
auto settings = base::make_unique_q<SettingsWidget>( auto settings = base::make_unique_q<SettingsWidget>(
_panel, _panel,
_session,
*_settings); *_settings);
settings->setShowBoxCallback([=](object_ptr<Ui::BoxContent> box) { settings->setShowBoxCallback([=](object_ptr<Ui::BoxContent> box) {
_panel->showBox( _panel->showBox(
@ -220,7 +230,7 @@ void PanelController::showError(const ApiErrorState &error) {
_settings->availableAt = base::unixtime::now() + seconds; _settings->availableAt = base::unixtime::now() + seconds;
_saveSettingsTimer.callOnce(kSaveSettingsTimeout); _saveSettingsTimer.callOnce(kSaveSettingsTimeout);
Auth().data().suggestStartExport(_settings->availableAt); _session->data().suggestStartExport(_settings->availableAt);
} else { } else {
showCriticalError("API Error happened :(\n" showCriticalError("API Error happened :(\n"
+ QString::number(error.data.code()) + ": " + error.data.type() + QString::number(error.data.code()) + ": " + error.data.type()
@ -273,7 +283,7 @@ void PanelController::showError(const QString &text) {
void PanelController::showProgress() { void PanelController::showProgress() {
_settings->availableAt = 0; _settings->availableAt = 0;
ClearSuggestStart(); ClearSuggestStart(_session);
_panel->setTitle(tr::lng_export_progress_title()); _panel->setTitle(tr::lng_export_progress_title());
@ -388,7 +398,7 @@ void PanelController::saveSettings() const {
return Platform::IsWindows() ? result.toLower() : result; return Platform::IsWindows() ? result.toLower() : result;
}; };
auto settings = *_settings; auto settings = *_settings;
if (check(settings.path) == check(File::DefaultDownloadPath())) { if (check(settings.path) == check(File::DefaultDownloadPath(_session))) {
settings.path = QString(); settings.path = QString();
} }
Local::WriteExportSettings(settings); Local::WriteExportSettings(settings);

View File

@ -17,6 +17,10 @@ class SeparatePanel;
class BoxContent; class BoxContent;
} // namespace Ui } // namespace Ui
namespace Main {
class Session;
} // namespace Main
namespace Export { namespace Export {
struct Environment; struct Environment;
@ -24,16 +28,18 @@ struct Environment;
namespace View { namespace View {
Environment PrepareEnvironment(); Environment PrepareEnvironment();
QPointer<Ui::BoxContent> SuggestStart(); QPointer<Ui::BoxContent> SuggestStart(not_null<Main::Session*> session);
void ClearSuggestStart(); void ClearSuggestStart(not_null<Main::Session*> session);
bool IsDefaultPath(const QString &path); bool IsDefaultPath(not_null<Main::Session*> session, const QString &path);
void ResolveSettings(Settings &settings); void ResolveSettings(not_null<Main::Session*> session, Settings &settings);
class Panel; class Panel;
class PanelController { class PanelController {
public: public:
PanelController(not_null<Controller*> process); PanelController(
not_null<Main::Session*> session,
not_null<Controller*> process);
~PanelController(); ~PanelController();
void activatePanel(); void activatePanel();
@ -63,7 +69,8 @@ private:
void saveSettings() const; void saveSettings() const;
not_null<Controller*> _process; const not_null<Main::Session*> _session;
const not_null<Controller*> _process;
std::unique_ptr<Settings> _settings; std::unique_ptr<Settings> _settings;
base::Timer _saveSettingsTimer; base::Timer _saveSettingsTimer;

View File

@ -36,7 +36,9 @@ namespace {
constexpr auto kMegabyte = 1024 * 1024; constexpr auto kMegabyte = 1024 * 1024;
[[nodiscard]] PeerId ReadPeerId(const MTPInputPeer &data) { [[nodiscard]] PeerId ReadPeerId(
not_null<Main::Session*> session,
const MTPInputPeer &data) {
return data.match([](const MTPDinputPeerUser &data) { return data.match([](const MTPDinputPeerUser &data) {
return peerFromUser(data.vuser_id().v); return peerFromUser(data.vuser_id().v);
}, [](const MTPDinputPeerUserFromMessage &data) { }, [](const MTPDinputPeerUserFromMessage &data) {
@ -47,8 +49,8 @@ constexpr auto kMegabyte = 1024 * 1024;
return peerFromChannel(data.vchannel_id().v); return peerFromChannel(data.vchannel_id().v);
}, [](const MTPDinputPeerChannelFromMessage &data) { }, [](const MTPDinputPeerChannelFromMessage &data) {
return peerFromChannel(data.vchannel_id().v); return peerFromChannel(data.vchannel_id().v);
}, [](const MTPDinputPeerSelf &data) { }, [&](const MTPDinputPeerSelf &data) {
return Auth().userPeerId(); return session->userPeerId();
}, [](const MTPDinputPeerEmpty &data) { }, [](const MTPDinputPeerEmpty &data) {
return PeerId(0); return PeerId(0);
}); });
@ -106,11 +108,15 @@ int SizeLimitByIndex(int index) {
return megabytes * kMegabyte; return megabytes * kMegabyte;
} }
SettingsWidget::SettingsWidget(QWidget *parent, Settings data) SettingsWidget::SettingsWidget(
QWidget *parent,
not_null<Main::Session*> session,
Settings data)
: RpWidget(parent) : RpWidget(parent)
, _singlePeerId(ReadPeerId(data.singlePeer)) , _session(session)
, _singlePeerId(ReadPeerId(session, data.singlePeer))
, _internal_data(std::move(data)) { , _internal_data(std::move(data)) {
ResolveSettings(_internal_data); ResolveSettings(session, _internal_data);
setupContent(); setupContent();
} }
@ -278,9 +284,9 @@ void SettingsWidget::addLocationLabel(
auto pathLink = value() | rpl::map([](const Settings &data) { auto pathLink = value() | rpl::map([](const Settings &data) {
return data.path; return data.path;
}) | rpl::distinct_until_changed( }) | rpl::distinct_until_changed(
) | rpl::map([](const QString &path) { ) | rpl::map([=](const QString &path) {
const auto text = IsDefaultPath(path) const auto text = IsDefaultPath(_session, path)
? QString("Downloads/Telegram Desktop") ? u"Downloads/"_q + File::DefaultDownloadPathFolder(_session)
: path; : path;
return Ui::Text::Link( return Ui::Text::Link(
QDir::toNativeSeparators(text), QDir::toNativeSeparators(text),
@ -326,9 +332,9 @@ void SettingsWidget::addFormatAndLocationLabel(
auto pathLink = value() | rpl::map([](const Settings &data) { auto pathLink = value() | rpl::map([](const Settings &data) {
return data.path; return data.path;
}) | rpl::distinct_until_changed( }) | rpl::distinct_until_changed(
) | rpl::map([](const QString &path) { ) | rpl::map([=](const QString &path) {
const auto text = IsDefaultPath(path) const auto text = IsDefaultPath(_session, path)
? u"Downloads/Telegram Desktop"_q ? u"Downloads/"_q + File::DefaultDownloadPathFolder(_session)
: path; : path;
return Ui::Text::Link( return Ui::Text::Link(
QDir::toNativeSeparators(text), QDir::toNativeSeparators(text),
@ -774,7 +780,7 @@ void SettingsWidget::chooseFolder() {
const auto callback = [=](QString &&result) { const auto callback = [=](QString &&result) {
changeData([&](Settings &data) { changeData([&](Settings &data) {
data.path = std::move(result); data.path = std::move(result);
data.forceSubPath = IsDefaultPath(data.path); data.forceSubPath = IsDefaultPath(_session, data.path);
}); });
}; };
FileDialog::GetFolder( FileDialog::GetFolder(

View File

@ -18,6 +18,10 @@ class ScrollArea;
class BoxContent; class BoxContent;
} // namespace Ui } // namespace Ui
namespace Main {
class Session;
} // namespace Main
namespace Export { namespace Export {
namespace View { namespace View {
@ -26,7 +30,10 @@ int SizeLimitByIndex(int index);
class SettingsWidget : public Ui::RpWidget { class SettingsWidget : public Ui::RpWidget {
public: public:
SettingsWidget(QWidget *parent, Settings data); SettingsWidget(
QWidget *parent,
not_null<Main::Session*> session,
Settings data);
rpl::producer<Settings> value() const; rpl::producer<Settings> value() const;
rpl::producer<Settings> changes() const; rpl::producer<Settings> changes() const;
@ -98,6 +105,7 @@ private:
template <typename Callback> template <typename Callback>
void changeData(Callback &&callback); void changeData(Callback &&callback);
const not_null<Main::Session*> _session;
PeerId _singlePeerId = 0; PeerId _singlePeerId = 0;
Fn<void(object_ptr<Ui::BoxContent>)> _showBoxCallback; Fn<void(object_ptr<Ui::BoxContent>)> _showBoxCallback;

View File

@ -58,8 +58,14 @@ void activateBotCommand(
not_null<const HistoryItem*> msg, not_null<const HistoryItem*> msg,
int row, int row,
int column) { int column) {
const auto button = HistoryMessageMarkupButton::Get(msg->fullId(), row, column); const auto button = HistoryMessageMarkupButton::Get(
if (!button) return; &msg->history()->owner(),
msg->fullId(),
row,
column);
if (!button) {
return;
}
using ButtonType = HistoryMessageMarkupButton::Type; using ButtonType = HistoryMessageMarkupButton::Type;
switch (button->type) { switch (button->type) {
@ -67,7 +73,11 @@ void activateBotCommand(
// Copy string before passing it to the sending method // Copy string before passing it to the sending method
// because the original button can be destroyed inside. // because the original button can be destroyed inside.
MsgId replyTo = (msg->id > 0) ? msg->id : 0; MsgId replyTo = (msg->id > 0) ? msg->id : 0;
sendBotCommand(msg->history()->peer, msg->fromOriginal()->asUser(), QString(button->text), replyTo); sendBotCommand(
msg->history()->peer,
msg->fromOriginal()->asUser(),
QString(button->text),
replyTo);
} break; } break;
case ButtonType::Callback: case ButtonType::Callback:
@ -98,7 +108,8 @@ void activateBotCommand(
case ButtonType::RequestLocation: { case ButtonType::RequestLocation: {
hideSingleUseKeyboard(msg); hideSingleUseKeyboard(msg);
Ui::show(Box<InformBox>(tr::lng_bot_share_location_unavailable(tr::now))); Ui::show(Box<InformBox>(
tr::lng_bot_share_location_unavailable(tr::now)));
} break; } break;
case ButtonType::RequestPhone: { case ButtonType::RequestPhone: {

View File

@ -243,9 +243,11 @@ TextWithEntities GenerateBannedChangeText(
return result; return result;
} }
auto GenerateUserString(MTPint userId) { auto GenerateUserString(
not_null<Main::Session*> session,
MTPint userId) {
// User name in "User name (@username)" format with entities. // User name in "User name (@username)" format with entities.
auto user = Auth().data().user(userId.v); auto user = session->data().user(userId.v);
auto name = TextWithEntities { user->name }; auto name = TextWithEntities { user->name };
auto entityData = QString::number(user->id) auto entityData = QString::number(user->id)
+ '.' + '.'
@ -283,10 +285,10 @@ auto GenerateParticipantChangeTextInner(
return tr::lng_admin_log_transferred( return tr::lng_admin_log_transferred(
tr::now, tr::now,
lt_user, lt_user,
GenerateUserString(data.vuser_id()), GenerateUserString(&channel->session(), data.vuser_id()),
Ui::Text::WithEntities); Ui::Text::WithEntities);
}, [&](const MTPDchannelParticipantAdmin &data) { }, [&](const MTPDchannelParticipantAdmin &data) {
auto user = GenerateUserString(data.vuser_id()); auto user = GenerateUserString(&channel->session(), data.vuser_id());
return GenerateAdminChangeText( return GenerateAdminChangeText(
channel, channel,
user, user,
@ -295,7 +297,7 @@ auto GenerateParticipantChangeTextInner(
? &oldParticipant->c_channelParticipantAdmin().vadmin_rights() ? &oldParticipant->c_channelParticipantAdmin().vadmin_rights()
: nullptr); : nullptr);
}, [&](const MTPDchannelParticipantBanned &data) { }, [&](const MTPDchannelParticipantBanned &data) {
auto user = GenerateUserString(data.vuser_id()); auto user = GenerateUserString(&channel->session(), data.vuser_id());
return GenerateBannedChangeText( return GenerateBannedChangeText(
user, user,
&data.vbanned_rights(), &data.vbanned_rights(),
@ -303,7 +305,7 @@ auto GenerateParticipantChangeTextInner(
? &oldParticipant->c_channelParticipantBanned().vbanned_rights() ? &oldParticipant->c_channelParticipantBanned().vbanned_rights()
: nullptr); : nullptr);
}, [&](const auto &data) { }, [&](const auto &data) {
auto user = GenerateUserString(data.vuser_id()); auto user = GenerateUserString(&channel->session(), data.vuser_id());
if (oldType == mtpc_channelParticipantAdmin) { if (oldType == mtpc_channelParticipantAdmin) {
return GenerateAdminChangeText( return GenerateAdminChangeText(
channel, channel,
@ -380,7 +382,7 @@ void GenerateItems(
const auto session = &history->session(); const auto session = &history->session();
const auto id = event.vid().v; const auto id = event.vid().v;
const auto from = Auth().data().user(event.vuser_id().v); const auto from = history->owner().user(event.vuser_id().v);
const auto channel = history->peer->asChannel(); const auto channel = history->peer->asChannel();
const auto &action = event.vaction(); const auto &action = event.vaction();
const auto date = event.vdate().v; const auto date = event.vdate().v;
@ -490,7 +492,7 @@ void GenerateItems(
auto createChangePhoto = [&](const MTPDchannelAdminLogEventActionChangePhoto &action) { auto createChangePhoto = [&](const MTPDchannelAdminLogEventActionChangePhoto &action) {
action.vnew_photo().match([&](const MTPDphoto &data) { action.vnew_photo().match([&](const MTPDphoto &data) {
auto photo = Auth().data().processPhoto(data); auto photo = history->owner().processPhoto(data);
auto text = (channel->isMegagroup() auto text = (channel->isMegagroup()
? tr::lng_admin_log_changed_photo_group ? tr::lng_admin_log_changed_photo_group
: tr::lng_admin_log_changed_photo_channel)( : tr::lng_admin_log_changed_photo_channel)(

View File

@ -38,8 +38,10 @@ const auto kPsaForwardedPrefix = "cloud_lng_forwarded_psa_";
} // namespace } // namespace
void HistoryMessageVia::create(UserId userId) { void HistoryMessageVia::create(
bot = Auth().data().user(userId); not_null<Data::Session*> owner,
UserId userId) {
bot = owner->user(userId);
maxWidth = st::msgServiceNameFont->width( maxWidth = st::msgServiceNameFont->width(
tr::lng_inline_bot_via(tr::now, lt_inline_bot, '@' + bot->username)); tr::lng_inline_bot_via(tr::now, lt_inline_bot, '@' + bot->username));
link = std::make_shared<LambdaClickHandler>([bot = this->bot] { link = std::make_shared<LambdaClickHandler>([bot = this->bot] {
@ -229,7 +231,9 @@ bool HistoryMessageReply::updateData(
if (!replyToMsg->Has<HistoryMessageForwarded>()) { if (!replyToMsg->Has<HistoryMessageForwarded>()) {
if (auto bot = replyToMsg->viaBot()) { if (auto bot = replyToMsg->viaBot()) {
replyToVia = std::make_unique<HistoryMessageVia>(); replyToVia = std::make_unique<HistoryMessageVia>();
replyToVia->create(peerToUser(bot->id)); replyToVia->create(
&holder->history()->owner(),
peerToUser(bot->id));
} }
} }
} else if (force) { } else if (force) {
@ -419,7 +423,11 @@ QString ReplyMarkupClickHandler::copyToClipboardContextItemText() const {
// Note: it is possible that we will point to the different button // Note: it is possible that we will point to the different button
// than the one was used when constructing the handler, but not a big deal. // than the one was used when constructing the handler, but not a big deal.
const HistoryMessageMarkupButton *ReplyMarkupClickHandler::getButton() const { const HistoryMessageMarkupButton *ReplyMarkupClickHandler::getButton() const {
return HistoryMessageMarkupButton::Get(_itemId, _row, _column); return HistoryMessageMarkupButton::Get(
&Auth().data(),
_itemId,
_row,
_column);
} }
void ReplyMarkupClickHandler::onClickImpl() const { void ReplyMarkupClickHandler::onClickImpl() const {
@ -788,10 +796,11 @@ HistoryMessageMarkupButton::HistoryMessageMarkupButton(
} }
HistoryMessageMarkupButton *HistoryMessageMarkupButton::Get( HistoryMessageMarkupButton *HistoryMessageMarkupButton::Get(
not_null<Data::Session*> owner,
FullMsgId itemId, FullMsgId itemId,
int row, int row,
int column) { int column) {
if (const auto item = Auth().data().message(itemId)) { if (const auto item = owner->message(itemId)) {
if (const auto markup = item->Get<HistoryMessageReplyMarkup>()) { if (const auto markup = item->Get<HistoryMessageReplyMarkup>()) {
if (row < markup->rows.size()) { if (row < markup->rows.size()) {
auto &buttons = markup->rows[row]; auto &buttons = markup->rows[row];

View File

@ -13,13 +13,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
struct WebPageData; struct WebPageData;
namespace Data {
class Session;
} // namespace Data
namespace HistoryView { namespace HistoryView {
class Element; class Element;
class Document; class Document;
} // namespace HistoryView } // namespace HistoryView
struct HistoryMessageVia : public RuntimeComponent<HistoryMessageVia, HistoryItem> { struct HistoryMessageVia : public RuntimeComponent<HistoryMessageVia, HistoryItem> {
void create(UserId userId); void create(not_null<Data::Session*> owner, UserId userId);
void resize(int32 availw) const; void resize(int32 availw) const;
UserData *bot = nullptr; UserData *bot = nullptr;
@ -181,6 +185,7 @@ struct HistoryMessageMarkupButton {
int32 buttonId = 0); int32 buttonId = 0);
static HistoryMessageMarkupButton *Get( static HistoryMessageMarkupButton *Get(
not_null<Data::Session*> owner,
FullMsgId itemId, FullMsgId itemId,
int row, int row,
int column); int column);

View File

@ -836,7 +836,7 @@ void HistoryMessage::createComponents(const CreateConfig &config) {
} }
} }
if (const auto via = Get<HistoryMessageVia>()) { if (const auto via = Get<HistoryMessageVia>()) {
via->create(config.viaBotId); via->create(&history()->owner(), config.viaBotId);
} }
if (const auto views = Get<HistoryMessageViews>()) { if (const auto views = Get<HistoryMessageViews>()) {
views->_views = config.viewsCount; views->_views = config.viewsCount;

View File

@ -3644,11 +3644,14 @@ void HistoryWidget::botCallbackDone(
const MTPmessages_BotCallbackAnswer &answer, const MTPmessages_BotCallbackAnswer &answer,
mtpRequestId req) { mtpRequestId req) {
const auto item = session().data().message(info.msgId); const auto item = session().data().message(info.msgId);
if (const auto button = HistoryMessageMarkupButton::Get(info.msgId, info.row, info.col)) { const auto button = HistoryMessageMarkupButton::Get(
if (button->requestId == req) { &session().data(),
button->requestId = 0; info.msgId,
session().data().requestItemRepaint(item); info.row,
} info.col);
if (button && button->requestId == req) {
button->requestId = 0;
session().data().requestItemRepaint(item);
} }
answer.match([&](const MTPDmessages_botCallbackAnswer &data) { answer.match([&](const MTPDmessages_botCallbackAnswer &data) {
if (const auto message = data.vmessage()) { if (const auto message = data.vmessage()) {
@ -3677,11 +3680,14 @@ bool HistoryWidget::botCallbackFail(
const RPCError &error, const RPCError &error,
mtpRequestId req) { mtpRequestId req) {
// show error? // show error?
if (const auto button = HistoryMessageMarkupButton::Get(info.msgId, info.row, info.col)) { const auto button = HistoryMessageMarkupButton::Get(
if (button->requestId == req) { &session().data(),
button->requestId = 0; info.msgId,
session().data().requestItemRepaint(session().data().message(info.msgId)); info.row,
} info.col);
if (button && button->requestId == req) {
button->requestId = 0;
session().data().requestItemRepaint(session().data().message(info.msgId));
} }
return true; return true;
} }

View File

@ -386,6 +386,7 @@ MainWidget::MainWidget(
, _history(this, _controller) , _history(this, _controller)
, _playerPlaylist(this, _controller) , _playerPlaylist(this, _controller)
, _noUpdatesTimer([=] { sendPing(); }) , _noUpdatesTimer([=] { sendPing(); })
, _ptsWaiter(&controller->session())
, _byPtsTimer([=] { getDifferenceByPts(); }) , _byPtsTimer([=] { getDifferenceByPts(); })
, _bySeqTimer([=] { getDifference(); }) , _bySeqTimer([=] { getDifference(); })
, _byMinChannelTimer([=] { getDifference(); }) , _byMinChannelTimer([=] { getDifference(); })
@ -1095,8 +1096,8 @@ void MainWidget::createPlayer() {
) | rpl::start_with_next( ) | rpl::start_with_next(
[this] { playerHeightUpdated(); }, [this] { playerHeightUpdated(); },
_player->lifetime()); _player->lifetime());
_player->entity()->setCloseCallback([this] { closeBothPlayers(); }); _player->entity()->setCloseCallback([=] { closeBothPlayers(); });
_playerVolume.create(this); _playerVolume.create(this, _controller);
_player->entity()->volumeWidgetCreated(_playerVolume); _player->entity()->volumeWidgetCreated(_playerVolume);
orderWidgets(); orderWidgets();
if (_a_show.animating()) { if (_a_show.animating()) {

View File

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/object_ptr.h" #include "base/object_ptr.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "window/window_session_controller.h"
#include "facades.h" #include "facades.h"
#include "app.h" #include "app.h"
#include "styles/style_media_player.h" #include "styles/style_media_player.h"
@ -23,7 +24,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Media { namespace Media {
namespace Player { namespace Player {
VolumeController::VolumeController(QWidget *parent) VolumeController::VolumeController(
QWidget *parent,
not_null<Window::SessionController*> controller)
: TWidget(parent) : TWidget(parent)
, _slider(this, st::mediaPlayerPanelPlayback) { , _slider(this, st::mediaPlayerPanelPlayback) {
_slider->setMoveByWheel(true); _slider->setMoveByWheel(true);
@ -35,7 +38,7 @@ VolumeController::VolumeController(QWidget *parent)
Global::SetRememberedSongVolume(volume); Global::SetRememberedSongVolume(volume);
} }
applyVolumeChange(volume); applyVolumeChange(volume);
Auth().saveSettingsDelayed(); controller->session().saveSettingsDelayed();
}); });
subscribe(Global::RefSongVolumeChanged(), [this] { subscribe(Global::RefSongVolumeChanged(), [this] {
if (!_slider->isChanging()) { if (!_slider->isChanging()) {
@ -73,9 +76,11 @@ void VolumeController::applyVolumeChange(float64 volume) {
} }
} }
VolumeWidget::VolumeWidget(QWidget *parent) VolumeWidget::VolumeWidget(
QWidget *parent,
not_null<Window::SessionController*> controller)
: RpWidget(parent) : RpWidget(parent)
, _controller(this) { , _controller(this, controller) {
hide(); hide();
_controller->setIsVertical(true); _controller->setIsVertical(true);

View File

@ -18,12 +18,18 @@ class IconButton;
class MediaSlider; class MediaSlider;
} // namespace Ui } // namespace Ui
namespace Window {
class SessionController;
} // namespace Window
namespace Media { namespace Media {
namespace Player { namespace Player {
class VolumeController : public TWidget, private base::Subscriber { class VolumeController : public TWidget, private base::Subscriber {
public: public:
VolumeController(QWidget *parent); VolumeController(
QWidget *parent,
not_null<Window::SessionController*> controller);
void setIsVertical(bool vertical); void setIsVertical(bool vertical);
@ -42,7 +48,9 @@ class VolumeWidget : public Ui::RpWidget {
Q_OBJECT Q_OBJECT
public: public:
VolumeWidget(QWidget *parent); VolumeWidget(
QWidget *parent,
not_null<Window::SessionController*> controller);
bool overlaps(const QRect &globalRect); bool overlaps(const QRect &globalRect);

View File

@ -57,7 +57,10 @@ Data::FileOrigin ComputeFileOrigin(const Key &key, const Context &context) {
}); });
} }
Context ComputeContext(const SharedMediaWithLastSlice &slice, int index) { Context ComputeContext(
not_null<Main::Session*> session,
const SharedMediaWithLastSlice &slice,
int index) {
Expects(index >= 0 && index < slice.size()); Expects(index >= 0 && index < slice.size());
const auto value = slice[index]; const auto value = slice[index];
@ -67,7 +70,7 @@ Context ComputeContext(const SharedMediaWithLastSlice &slice, int index) {
} }
return std::nullopt; return std::nullopt;
} else if (const auto msgId = base::get_if<FullMsgId>(&value)) { } else if (const auto msgId = base::get_if<FullMsgId>(&value)) {
if (const auto item = Auth().data().message(*msgId)) { if (const auto item = session->data().message(*msgId)) {
if (!item->toHistoryMessage()) { if (!item->toHistoryMessage()) {
return item->history()->peer->id; return item->history()->peer->id;
} else if (const auto groupId = item->groupId()) { } else if (const auto groupId = item->groupId()) {
@ -79,11 +82,17 @@ Context ComputeContext(const SharedMediaWithLastSlice &slice, int index) {
Unexpected("Variant in ComputeContext(SharedMediaWithLastSlice::Value)"); Unexpected("Variant in ComputeContext(SharedMediaWithLastSlice::Value)");
} }
Context ComputeContext(const UserPhotosSlice &slice, int index) { Context ComputeContext(
not_null<Main::Session*> session,
const UserPhotosSlice &slice,
int index) {
return peerFromUser(slice.key().userId); return peerFromUser(slice.key().userId);
} }
Context ComputeContext(const GroupThumbs::CollageSlice &slice, int index) { Context ComputeContext(
not_null<Main::Session*> session,
const GroupThumbs::CollageSlice &slice,
int index) {
return slice.context; return slice.context;
} }
@ -96,7 +105,7 @@ Key ComputeKey(const SharedMediaWithLastSlice &slice, int index) {
} else if (const auto msgId = base::get_if<FullMsgId>(&value)) { } else if (const auto msgId = base::get_if<FullMsgId>(&value)) {
return *msgId; return *msgId;
} }
Unexpected("Variant in ComputeContext(SharedMediaWithLastSlice::Value)"); Unexpected("Variant in ComputeKey(SharedMediaWithLastSlice::Value)");
} }
Key ComputeKey(const UserPhotosSlice &slice, int index) { Key ComputeKey(const UserPhotosSlice &slice, int index) {
@ -410,8 +419,9 @@ int GroupThumbs::CollageSlice::size() const {
return data->items.size(); return data->items.size();
} }
GroupThumbs::GroupThumbs(Context context) GroupThumbs::GroupThumbs(not_null<Main::Session*> session, Context context)
: _context(context) { : _session(session)
, _context(context) {
} }
void GroupThumbs::updateContext(Context context) { void GroupThumbs::updateContext(Context context) {
@ -423,11 +433,12 @@ void GroupThumbs::updateContext(Context context) {
template <typename Slice> template <typename Slice>
void GroupThumbs::RefreshFromSlice( void GroupThumbs::RefreshFromSlice(
not_null<Main::Session*> session,
std::unique_ptr<GroupThumbs> &instance, std::unique_ptr<GroupThumbs> &instance,
const Slice &slice, const Slice &slice,
int index, int index,
int availableWidth) { int availableWidth) {
const auto context = ComputeContext(slice, index); const auto context = ComputeContext(session, slice, index);
if (instance) { if (instance) {
instance->updateContext(context); instance->updateContext(context);
} }
@ -441,7 +452,7 @@ void GroupThumbs::RefreshFromSlice(
const auto from = [&] { const auto from = [&] {
const auto edge = std::max(index - limit, 0); const auto edge = std::max(index - limit, 0);
for (auto result = index; result != edge; --result) { for (auto result = index; result != edge; --result) {
if (ComputeContext(slice, result - 1) != context) { if (ComputeContext(session, slice, result - 1) != context) {
return result; return result;
} }
} }
@ -450,7 +461,7 @@ void GroupThumbs::RefreshFromSlice(
const auto till = [&] { const auto till = [&] {
const auto edge = std::min(index + limit + 1, slice.size()); const auto edge = std::min(index + limit + 1, slice.size());
for (auto result = index + 1; result != edge; ++result) { for (auto result = index + 1; result != edge; ++result) {
if (ComputeContext(slice, result) != context) { if (ComputeContext(session, slice, result) != context) {
return result; return result;
} }
} }
@ -458,7 +469,7 @@ void GroupThumbs::RefreshFromSlice(
}(); }();
if (from + 1 < till) { if (from + 1 < till) {
if (!instance) { if (!instance) {
instance = std::make_unique<GroupThumbs>(context); instance = std::make_unique<GroupThumbs>(session, context);
} }
instance->fillItems(slice, from, index, till); instance->fillItems(slice, from, index, till);
instance->resizeToWidth(availableWidth); instance->resizeToWidth(availableWidth);
@ -554,10 +565,10 @@ void GroupThumbs::animatePreviouslyAlive(
auto GroupThumbs::createThumb(Key key) auto GroupThumbs::createThumb(Key key)
-> std::unique_ptr<Thumb> { -> std::unique_ptr<Thumb> {
if (const auto photoId = base::get_if<PhotoId>(&key)) { if (const auto photoId = base::get_if<PhotoId>(&key)) {
const auto photo = Auth().data().photo(*photoId); const auto photo = _session->data().photo(*photoId);
return createThumb(key, photo); return createThumb(key, photo);
} else if (const auto msgId = base::get_if<FullMsgId>(&key)) { } else if (const auto msgId = base::get_if<FullMsgId>(&key)) {
if (const auto item = Auth().data().message(*msgId)) { if (const auto item = _session->data().message(*msgId)) {
if (const auto media = item->media()) { if (const auto media = item->media()) {
if (const auto photo = media->photo()) { if (const auto photo = media->photo()) {
return createThumb(key, photo); return createThumb(key, photo);
@ -569,7 +580,7 @@ auto GroupThumbs::createThumb(Key key)
return createThumb(key, nullptr); return createThumb(key, nullptr);
} else if (const auto collageKey = base::get_if<CollageKey>(&key)) { } else if (const auto collageKey = base::get_if<CollageKey>(&key)) {
if (const auto itemId = base::get_if<FullMsgId>(&_context)) { if (const auto itemId = base::get_if<FullMsgId>(&_context)) {
if (const auto item = Auth().data().message(*itemId)) { if (const auto item = _session->data().message(*itemId)) {
if (const auto media = item->media()) { if (const auto media = item->media()) {
if (const auto page = media->webpage()) { if (const auto page = media->webpage()) {
return createThumb( return createThumb(
@ -651,27 +662,30 @@ void GroupThumbs::markCacheStale() {
} }
void GroupThumbs::Refresh( void GroupThumbs::Refresh(
not_null<Main::Session*> session,
std::unique_ptr<GroupThumbs> &instance, std::unique_ptr<GroupThumbs> &instance,
const SharedMediaWithLastSlice &slice, const SharedMediaWithLastSlice &slice,
int index, int index,
int availableWidth) { int availableWidth) {
RefreshFromSlice(instance, slice, index, availableWidth); RefreshFromSlice(session, instance, slice, index, availableWidth);
} }
void GroupThumbs::Refresh( void GroupThumbs::Refresh(
not_null<Main::Session*> session,
std::unique_ptr<GroupThumbs> &instance, std::unique_ptr<GroupThumbs> &instance,
const UserPhotosSlice &slice, const UserPhotosSlice &slice,
int index, int index,
int availableWidth) { int availableWidth) {
RefreshFromSlice(instance, slice, index, availableWidth); RefreshFromSlice(session, instance, slice, index, availableWidth);
} }
void GroupThumbs::Refresh( void GroupThumbs::Refresh(
not_null<Main::Session*> session,
std::unique_ptr<GroupThumbs> &instance, std::unique_ptr<GroupThumbs> &instance,
const CollageSlice &slice, const CollageSlice &slice,
int index, int index,
int availableWidth) { int availableWidth) {
RefreshFromSlice(instance, slice, index, availableWidth); RefreshFromSlice(session, instance, slice, index, availableWidth);
} }
void GroupThumbs::clear() { void GroupThumbs::clear() {

View File

@ -15,6 +15,10 @@ class SharedMediaWithLastSlice;
class UserPhotosSlice; class UserPhotosSlice;
struct WebPageCollage; struct WebPageCollage;
namespace Main {
class Session;
} // namespace Main
namespace Media { namespace Media {
namespace View { namespace View {
@ -36,16 +40,19 @@ public:
using Key = base::variant<PhotoId, FullMsgId, CollageKey>; using Key = base::variant<PhotoId, FullMsgId, CollageKey>;
static void Refresh( static void Refresh(
not_null<Main::Session*> session,
std::unique_ptr<GroupThumbs> &instance, std::unique_ptr<GroupThumbs> &instance,
const SharedMediaWithLastSlice &slice, const SharedMediaWithLastSlice &slice,
int index, int index,
int availableWidth); int availableWidth);
static void Refresh( static void Refresh(
not_null<Main::Session*> session,
std::unique_ptr<GroupThumbs> &instance, std::unique_ptr<GroupThumbs> &instance,
const UserPhotosSlice &slice, const UserPhotosSlice &slice,
int index, int index,
int availableWidth); int availableWidth);
static void Refresh( static void Refresh(
not_null<Main::Session*> session,
std::unique_ptr<GroupThumbs> &instance, std::unique_ptr<GroupThumbs> &instance,
const CollageSlice &slice, const CollageSlice &slice,
int index, int index,
@ -78,7 +85,7 @@ public:
MessageGroupId, MessageGroupId,
FullMsgId>; FullMsgId>;
GroupThumbs(Context context); GroupThumbs(not_null<Main::Session*> session, Context context);
~GroupThumbs(); ~GroupThumbs();
private: private:
@ -86,6 +93,7 @@ private:
template <typename Slice> template <typename Slice>
static void RefreshFromSlice( static void RefreshFromSlice(
not_null<Main::Session*> session,
std::unique_ptr<GroupThumbs> &instance, std::unique_ptr<GroupThumbs> &instance,
const Slice &slice, const Slice &slice,
int index, int index,
@ -115,6 +123,7 @@ private:
void animatePreviouslyAlive(const std::vector<not_null<Thumb*>> &old); void animatePreviouslyAlive(const std::vector<not_null<Thumb*>> &old);
void startDelayedAnimation(); void startDelayedAnimation();
const not_null<Main::Session*> _session;
Context _context; Context _context;
bool _waitingForAnimationStart = true; bool _waitingForAnimationStart = true;
Ui::Animations::Simple _animation; Ui::Animations::Simple _animation;

View File

@ -554,7 +554,9 @@ void OverlayWidget::changingMsgId(not_null<HistoryItem*> row, MsgId newId) {
} }
void OverlayWidget::updateDocSize() { void OverlayWidget::updateDocSize() {
if (!_document || !documentBubbleShown()) return; if (!_document || !documentBubbleShown()) {
return;
}
if (_document->loading()) { if (_document->loading()) {
quint64 ready = _document->loadOffset(), total = _document->size; quint64 ready = _document->loadOffset(), total = _document->size;
@ -646,7 +648,9 @@ void OverlayWidget::updateControls() {
const auto dNow = QDateTime::currentDateTime(); const auto dNow = QDateTime::currentDateTime();
const auto d = [&] { const auto d = [&] {
if (const auto item = Auth().data().message(_msgid)) { if (!_session) {
return dNow;
} else if (const auto item = _session->data().message(_msgid)) {
return ItemDateTime(item); return ItemDateTime(item);
} else if (_photo) { } else if (_photo) {
return base::unixtime::parse(_photo->date); return base::unixtime::parse(_photo->date);
@ -752,10 +756,13 @@ void OverlayWidget::updateActions() {
if (_canForwardItem) { if (_canForwardItem) {
_actions.push_back({ tr::lng_mediaview_forward(tr::now), SLOT(onForward()) }); _actions.push_back({ tr::lng_mediaview_forward(tr::now), SLOT(onForward()) });
} }
auto canDelete = [&] { const auto canDelete = [&] {
if (_canDeleteItem) { if (_canDeleteItem) {
return true; return true;
} else if (!_msgid && _photo && _user && _user == Auth().user()) { } else if (!_msgid
&& _photo
&& _user
&& _user == _user->session().user()) {
return _userPhotosData && _fullIndex && _fullCount; return _userPhotosData && _fullIndex && _fullCount;
} else if (_photo && _photo->peer && _photo->peer->userpicPhotoId() == _photo->id) { } else if (_photo && _photo->peer && _photo->peer->userpicPhotoId() == _photo->id) {
if (auto chat = _photo->peer->asChat()) { if (auto chat = _photo->peer->asChat()) {
@ -1096,6 +1103,7 @@ void OverlayWidget::clearData() {
_pip = nullptr; _pip = nullptr;
_fullScreenVideo = false; _fullScreenVideo = false;
_caption.clear(); _caption.clear();
_session = nullptr;
} }
OverlayWidget::~OverlayWidget() { OverlayWidget::~OverlayWidget() {
@ -1224,7 +1232,10 @@ void OverlayWidget::onScreenResized(int screen) {
} }
void OverlayWidget::onToMessage() { void OverlayWidget::onToMessage() {
if (const auto item = Auth().data().message(_msgid)) { if (!_session) {
return;
}
if (const auto item = _session->data().message(_msgid)) {
close(); close();
Ui::showPeerHistoryAtItem(item); Ui::showPeerHistoryAtItem(item);
} }
@ -1263,7 +1274,14 @@ void OverlayWidget::onSaveAs() {
filter = mimeType.filterString() + qsl(";;") + FileDialog::AllFilesFilter(); filter = mimeType.filterString() + qsl(";;") + FileDialog::AllFilesFilter();
} }
file = FileNameForSave(tr::lng_save_file(tr::now), filter, qsl("doc"), name, true, alreadyDir); file = FileNameForSave(
_session,
tr::lng_save_file(tr::now),
filter,
qsl("doc"),
name,
true,
alreadyDir);
if (!file.isEmpty() && file != location.name()) { if (!file.isEmpty() && file != location.name()) {
if (bytes.isEmpty()) { if (bytes.isEmpty()) {
QFile(file).remove(); QFile(file).remove();
@ -1319,7 +1337,7 @@ void OverlayWidget::onDocClick() {
DocumentOpenClickHandler::Open( DocumentOpenClickHandler::Open(
fileOrigin(), fileOrigin(),
_document, _document,
Auth().data().message(_msgid)); _document->owner().message(_msgid));
if (_document->loading() && !_radial.animating()) { if (_document->loading() && !_radial.animating()) {
_radial.start(_documentMedia->progress()); _radial.start(_documentMedia->progress());
} }
@ -1331,13 +1349,17 @@ PeerData *OverlayWidget::ui_getPeerForMouseAction() {
} }
void OverlayWidget::onDownload() { void OverlayWidget::onDownload() {
if (!_photo && !_document) {
return;
}
if (Global::AskDownloadPath()) { if (Global::AskDownloadPath()) {
return onSaveAs(); return onSaveAs();
} }
QString path; QString path;
const auto session = _photo ? &_photo->session() : &_document->session();
if (Global::DownloadPath().isEmpty()) { if (Global::DownloadPath().isEmpty()) {
path = File::DefaultDownloadPath(); path = File::DefaultDownloadPath(session);
} else if (Global::DownloadPath() == qsl("tmp")) { } else if (Global::DownloadPath() == qsl("tmp")) {
path = cTempDir(); path = cTempDir();
} else { } else {
@ -1418,7 +1440,10 @@ void OverlayWidget::onShowInFolder() {
} }
void OverlayWidget::onForward() { void OverlayWidget::onForward() {
auto item = Auth().data().message(_msgid); if (!_session) {
return;
}
const auto item = _session->data().message(_msgid);
if (!item || !IsServerMsgId(item->id) || item->serviceMsg()) { if (!item || !IsServerMsgId(item->id) || item->serviceMsg()) {
return; return;
} }
@ -1430,6 +1455,11 @@ void OverlayWidget::onForward() {
} }
void OverlayWidget::onDelete() { void OverlayWidget::onDelete() {
const auto session = _session;
if (!session) {
return;
}
close(); close();
const auto deletingPeerPhoto = [this] { const auto deletingPeerPhoto = [this] {
if (!_msgid) { if (!_msgid) {
@ -1445,7 +1475,7 @@ void OverlayWidget::onDelete() {
if (deletingPeerPhoto()) { if (deletingPeerPhoto()) {
App::main()->deletePhotoLayer(_photo); App::main()->deletePhotoLayer(_photo);
} else if (const auto item = Auth().data().message(_msgid)) { } else if (const auto item = session->data().message(_msgid)) {
const auto suggestModerateActions = true; const auto suggestModerateActions = true;
Ui::show(Box<DeleteMessagesBox>(item, suggestModerateActions)); Ui::show(Box<DeleteMessagesBox>(item, suggestModerateActions));
} }
@ -1474,13 +1504,20 @@ void OverlayWidget::onCopy() {
} }
void OverlayWidget::onAttachedStickers() { void OverlayWidget::onAttachedStickers() {
const auto session = _session;
if (!session) {
return;
}
close(); close();
Auth().api().requestAttachedStickerSets(_photo); session->api().requestAttachedStickerSets(_photo);
} }
std::optional<OverlayWidget::SharedMediaType> OverlayWidget::sharedMediaType() const { auto OverlayWidget::sharedMediaType() const
-> std::optional<SharedMediaType> {
using Type = SharedMediaType; using Type = SharedMediaType;
if (const auto item = Auth().data().message(_msgid)) { if (!_session) {
return std::nullopt;
} else if (const auto item = _session->data().message(_msgid)) {
if (const auto media = item->media()) { if (const auto media = item->media()) {
if (media->webpage()) { if (media->webpage()) {
return std::nullopt; return std::nullopt;
@ -1503,8 +1540,12 @@ std::optional<OverlayWidget::SharedMediaType> OverlayWidget::sharedMediaType() c
return std::nullopt; return std::nullopt;
} }
std::optional<OverlayWidget::SharedMediaKey> OverlayWidget::sharedMediaKey() const { auto OverlayWidget::sharedMediaKey() const -> std::optional<SharedMediaKey> {
if (!_msgid && _peer && !_user && _photo && _peer->userpicPhotoId() == _photo->id) { if (!_msgid
&& _peer
&& !_user
&& _photo
&& _peer->userpicPhotoId() == _photo->id) {
return SharedMediaKey { return SharedMediaKey {
_history->peer->id, _history->peer->id,
_migrated ? _migrated->peer->id : 0, _migrated ? _migrated->peer->id : 0,
@ -1689,7 +1730,9 @@ void OverlayWidget::handleUserPhotosUpdate(UserPhotosSlice &&update) {
} }
std::optional<OverlayWidget::CollageKey> OverlayWidget::collageKey() const { std::optional<OverlayWidget::CollageKey> OverlayWidget::collageKey() const {
if (const auto item = Auth().data().message(_msgid)) { if (!_session) {
return std::nullopt;
} else if (const auto item = _session->data().message(_msgid)) {
if (const auto media = item->media()) { if (const auto media = item->media()) {
if (const auto page = media->webpage()) { if (const auto page = media->webpage()) {
for (const auto &item : page->collage.items) { for (const auto &item : page->collage.items) {
@ -1735,7 +1778,7 @@ void OverlayWidget::validateCollage() {
if (const auto key = collageKey()) { if (const auto key = collageKey()) {
_collage = std::make_unique<Collage>(*key); _collage = std::make_unique<Collage>(*key);
_collageData = WebPageCollage(); _collageData = WebPageCollage();
if (const auto item = Auth().data().message(_msgid)) { if (const auto item = _session->data().message(_msgid)) {
if (const auto media = item->media()) { if (const auto media = item->media()) {
if (const auto page = media->webpage()) { if (const auto page = media->webpage()) {
_collageData = page->collage; _collageData = page->collage;
@ -1816,18 +1859,21 @@ void OverlayWidget::refreshGroupThumbs() {
const auto existed = (_groupThumbs != nullptr); const auto existed = (_groupThumbs != nullptr);
if (_index && _sharedMediaData) { if (_index && _sharedMediaData) {
View::GroupThumbs::Refresh( View::GroupThumbs::Refresh(
_session,
_groupThumbs, _groupThumbs,
*_sharedMediaData, *_sharedMediaData,
*_index, *_index,
_groupThumbsAvailableWidth); _groupThumbsAvailableWidth);
} else if (_index && _userPhotosData) { } else if (_index && _userPhotosData) {
View::GroupThumbs::Refresh( View::GroupThumbs::Refresh(
_session,
_groupThumbs, _groupThumbs,
*_userPhotosData, *_userPhotosData,
*_index, *_index,
_groupThumbsAvailableWidth); _groupThumbsAvailableWidth);
} else if (_index && _collageData) { } else if (_index && _collageData) {
View::GroupThumbs::Refresh( View::GroupThumbs::Refresh(
_session,
_groupThumbs, _groupThumbs,
{ _msgid, &*_collageData }, { _msgid, &*_collageData },
*_index, *_index,
@ -1859,7 +1905,7 @@ void OverlayWidget::initGroupThumbs() {
) | rpl::start_with_next([this](View::GroupThumbs::Key key) { ) | rpl::start_with_next([this](View::GroupThumbs::Key key) {
using CollageKey = View::GroupThumbs::CollageKey; using CollageKey = View::GroupThumbs::CollageKey;
if (const auto photoId = base::get_if<PhotoId>(&key)) { if (const auto photoId = base::get_if<PhotoId>(&key)) {
const auto photo = Auth().data().photo(*photoId); const auto photo = _session->data().photo(*photoId);
moveToEntity({ photo, nullptr }); moveToEntity({ photo, nullptr });
} else if (const auto itemId = base::get_if<FullMsgId>(&key)) { } else if (const auto itemId = base::get_if<FullMsgId>(&key)) {
moveToEntity(entityForItemId(*itemId)); moveToEntity(entityForItemId(*itemId));
@ -1894,6 +1940,8 @@ void OverlayWidget::clearControlsState() {
} }
void OverlayWidget::showPhoto(not_null<PhotoData*> photo, HistoryItem *context) { void OverlayWidget::showPhoto(not_null<PhotoData*> photo, HistoryItem *context) {
_session = &photo->session();
if (context) { if (context) {
setContext(context); setContext(context);
} else { } else {
@ -1910,6 +1958,8 @@ void OverlayWidget::showPhoto(not_null<PhotoData*> photo, HistoryItem *context)
} }
void OverlayWidget::showPhoto(not_null<PhotoData*> photo, not_null<PeerData*> context) { void OverlayWidget::showPhoto(not_null<PhotoData*> photo, not_null<PeerData*> context) {
_session = &photo->session();
setContext(context); setContext(context);
clearControlsState(); clearControlsState();
@ -1938,6 +1988,8 @@ void OverlayWidget::showDocument(
HistoryItem *context, HistoryItem *context,
const Data::CloudTheme &cloud, const Data::CloudTheme &cloud,
bool continueStreaming) { bool continueStreaming) {
_session = &document->session();
if (context) { if (context) {
setContext(context); setContext(context);
} else { } else {
@ -1997,10 +2049,10 @@ void OverlayWidget::destroyThemePreview() {
} }
void OverlayWidget::redisplayContent() { void OverlayWidget::redisplayContent() {
if (isHidden()) { if (isHidden() || !_session) {
return; return;
} }
const auto item = Auth().data().message(_msgid); const auto item = _session->data().message(_msgid);
if (_photo) { if (_photo) {
displayPhoto(_photo, item); displayPhoto(_photo, item);
} else { } else {
@ -3367,11 +3419,13 @@ void OverlayWidget::setZoomLevel(int newZoom, bool force) {
OverlayWidget::Entity OverlayWidget::entityForUserPhotos(int index) const { OverlayWidget::Entity OverlayWidget::entityForUserPhotos(int index) const {
Expects(_userPhotosData.has_value()); Expects(_userPhotosData.has_value());
Expects(_session != nullptr);
if (index < 0 || index >= _userPhotosData->size()) { if (index < 0 || index >= _userPhotosData->size()) {
return { std::nullopt, nullptr }; return { std::nullopt, nullptr };
} }
if (auto photo = Auth().data().photo((*_userPhotosData)[index])) { const auto id = (*_userPhotosData)[index];
if (const auto photo = _session->data().photo(id)) {
return { photo, nullptr }; return { photo, nullptr };
} }
return { std::nullopt, nullptr }; return { std::nullopt, nullptr };
@ -3395,8 +3449,9 @@ OverlayWidget::Entity OverlayWidget::entityForSharedMedia(int index) const {
OverlayWidget::Entity OverlayWidget::entityForCollage(int index) const { OverlayWidget::Entity OverlayWidget::entityForCollage(int index) const {
Expects(_collageData.has_value()); Expects(_collageData.has_value());
Expects(_session != nullptr);
const auto item = Auth().data().message(_msgid); const auto item = _session->data().message(_msgid);
const auto &items = _collageData->items; const auto &items = _collageData->items;
if (!item || index < 0 || index >= items.size()) { if (!item || index < 0 || index >= items.size()) {
return { std::nullopt, nullptr }; return { std::nullopt, nullptr };
@ -3410,7 +3465,9 @@ OverlayWidget::Entity OverlayWidget::entityForCollage(int index) const {
} }
OverlayWidget::Entity OverlayWidget::entityForItemId(const FullMsgId &itemId) const { OverlayWidget::Entity OverlayWidget::entityForItemId(const FullMsgId &itemId) const {
if (const auto item = Auth().data().message(itemId)) { Expects(_session != nullptr);
if (const auto item = _session->data().message(itemId)) {
if (const auto media = item->media()) { if (const auto media = item->media()) {
if (const auto photo = media->photo()) { if (const auto photo = media->photo()) {
return { photo, item }; return { photo, item };

View File

@ -355,6 +355,7 @@ private:
QBrush _transparentBrush; QBrush _transparentBrush;
Main::Session *_session = nullptr;
PhotoData *_photo = nullptr; PhotoData *_photo = nullptr;
DocumentData *_document = nullptr; DocumentData *_document = nullptr;
std::shared_ptr<Data::PhotoMedia> _photoMedia; std::shared_ptr<Data::PhotoMedia> _photoMedia;

View File

@ -1740,6 +1740,7 @@ void FormController::loadFile(File &file) {
const auto [j, ok] = _fileLoaders.emplace( const auto [j, ok] = _fileLoaders.emplace(
key, key,
std::make_unique<mtpFileLoader>( std::make_unique<mtpFileLoader>(
&_controller->session(),
StorageFileLocation( StorageFileLocation(
file.dcId, file.dcId,
session().userId(), session().userId(),

View File

@ -381,7 +381,7 @@ void CountryRow::chooseCountry() {
const auto top = _value.current(); const auto top = _value.current();
const auto name = Data::CountryNameByISO2(top); const auto name = Data::CountryNameByISO2(top);
const auto isoByPhone = Data::CountryISO2ByPhone( const auto isoByPhone = Data::CountryISO2ByPhone(
Auth().user()->phone()); _controller->bot()->session().user()->phone());
const auto box = _controller->show(Box<CountrySelectBox>(!name.isEmpty() const auto box = _controller->show(Box<CountrySelectBox>(!name.isEmpty()
? top ? top
: !isoByPhone.isEmpty() : !isoByPhone.isEmpty()

View File

@ -71,7 +71,7 @@ GroupMembersWidget::GroupMembersWidget(
} }
void GroupMembersWidget::removePeer(PeerData *selectedPeer) { void GroupMembersWidget::removePeer(PeerData *selectedPeer) {
auto user = selectedPeer->asUser(); const auto user = selectedPeer->asUser();
Assert(user != nullptr); Assert(user != nullptr);
auto text = tr::lng_profile_sure_kick(tr::now, lt_user, user->firstName); auto text = tr::lng_profile_sure_kick(tr::now, lt_user, user->firstName);
@ -84,18 +84,24 @@ void GroupMembersWidget::removePeer(PeerData *selectedPeer) {
} }
return MTP_chatBannedRights(MTP_flags(0), MTP_int(0)); return MTP_chatBannedRights(MTP_flags(0), MTP_int(0));
}(); }();
Ui::show(Box<ConfirmBox>(text, tr::lng_box_remove(tr::now), [user, currentRestrictedRights, peer = peer()] {
const auto peer = this->peer();
const auto callback = [=] {
Ui::hideLayer(); Ui::hideLayer();
if (const auto chat = peer->asChat()) { if (const auto chat = peer->asChat()) {
Auth().api().kickParticipant(chat, user); chat->session().api().kickParticipant(chat, user);
Ui::showPeerHistory(chat->id, ShowAtTheEndMsgId); Ui::showPeerHistory(chat->id, ShowAtTheEndMsgId);
} else if (const auto channel = peer->asChannel()) { } else if (const auto channel = peer->asChannel()) {
Auth().api().kickParticipant( channel->session().api().kickParticipant(
channel, channel,
user, user,
currentRestrictedRights); currentRestrictedRights);
} }
})); };
Ui::show(Box<ConfirmBox>(
text,
tr::lng_box_remove(tr::now),
crl::guard(&peer->session(), callback)));
} }
void GroupMembersWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) { void GroupMembersWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) {
@ -152,7 +158,7 @@ void GroupMembersWidget::preloadMore() {
//if (auto megagroup = peer()->asMegagroup()) { //if (auto megagroup = peer()->asMegagroup()) {
// auto &megagroupInfo = megagroup->mgInfo; // auto &megagroupInfo = megagroup->mgInfo;
// if (!megagroupInfo->lastParticipants.isEmpty() && megagroupInfo->lastParticipants.size() < megagroup->membersCount()) { // if (!megagroupInfo->lastParticipants.isEmpty() && megagroupInfo->lastParticipants.size() < megagroup->membersCount()) {
// Auth().api().requestLastParticipants(megagroup, false); // peer()->session().api().requestLastParticipants(megagroup, false);
// } // }
//} //}
} }
@ -187,13 +193,13 @@ void GroupMembersWidget::refreshMembers() {
if (const auto chat = peer()->asChat()) { if (const auto chat = peer()->asChat()) {
checkSelfAdmin(chat); checkSelfAdmin(chat);
if (chat->noParticipantInfo()) { if (chat->noParticipantInfo()) {
Auth().api().requestFullPeer(chat); chat->session().api().requestFullPeer(chat);
} }
fillChatMembers(chat); fillChatMembers(chat);
} else if (const auto megagroup = peer()->asMegagroup()) { } else if (const auto megagroup = peer()->asMegagroup()) {
auto &megagroupInfo = megagroup->mgInfo; auto &megagroupInfo = megagroup->mgInfo;
if (megagroup->lastParticipantsRequestNeeded()) { if (megagroup->lastParticipantsRequestNeeded()) {
Auth().api().requestLastParticipants(megagroup); megagroup->session().api().requestLastParticipants(megagroup);
} }
fillMegagroupMembers(megagroup); fillMegagroupMembers(megagroup);
} }

View File

@ -22,13 +22,18 @@ PeerListWidget::Item::Item(not_null<PeerData*> peer) : peer(peer) {
PeerListWidget::Item::~Item() = default; PeerListWidget::Item::~Item() = default;
PeerListWidget::PeerListWidget(QWidget *parent, PeerData *peer, const QString &title, const style::PeerListItem &st, const QString &removeText) PeerListWidget::PeerListWidget(
QWidget *parent,
PeerData *peer,
const QString &title,
const style::PeerListItem &st,
const QString &removeText)
: BlockWidget(parent, peer, title) : BlockWidget(parent, peer, title)
, _st(st) , _st(st)
, _removeText(removeText) , _removeText(removeText)
, _removeWidth(st::normalFont->width(_removeText)) { , _removeWidth(st::normalFont->width(_removeText)) {
setMouseTracking(true); setMouseTracking(true);
subscribe(Auth().downloaderTaskFinished(), [this] { update(); }); subscribe(peer->session().downloaderTaskFinished(), [=] { update(); });
} }
int PeerListWidget::resizeGetHeight(int newWidth) { int PeerListWidget::resizeGetHeight(int newWidth) {

View File

@ -30,6 +30,7 @@ namespace {
class FromMemoryLoader final : public FileLoader { class FromMemoryLoader final : public FileLoader {
public: public:
FromMemoryLoader( FromMemoryLoader(
not_null<Main::Session*> session,
const QByteArray &data, const QByteArray &data,
const QString &toFile, const QString &toFile,
int32 size, int32 size,
@ -50,6 +51,7 @@ private:
}; };
FromMemoryLoader::FromMemoryLoader( FromMemoryLoader::FromMemoryLoader(
not_null<Main::Session*> session,
const QByteArray &data, const QByteArray &data,
const QString &toFile, const QString &toFile,
int32 size, int32 size,
@ -59,6 +61,7 @@ FromMemoryLoader::FromMemoryLoader(
bool autoLoading, bool autoLoading,
uint8 cacheTag uint8 cacheTag
) : FileLoader( ) : FileLoader(
session,
toFile, toFile,
size, size,
locationType, locationType,
@ -87,6 +90,7 @@ void FromMemoryLoader::startLoading() {
} // namespace } // namespace
FileLoader::FileLoader( FileLoader::FileLoader(
not_null<Main::Session*> session,
const QString &toFile, const QString &toFile,
int32 size, int32 size,
LocationType locationType, LocationType locationType,
@ -94,7 +98,7 @@ FileLoader::FileLoader(
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
bool autoLoading, bool autoLoading,
uint8 cacheTag) uint8 cacheTag)
: _session(&Auth()) : _session(session)
, _autoLoading(autoLoading) , _autoLoading(autoLoading)
, _cacheTag(cacheTag) , _cacheTag(cacheTag)
, _filename(toFile) , _filename(toFile)
@ -441,6 +445,7 @@ bool FileLoader::finalizeResult() {
} }
std::unique_ptr<FileLoader> CreateFileLoader( std::unique_ptr<FileLoader> CreateFileLoader(
not_null<Main::Session*> session,
const DownloadLocation &location, const DownloadLocation &location,
Data::FileOrigin origin, Data::FileOrigin origin,
const QString &toFile, const QString &toFile,
@ -453,6 +458,7 @@ std::unique_ptr<FileLoader> CreateFileLoader(
auto result = std::unique_ptr<FileLoader>(); auto result = std::unique_ptr<FileLoader>();
location.data.match([&](const StorageFileLocation &data) { location.data.match([&](const StorageFileLocation &data) {
result = std::make_unique<mtpFileLoader>( result = std::make_unique<mtpFileLoader>(
session,
data, data,
origin, origin,
locationType, locationType,
@ -464,6 +470,7 @@ std::unique_ptr<FileLoader> CreateFileLoader(
cacheTag); cacheTag);
}, [&](const WebFileLocation &data) { }, [&](const WebFileLocation &data) {
result = std::make_unique<mtpFileLoader>( result = std::make_unique<mtpFileLoader>(
session,
data, data,
size, size,
fromCloud, fromCloud,
@ -471,6 +478,7 @@ std::unique_ptr<FileLoader> CreateFileLoader(
cacheTag); cacheTag);
}, [&](const GeoPointLocation &data) { }, [&](const GeoPointLocation &data) {
result = std::make_unique<mtpFileLoader>( result = std::make_unique<mtpFileLoader>(
session,
data, data,
size, size,
fromCloud, fromCloud,
@ -478,6 +486,7 @@ std::unique_ptr<FileLoader> CreateFileLoader(
cacheTag); cacheTag);
}, [&](const PlainUrlLocation &data) { }, [&](const PlainUrlLocation &data) {
result = std::make_unique<webFileLoader>( result = std::make_unique<webFileLoader>(
session,
data.url, data.url,
toFile, toFile,
fromCloud, fromCloud,
@ -485,6 +494,7 @@ std::unique_ptr<FileLoader> CreateFileLoader(
cacheTag); cacheTag);
}, [&](const InMemoryLocation &data) { }, [&](const InMemoryLocation &data) {
result = std::make_unique<FromMemoryLoader>( result = std::make_unique<FromMemoryLoader>(
session,
data.bytes, data.bytes,
toFile, toFile,
size, size,

View File

@ -55,6 +55,7 @@ struct StorageImageSaved {
class FileLoader : public base::has_weak_ptr { class FileLoader : public base::has_weak_ptr {
public: public:
FileLoader( FileLoader(
not_null<Main::Session*> session,
const QString &toFile, const QString &toFile,
int32 size, int32 size,
LocationType locationType, LocationType locationType,
@ -173,6 +174,7 @@ protected:
}; };
[[nodiscard]] std::unique_ptr<FileLoader> CreateFileLoader( [[nodiscard]] std::unique_ptr<FileLoader> CreateFileLoader(
not_null<Main::Session*> session,
const DownloadLocation &location, const DownloadLocation &location,
Data::FileOrigin origin, Data::FileOrigin origin,
const QString &toFile, const QString &toFile,

View File

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "facades.h" #include "facades.h"
mtpFileLoader::mtpFileLoader( mtpFileLoader::mtpFileLoader(
not_null<Main::Session*> session,
const StorageFileLocation &location, const StorageFileLocation &location,
Data::FileOrigin origin, Data::FileOrigin origin,
LocationType type, LocationType type,
@ -28,6 +29,7 @@ mtpFileLoader::mtpFileLoader(
bool autoLoading, bool autoLoading,
uint8 cacheTag) uint8 cacheTag)
: FileLoader( : FileLoader(
session,
to, to,
size, size,
type, type,
@ -35,16 +37,18 @@ mtpFileLoader::mtpFileLoader(
fromCloud, fromCloud,
autoLoading, autoLoading,
cacheTag) cacheTag)
, DownloadMtprotoTask(&session().downloader(), location, origin) { , DownloadMtprotoTask(&session->downloader(), location, origin) {
} }
mtpFileLoader::mtpFileLoader( mtpFileLoader::mtpFileLoader(
not_null<Main::Session*> session,
const WebFileLocation &location, const WebFileLocation &location,
int32 size, int32 size,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
bool autoLoading, bool autoLoading,
uint8 cacheTag) uint8 cacheTag)
: FileLoader( : FileLoader(
session,
QString(), QString(),
size, size,
UnknownFileLocation, UnknownFileLocation,
@ -53,18 +57,20 @@ mtpFileLoader::mtpFileLoader(
autoLoading, autoLoading,
cacheTag) cacheTag)
, DownloadMtprotoTask( , DownloadMtprotoTask(
&session().downloader(), &session->downloader(),
Global::WebFileDcId(), Global::WebFileDcId(),
{ location }) { { location }) {
} }
mtpFileLoader::mtpFileLoader( mtpFileLoader::mtpFileLoader(
not_null<Main::Session*> session,
const GeoPointLocation &location, const GeoPointLocation &location,
int32 size, int32 size,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
bool autoLoading, bool autoLoading,
uint8 cacheTag) uint8 cacheTag)
: FileLoader( : FileLoader(
session,
QString(), QString(),
size, size,
UnknownFileLocation, UnknownFileLocation,
@ -73,7 +79,7 @@ mtpFileLoader::mtpFileLoader(
autoLoading, autoLoading,
cacheTag) cacheTag)
, DownloadMtprotoTask( , DownloadMtprotoTask(
&session().downloader(), &session->downloader(),
Global::WebFileDcId(), Global::WebFileDcId(),
{ location }) { { location }) {
} }

View File

@ -15,6 +15,7 @@ class mtpFileLoader final
, private Storage::DownloadMtprotoTask { , private Storage::DownloadMtprotoTask {
public: public:
mtpFileLoader( mtpFileLoader(
not_null<Main::Session*> session,
const StorageFileLocation &location, const StorageFileLocation &location,
Data::FileOrigin origin, Data::FileOrigin origin,
LocationType type, LocationType type,
@ -25,12 +26,14 @@ public:
bool autoLoading, bool autoLoading,
uint8 cacheTag); uint8 cacheTag);
mtpFileLoader( mtpFileLoader(
not_null<Main::Session*> session,
const WebFileLocation &location, const WebFileLocation &location,
int32 size, int32 size,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
bool autoLoading, bool autoLoading,
uint8 cacheTag); uint8 cacheTag);
mtpFileLoader( mtpFileLoader(
not_null<Main::Session*> session,
const GeoPointLocation &location, const GeoPointLocation &location,
int32 size, int32 size,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,

View File

@ -436,12 +436,14 @@ void WebLoadManager::sendUpdate(int id, Update &&data) {
} }
webFileLoader::webFileLoader( webFileLoader::webFileLoader(
not_null<Main::Session*> session,
const QString &url, const QString &url,
const QString &to, const QString &to,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
bool autoLoading, bool autoLoading,
uint8 cacheTag) uint8 cacheTag)
: FileLoader( : FileLoader(
session,
QString(), QString(),
0, 0,
UnknownFileLocation, UnknownFileLocation,

View File

@ -14,6 +14,7 @@ class WebLoadManager;
class webFileLoader final : public FileLoader { class webFileLoader final : public FileLoader {
public: public:
webFileLoader( webFileLoader(
not_null<Main::Session*> session,
const QString &url, const QString &url,
const QString &to, const QString &to,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,

View File

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/image/image_location_factory.h" #include "ui/image/image_location_factory.h"
#include "core/mime_type.h" #include "core/mime_type.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "apiwrap.h"
namespace Storage { namespace Storage {
namespace { namespace {
@ -154,17 +155,25 @@ Uploader::Uploader(not_null<ApiWrap*> api)
connect(&stopSessionsTimer, SIGNAL(timeout()), this, SLOT(stopSessions())); connect(&stopSessionsTimer, SIGNAL(timeout()), this, SLOT(stopSessions()));
} }
Uploader::~Uploader() {
clear();
}
Main::Session &Uploader::session() const {
return _api->session();
}
void Uploader::uploadMedia( void Uploader::uploadMedia(
const FullMsgId &msgId, const FullMsgId &msgId,
const SendMediaReady &media) { const SendMediaReady &media) {
if (media.type == SendMediaType::Photo) { if (media.type == SendMediaType::Photo) {
Auth().data().processPhoto(media.photo, media.photoThumbs); session().data().processPhoto(media.photo, media.photoThumbs);
} else if (media.type == SendMediaType::File } else if (media.type == SendMediaType::File
|| media.type == SendMediaType::ThemeFile || media.type == SendMediaType::ThemeFile
|| media.type == SendMediaType::Audio) { || media.type == SendMediaType::Audio) {
const auto document = media.photoThumbs.empty() const auto document = media.photoThumbs.empty()
? Auth().data().processDocument(media.document) ? session().data().processDocument(media.document)
: Auth().data().processDocument( : session().data().processDocument(
media.document, media.document,
Images::FromImageInMemory( Images::FromImageInMemory(
media.photoThumbs.front().second, media.photoThumbs.front().second,
@ -187,7 +196,7 @@ void Uploader::upload(
const FullMsgId &msgId, const FullMsgId &msgId,
const std::shared_ptr<FileLoadResult> &file) { const std::shared_ptr<FileLoadResult> &file) {
if (file->type == SendMediaType::Photo) { if (file->type == SendMediaType::Photo) {
const auto photo = Auth().data().processPhoto( const auto photo = session().data().processPhoto(
file->photo, file->photo,
file->photoThumbs); file->photoThumbs);
photo->uploadingData = std::make_unique<Data::UploadState>( photo->uploadingData = std::make_unique<Data::UploadState>(
@ -196,8 +205,8 @@ void Uploader::upload(
|| file->type == SendMediaType::ThemeFile || file->type == SendMediaType::ThemeFile
|| file->type == SendMediaType::Audio) { || file->type == SendMediaType::Audio) {
const auto document = file->thumb.isNull() const auto document = file->thumb.isNull()
? Auth().data().processDocument(file->document) ? session().data().processDocument(file->document)
: Auth().data().processDocument( : session().data().processDocument(
file->document, file->document,
Images::FromImageInMemory( Images::FromImageInMemory(
file->thumb, file->thumb,
@ -241,7 +250,7 @@ void Uploader::currentFailed() {
} else if (j->second.type() == SendMediaType::File } else if (j->second.type() == SendMediaType::File
|| j->second.type() == SendMediaType::ThemeFile || j->second.type() == SendMediaType::ThemeFile
|| j->second.type() == SendMediaType::Audio) { || j->second.type() == SendMediaType::Audio) {
const auto document = Auth().data().document(j->second.id()); const auto document = session().data().document(j->second.id());
if (document->uploading()) { if (document->uploading()) {
document->status = FileUploadFailed; document->status = FileUploadFailed;
} }
@ -552,7 +561,7 @@ void Uploader::partLoaded(const MTPBool &result, mtpRequestId requestId) {
sentSizes[dc] -= sentPartSize; sentSizes[dc] -= sentPartSize;
if (file.type() == SendMediaType::Photo) { if (file.type() == SendMediaType::Photo) {
file.fileSentSize += sentPartSize; file.fileSentSize += sentPartSize;
const auto photo = Auth().data().photo(file.id()); const auto photo = session().data().photo(file.id());
if (photo->uploading() && file.file) { if (photo->uploading() && file.file) {
photo->uploadingData->size = file.file->partssize; photo->uploadingData->size = file.file->partssize;
photo->uploadingData->offset = file.fileSentSize; photo->uploadingData->offset = file.fileSentSize;
@ -561,7 +570,7 @@ void Uploader::partLoaded(const MTPBool &result, mtpRequestId requestId) {
} else if (file.type() == SendMediaType::File } else if (file.type() == SendMediaType::File
|| file.type() == SendMediaType::ThemeFile || file.type() == SendMediaType::ThemeFile
|| file.type() == SendMediaType::Audio) { || file.type() == SendMediaType::Audio) {
const auto document = Auth().data().document(file.id()); const auto document = session().data().document(file.id());
if (document->uploading()) { if (document->uploading()) {
const auto doneParts = file.docSentParts const auto doneParts = file.docSentParts
- int(docRequestsSent.size()); - int(docRequestsSent.size());
@ -595,8 +604,4 @@ bool Uploader::partFailed(const RPCError &error, mtpRequestId requestId) {
return true; return true;
} }
Uploader::~Uploader() {
clear();
}
} // namespace Storage } // namespace Storage

View File

@ -16,6 +16,10 @@ class ApiWrap;
struct FileLoadResult; struct FileLoadResult;
struct SendMediaReady; struct SendMediaReady;
namespace Main {
class Session;
} // namespace Main
namespace Storage { namespace Storage {
// MTP big files methods used for files greater than 10mb. // MTP big files methods used for files greater than 10mb.
@ -62,6 +66,8 @@ public:
explicit Uploader(not_null<ApiWrap*> api); explicit Uploader(not_null<ApiWrap*> api);
~Uploader(); ~Uploader();
[[nodiscard]] Main::Session &session() const;
void uploadMedia(const FullMsgId &msgId, const SendMediaReady &image); void uploadMedia(const FullMsgId &msgId, const SendMediaReady &image);
void upload( void upload(
const FullMsgId &msgId, const FullMsgId &msgId,

View File

@ -428,7 +428,7 @@ void SendingAlbum::removeItem(not_null<HistoryItem*> item) {
if (moveCaption) { if (moveCaption) {
const auto caption = item->originalText(); const auto caption = item->originalText();
const auto firstId = items.front().msgId; const auto firstId = items.front().msgId;
if (const auto first = Auth().data().message(firstId)) { if (const auto first = item->history()->owner().message(firstId)) {
// We don't need to finishEdition() here, because the whole // We don't need to finishEdition() here, because the whole
// album will be rebuilt after one item was removed from it. // album will be rebuilt after one item was removed from it.
first->setText(caption); first->setText(caption);

View File

@ -21,6 +21,8 @@ constexpr auto kRequestPartsCount = 8;
} // namespace } // namespace
StreamedFileDownloader::StreamedFileDownloader( StreamedFileDownloader::StreamedFileDownloader(
not_null<Main::Session*> session,
uint64 objectId, uint64 objectId,
MTP::DcId dcId, MTP::DcId dcId,
Data::FileOrigin origin, Data::FileOrigin origin,
@ -37,6 +39,7 @@ StreamedFileDownloader::StreamedFileDownloader(
bool autoLoading, bool autoLoading,
uint8 cacheTag) uint8 cacheTag)
: FileLoader( : FileLoader(
session,
toFile, toFile,
size, size,
locationType, locationType,

View File

@ -23,6 +23,8 @@ namespace Storage {
class StreamedFileDownloader final : public FileLoader { class StreamedFileDownloader final : public FileLoader {
public: public:
StreamedFileDownloader( StreamedFileDownloader(
not_null<Main::Session*> session,
uint64 objectId, uint64 objectId,
MTP::DcId dcId, MTP::DcId dcId,
Data::FileOrigin origin, Data::FileOrigin origin,