2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 22:46:10 +00:00

Export file thumbs, use in video messages.

This commit is contained in:
John Preston
2018-07-07 23:58:54 +03:00
parent cb8ff398a5
commit cef50e5f52
7 changed files with 143 additions and 81 deletions

View File

@@ -139,7 +139,7 @@ struct ApiWrap::UserpicsProcess {
base::optional<Data::UserpicsSlice> slice;
uint64 maxId = 0;
bool lastSlice = false;
int fileIndex = -1;
int fileIndex = 0;
};
struct ApiWrap::OtherDataProcess {
@@ -210,7 +210,7 @@ struct ApiWrap::ChatProcess {
Data::ParseMediaContext context;
base::optional<Data::MessagesSlice> slice;
bool lastSlice = false;
int fileIndex = -1;
int fileIndex = 0;
};
@@ -727,7 +727,7 @@ void ApiWrap::loadUserpicsFiles(Data::UserpicsSlice &&slice) {
_userpicsProcess->lastSlice = true;
}
_userpicsProcess->slice = std::move(slice);
_userpicsProcess->fileIndex = -1;
_userpicsProcess->fileIndex = 0;
loadNextUserpic();
}
@@ -735,14 +735,11 @@ void ApiWrap::loadNextUserpic() {
Expects(_userpicsProcess != nullptr);
Expects(_userpicsProcess->slice.has_value());
auto &list = _userpicsProcess->slice->list;
while (true) {
const auto index = ++_userpicsProcess->fileIndex;
if (index >= list.size()) {
break;
}
for (auto &list = _userpicsProcess->slice->list
; _userpicsProcess->fileIndex < list.size()
; ++_userpicsProcess->fileIndex) {
const auto ready = processFileLoad(
list[index].image.file,
list[_userpicsProcess->fileIndex].image.file,
[=](FileProgress value) { return loadUserpicProgress(value); },
[=](const QString &path) { loadUserpicDone(path); });
if (!ready) {
@@ -1213,7 +1210,7 @@ void ApiWrap::loadMessagesFiles(Data::MessagesSlice &&slice) {
_chatProcess->lastSlice = true;
}
_chatProcess->slice = std::move(slice);
_chatProcess->fileIndex = -1;
_chatProcess->fileIndex = 0;
loadNextMessageFile();
}
@@ -1222,23 +1219,31 @@ void ApiWrap::loadNextMessageFile() {
Expects(_chatProcess != nullptr);
Expects(_chatProcess->slice.has_value());
auto &list = _chatProcess->slice->list;
while (true) {
const auto index = ++_chatProcess->fileIndex;
if (index >= list.size()) {
break;
}
for (auto &list = _chatProcess->slice->list
; _chatProcess->fileIndex < list.size()
; ++_chatProcess->fileIndex) {
const auto fileProgress = [=](FileProgress value) {
return loadMessageFileProgress(value);
};
const auto ready = processFileLoad(
list[index].file(),
list[_chatProcess->fileIndex].file(),
fileProgress,
[=](const QString &path) { loadMessageFileDone(path); },
&list[index]);
&list[_chatProcess->fileIndex]);
if (!ready) {
return;
}
const auto thumbProgress = [=](FileProgress value) {
return loadMessageThumbProgress(value);
};
const auto thumbReady = processFileLoad(
list[_chatProcess->fileIndex].thumb().file,
thumbProgress,
[=](const QString &path) { loadMessageThumbDone(path); },
&list[_chatProcess->fileIndex]);
if (!thumbReady) {
return;
}
}
finishMessagesSlice();
}
@@ -1296,6 +1301,25 @@ void ApiWrap::loadMessageFileDone(const QString &relativePath) {
loadNextMessageFile();
}
bool ApiWrap::loadMessageThumbProgress(FileProgress progress) {
return loadMessageFileProgress(progress);
}
void ApiWrap::loadMessageThumbDone(const QString &relativePath) {
Expects(_chatProcess != nullptr);
Expects(_chatProcess->slice.has_value());
Expects((_chatProcess->fileIndex >= 0)
&& (_chatProcess->fileIndex < _chatProcess->slice->list.size()));
const auto index = _chatProcess->fileIndex;
auto &file = _chatProcess->slice->list[index].thumb().file;
file.relativePath = relativePath;
if (relativePath.isEmpty()) {
file.skipReason = Data::File::SkipReason::Unavailable;
}
loadNextMessageFile();
}
void ApiWrap::finishMessages() {
Expects(_chatProcess != nullptr);
Expects(!_chatProcess->slice.has_value());
@@ -1311,7 +1335,8 @@ bool ApiWrap::processFileLoad(
Data::Message *message) {
using SkipReason = Data::File::SkipReason;
if (!file.relativePath.isEmpty()) {
if (!file.relativePath.isEmpty()
|| file.skipReason != SkipReason::None) {
return true;
} else if (!file.location && file.content.isEmpty()) {
file.skipReason = SkipReason::Unavailable;