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

Function PreparePeerPhoto

Telegram/SourceFiles/api/api_peer_photo.cpp:37–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35constexpr auto kSharedMediaLimit = 100;
36
37[[nodiscard]] std::shared_ptr<FilePrepareResult> PreparePeerPhoto(
38 MTP::DcId dcId,
39 PeerId peerId,
40 QImage &&image) {
41 PreparedPhotoThumbs photoThumbs;
42 QVector<MTPPhotoSize> photoSizes;
43
44 QByteArray jpeg;
45 QBuffer jpegBuffer(&jpeg);
46 image.save(&jpegBuffer, "JPG", 87);
47
48 const auto scaled = [&](int size) {
49 return image.scaled(
50 size,
51 size,
52 Qt::KeepAspectRatio,
53 Qt::SmoothTransformation);
54 };
55 const auto push = [&](
56 const char *type,
57 QImage &&image,
58 QByteArray bytes = QByteArray()) {
59 photoSizes.push_back(MTP_photoSize(
60 MTP_string(type),
61 MTP_int(image.width()),
62 MTP_int(image.height()), MTP_int(0)));
63 photoThumbs.emplace(type[0], PreparedPhotoThumb{
64 .image = std::move(image),
65 .bytes = std::move(bytes)
66 });
67 };
68 push("a", scaled(160));
69 push("b", scaled(320));
70 push("c", std::move(image), jpeg);
71
72 const auto id = base::RandomValue<PhotoId>();
73 const auto photo = MTP_photo(
74 MTP_flags(0),
75 MTP_long(id),
76 MTP_long(0),
77 MTP_bytes(),
78 MTP_int(base::unixtime::now()),
79 MTP_vector<MTPPhotoSize>(photoSizes),
80 MTPVector<MTPVideoSize>(),
81 MTP_int(dcId));
82
83 auto result = MakePreparedFile({
84 .id = id,
85 .type = SendMediaType::Photo,
86 });
87 result->type = SendMediaType::Photo;
88 result->setFileData(jpeg);
89 result->thumbId = id;
90 result->thumbname = "thumb.jpg";
91 result->photo = photo;
92 result->photoThumbs = photoThumbs;
93 return result;
94}

Callers 1

uploadMethod · 0.85

Calls 13

QByteArrayClass · 0.85
MTP_stringFunction · 0.85
MTP_flagsFunction · 0.85
MTP_longFunction · 0.85
MTP_bytesFunction · 0.85
MakePreparedFileFunction · 0.85
scaledMethod · 0.80
emplaceMethod · 0.80
setFileDataMethod · 0.80
MTP_intFunction · 0.50
saveMethod · 0.45
widthMethod · 0.45

Tested by

no test coverage detected