diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 47e59c7a1a..af074e8a75 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3741,14 +3741,16 @@ void ApiWrap::sendVoiceMessage( const SendAction &action) { const auto caption = TextWithTags(); const auto to = FileLoadTaskOptions(action); - _fileLoader->addTask(std::make_unique( - &session(), - result, - duration, - waveform, - video, - to, - caption)); + _fileLoader->addTask( + std::make_unique(FileLoadTask::VoiceArgs{ + .session = &session(), + .voice = result, + .duration = duration, + .waveform = waveform, + .video = video, + .to = to, + .caption = caption, + })); } void ApiWrap::editMedia( @@ -3774,29 +3776,35 @@ void ApiWrap::editMedia( } const auto forceFile = (type == SendMediaType::File) && (file.type == Ui::PreparedFile::Type::Video); - _fileLoader->addTask(std::make_unique( - &session(), - file.path, - file.content, - std::move(file.information), - (file.videoCover - ? std::make_unique( - &session(), - file.videoCover->path, - file.videoCover->content, - std::move(file.videoCover->information), - nullptr, - SendMediaType::Photo, - to, - TextWithTags(), - false) + _fileLoader->addTask(std::make_unique(FileLoadTask::Args{ + .session = &session(), + .filepath = file.path, + .content = file.content, + .information = std::move(file.information), + .videoCover = (file.videoCover + ? std::make_unique(FileLoadTask::Args{ + .session = &session(), + .filepath = file.videoCover->path, + .content = file.videoCover->content, + .information = std::move(file.videoCover->information), + .videoCover = nullptr, + .type = SendMediaType::Photo, + .to = to, + .caption = TextWithTags(), + .spoiler = false, + .album = nullptr, + .forceFile = false, + .idOverride = 0, + }) : nullptr), - type, - to, - caption, - file.spoiler, - nullptr, - forceFile)); + .type = type, + .to = to, + .caption = caption, + .spoiler = file.spoiler, + .album = nullptr, + .forceFile = forceFile, + .idOverride = 0, + })); } void ApiWrap::sendFiles( @@ -3831,30 +3839,35 @@ void ApiWrap::sendFiles( : SendMediaType::File; const auto forceFile = (type == SendMediaType::File) && (file.type == Ui::PreparedFile::Type::Video); - tasks.push_back(std::make_unique( - &session(), - file.path, - file.content, - std::move(file.information), - (file.videoCover - ? std::make_unique( - &session(), - file.videoCover->path, - file.videoCover->content, - std::move(file.videoCover->information), - nullptr, - SendMediaType::Photo, - to, - TextWithTags(), - false, - nullptr) + tasks.push_back(std::make_unique(FileLoadTask::Args{ + .session = &session(), + .filepath = file.path, + .content = file.content, + .information = std::move(file.information), + .videoCover = (file.videoCover + ? std::make_unique(FileLoadTask::Args{ + .session = &session(), + .filepath = file.videoCover->path, + .content = file.videoCover->content, + .information = std::move(file.videoCover->information), + .videoCover = nullptr, + .type = SendMediaType::Photo, + .to = to, + .caption = TextWithTags(), + .spoiler = false, + .album = nullptr, + .forceFile = false, + .idOverride = 0, + }) : nullptr), - uploadWithType, - to, - caption, - file.spoiler, - album, - forceFile)); + .type = uploadWithType, + .to = to, + .caption = caption, + .spoiler = file.spoiler, + .album = album, + .forceFile = forceFile, + .idOverride = 0, + })); caption = TextWithTags(); } if (album) { @@ -3874,18 +3887,20 @@ void ApiWrap::sendFile( const auto to = FileLoadTaskOptions(action); auto caption = TextWithTags(); const auto spoiler = false; - const auto information = nullptr; - const auto videoCover = nullptr; - _fileLoader->addTask(std::make_unique( - &session(), - QString(), - fileContent, - information, - videoCover, - type, - to, - caption, - spoiler)); + _fileLoader->addTask(std::make_unique(FileLoadTask::Args{ + .session = &session(), + .filepath = QString(), + .content = fileContent, + .information = nullptr, + .videoCover = nullptr, + .type = type, + .to = to, + .caption = caption, + .spoiler = spoiler, + .album = nullptr, + .forceFile = false, + .idOverride = 0 + })); } void ApiWrap::sendUploadedPhoto( diff --git a/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp b/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp index 0c62f7680a..e2b9cd80e7 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp @@ -324,18 +324,14 @@ QSize ComputeStickerSize(not_null document, QSize box) { not_null GenerateLocalSticker( not_null session, const QString &path) { - auto task = FileLoadTask( - session, - path, - QByteArray(), - nullptr, - nullptr, - SendMediaType::File, - FileLoadTo(0, {}, {}, 0), - {}, - false, - nullptr, - LocalStickerId(path)); + auto task = FileLoadTask(FileLoadTask::Args{ + .session = session, + .filepath = path, + .type = SendMediaType::File, + .to = FileLoadTo(0, {}, {}, 0), + .caption = {}, + .idOverride = LocalStickerId(path), + }); task.process({ .generateGoodThumbnail = false }); const auto result = task.peekResult(); Assert(result != nullptr); diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index 8c143c2a10..34be9f435d 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -466,57 +466,38 @@ std::shared_ptr MakePreparedFile( return std::make_shared(std::move(descriptor)); } -FileLoadTask::FileLoadTask( - not_null session, - const QString &filepath, - const QByteArray &content, - std::unique_ptr information, - std::unique_ptr videoCover, - SendMediaType type, - const FileLoadTo &to, - const TextWithTags &caption, - bool spoiler, - std::shared_ptr album, - bool forceFile, - uint64 idOverride) -: _id(idOverride ? idOverride : base::RandomValue()) -, _session(session) -, _dcId(session->mainDcId()) -, _to(to) -, _album(std::move(album)) -, _filepath(filepath) -, _content(content) -, _videoCover(std::move(videoCover)) -, _information(std::move(information)) -, _type(type) -, _caption(caption) -, _spoiler(spoiler) -, _forceFile(forceFile) { - Expects(to.options.scheduled - || to.options.shortcutId - || !to.replaceMediaOf - || IsServerMsgId(to.replaceMediaOf)); +FileLoadTask::FileLoadTask(Args &&args) +: _id(args.idOverride ? args.idOverride : base::RandomValue()) +, _session(args.session) +, _dcId(args.session->mainDcId()) +, _to(std::move(args.to)) +, _album(std::move(args.album)) +, _filepath(std::move(args.filepath)) +, _content(std::move(args.content)) +, _videoCover(std::move(args.videoCover)) +, _information(std::move(args.information)) +, _type(args.type) +, _caption(std::move(args.caption)) +, _spoiler(args.spoiler) +, _forceFile(args.forceFile) { + Expects(_to.options.scheduled + || _to.options.shortcutId + || !_to.replaceMediaOf + || IsServerMsgId(_to.replaceMediaOf)); SendLargePhotosAtomic = SendLargePhotos.value(); } -FileLoadTask::FileLoadTask( - not_null session, - const QByteArray &voice, - crl::time duration, - const VoiceWaveform &waveform, - bool video, - const FileLoadTo &to, - const TextWithTags &caption) +FileLoadTask::FileLoadTask(VoiceArgs &&args) : _id(base::RandomValue()) -, _session(session) -, _dcId(session->mainDcId()) -, _to(to) -, _content(voice) -, _duration(duration) -, _waveform(waveform) -, _type(video ? SendMediaType::Round : SendMediaType::Audio) -, _caption(caption) { +, _session(args.session) +, _dcId(args.session->mainDcId()) +, _to(std::move(args.to)) +, _content(std::move(args.voice)) +, _duration(args.duration) +, _waveform(std::move(args.waveform)) +, _type(args.video ? SendMediaType::Round : SendMediaType::Audio) +, _caption(std::move(args.caption)) { } FileLoadTask::~FileLoadTask() = default; @@ -686,7 +667,7 @@ bool FileLoadTask::FillImageInformation( return true; } -void FileLoadTask::process(Args &&args) { +void FileLoadTask::process(ProcessArgs &&args) { _result = MakePreparedFile({ .taskId = id(), .id = _id, diff --git a/Telegram/SourceFiles/storage/localimageloader.h b/Telegram/SourceFiles/storage/localimageloader.h index a5f38e46b4..2c011f45fd 100644 --- a/Telegram/SourceFiles/storage/localimageloader.h +++ b/Telegram/SourceFiles/storage/localimageloader.h @@ -220,37 +220,43 @@ public: QByteArray content = {}, QByteArray format = {}); - FileLoadTask( - not_null session, - const QString &filepath, - const QByteArray &content, - std::unique_ptr information, - std::unique_ptr videoCover, - SendMediaType type, - const FileLoadTo &to, - const TextWithTags &caption, - bool spoiler, - std::shared_ptr album = nullptr, - bool forceFile = false, - uint64 idOverride = 0); - FileLoadTask( - not_null session, - const QByteArray &voice, - crl::time duration, - const VoiceWaveform &waveform, - bool video, - const FileLoadTo &to, - const TextWithTags &caption); + struct Args { + not_null session; + QString filepath; + QByteArray content; + std::unique_ptr information; + std::unique_ptr videoCover; + SendMediaType type; + FileLoadTo to; + TextWithTags caption; + bool spoiler = false; + std::shared_ptr album; + bool forceFile = false; + uint64 idOverride = 0; + }; + + struct VoiceArgs { + not_null session; + QByteArray voice; + crl::time duration = 0; + VoiceWaveform waveform; + bool video = false; + FileLoadTo to; + TextWithTags caption; + }; + + explicit FileLoadTask(Args &&args); + explicit FileLoadTask(VoiceArgs &&args); ~FileLoadTask(); uint64 fileid() const { return _id; } - struct Args { + struct ProcessArgs { bool generateGoodThumbnail = true; }; - void process(Args &&args); + void process(ProcessArgs &&args); void process() override { process({});