MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / ExtractCollage

Function ExtractCollage

Telegram/SourceFiles/data/data_web_page.cpp:26–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24namespace {
25
26[[nodiscard]] WebPageCollage ExtractCollage(
27 not_null<Data::Session*> owner,
28 const QVector<MTPPageBlock> &items,
29 const QVector<MTPPhoto> &photos,
30 const QVector<MTPDocument> &documents) {
31 const auto count = items.size();
32 if (count < 2) {
33 return {};
34 }
35 const auto bad = ranges::find_if(items, [](mtpTypeId type) {
36 return (type != mtpc_pageBlockPhoto && type != mtpc_pageBlockVideo);
37 }, [](const MTPPageBlock &item) {
38 return item.type();
39 });
40 if (bad != items.end()) {
41 return {};
42 }
43
44 for (const auto &photo : photos) {
45 owner->processPhoto(photo);
46 }
47 for (const auto &document : documents) {
48 owner->processDocument(document);
49 }
50 auto result = WebPageCollage();
51 result.items.reserve(count);
52 for (const auto &item : items) {
53 const auto good = item.match([&](const MTPDpageBlockPhoto &data) {
54 const auto photo = owner->photo(data.vphoto_id().v);
55 if (photo->isNull()) {
56 return false;
57 }
58 result.items.emplace_back(photo);
59 return true;
60 }, [&](const MTPDpageBlockVideo &data) {
61 const auto document = owner->document(data.vvideo_id().v);
62 if (!document->isVideoFile()) {
63 return false;
64 }
65 result.items.emplace_back(document);
66 return true;
67 }, [](const auto &) -> bool {
68 Unexpected("Type of block in Collage.");
69 });
70 if (!good) {
71 return {};
72 }
73 }
74 return result;
75}
76
77WebPageCollage ExtractCollage(
78 not_null<Data::Session*> owner,

Callers 1

WebPageCollageMethod · 0.85

Calls 10

processDocumentMethod · 0.80
WebPageCollageClass · 0.70
sizeMethod · 0.45
typeMethod · 0.45
endMethod · 0.45
processPhotoMethod · 0.45
photoMethod · 0.45
isNullMethod · 0.45
documentMethod · 0.45
isVideoFileMethod · 0.45

Tested by

no test coverage detected