Replaced FileLoadTask constructor parameters with structs.

This commit is contained in:
23rd
2026-02-19 10:59:54 +03:00
parent ca8959fc67
commit dff3698432
4 changed files with 145 additions and 147 deletions
+80 -65
View File
@@ -3741,14 +3741,16 @@ void ApiWrap::sendVoiceMessage(
const SendAction &action) {
const auto caption = TextWithTags();
const auto to = FileLoadTaskOptions(action);
_fileLoader->addTask(std::make_unique<FileLoadTask>(
&session(),
result,
duration,
waveform,
video,
to,
caption));
_fileLoader->addTask(
std::make_unique<FileLoadTask>(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<FileLoadTask>(
&session(),
file.path,
file.content,
std::move(file.information),
(file.videoCover
? std::make_unique<FileLoadTask>(
&session(),
file.videoCover->path,
file.videoCover->content,
std::move(file.videoCover->information),
nullptr,
SendMediaType::Photo,
to,
TextWithTags(),
false)
_fileLoader->addTask(std::make_unique<FileLoadTask>(FileLoadTask::Args{
.session = &session(),
.filepath = file.path,
.content = file.content,
.information = std::move(file.information),
.videoCover = (file.videoCover
? std::make_unique<FileLoadTask>(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<FileLoadTask>(
&session(),
file.path,
file.content,
std::move(file.information),
(file.videoCover
? std::make_unique<FileLoadTask>(
&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>(FileLoadTask::Args{
.session = &session(),
.filepath = file.path,
.content = file.content,
.information = std::move(file.information),
.videoCover = (file.videoCover
? std::make_unique<FileLoadTask>(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<FileLoadTask>(
&session(),
QString(),
fileContent,
information,
videoCover,
type,
to,
caption,
spoiler));
_fileLoader->addTask(std::make_unique<FileLoadTask>(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(
@@ -324,18 +324,14 @@ QSize ComputeStickerSize(not_null<DocumentData*> document, QSize box) {
not_null<DocumentData*> GenerateLocalSticker(
not_null<Main::Session*> 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);
@@ -466,57 +466,38 @@ std::shared_ptr<FilePrepareResult> MakePreparedFile(
return std::make_shared<FilePrepareResult>(std::move(descriptor));
}
FileLoadTask::FileLoadTask(
not_null<Main::Session*> session,
const QString &filepath,
const QByteArray &content,
std::unique_ptr<Ui::PreparedFileInformation> information,
std::unique_ptr<FileLoadTask> videoCover,
SendMediaType type,
const FileLoadTo &to,
const TextWithTags &caption,
bool spoiler,
std::shared_ptr<SendingAlbum> album,
bool forceFile,
uint64 idOverride)
: _id(idOverride ? idOverride : base::RandomValue<uint64>())
, _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<uint64>())
, _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<Main::Session*> 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<uint64>())
, _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,
+29 -23
View File
@@ -220,37 +220,43 @@ public:
QByteArray content = {},
QByteArray format = {});
FileLoadTask(
not_null<Main::Session*> session,
const QString &filepath,
const QByteArray &content,
std::unique_ptr<Ui::PreparedFileInformation> information,
std::unique_ptr<FileLoadTask> videoCover,
SendMediaType type,
const FileLoadTo &to,
const TextWithTags &caption,
bool spoiler,
std::shared_ptr<SendingAlbum> album = nullptr,
bool forceFile = false,
uint64 idOverride = 0);
FileLoadTask(
not_null<Main::Session*> session,
const QByteArray &voice,
crl::time duration,
const VoiceWaveform &waveform,
bool video,
const FileLoadTo &to,
const TextWithTags &caption);
struct Args {
not_null<Main::Session*> session;
QString filepath;
QByteArray content;
std::unique_ptr<Ui::PreparedFileInformation> information;
std::unique_ptr<FileLoadTask> videoCover;
SendMediaType type;
FileLoadTo to;
TextWithTags caption;
bool spoiler = false;
std::shared_ptr<SendingAlbum> album;
bool forceFile = false;
uint64 idOverride = 0;
};
struct VoiceArgs {
not_null<Main::Session*> 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({});