mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-30 22:25:12 +00:00
Update API and use WebDocument for inline bots.
This commit is contained in:
@@ -717,11 +717,14 @@ void DocumentData::save(
|
||||
if (fromCloud == LoadFromCloudOrLocal) _loader->permitLoadFromCloud();
|
||||
} else {
|
||||
status = FileReady;
|
||||
if (!_access && !_url.isEmpty()) {
|
||||
if (hasWebLocation()) {
|
||||
_loader = new mtpFileLoader(&_urlLocation, size, fromCloud, autoLoading);
|
||||
} else if (!_access && !_url.isEmpty()) {
|
||||
_loader = new webFileLoader(_url, toFile, fromCloud, autoLoading);
|
||||
} else {
|
||||
_loader = new mtpFileLoader(_dc, id, _access, _version, locationType(), toFile, size, (saveToCache() ? LoadToCacheAsWell : LoadToFileOnly), fromCloud, autoLoading);
|
||||
}
|
||||
|
||||
_loader->connect(_loader, SIGNAL(progress(FileLoader*)), App::main(), SLOT(documentLoadProgress(FileLoader*)));
|
||||
_loader->connect(_loader, SIGNAL(failed(FileLoader*,bool)), App::main(), SLOT(documentLoadFailed(FileLoader*,bool)));
|
||||
_loader->start();
|
||||
@@ -935,8 +938,12 @@ bool DocumentData::hasRemoteLocation() const {
|
||||
return (_dc != 0 && _access != 0);
|
||||
}
|
||||
|
||||
bool DocumentData::hasWebLocation() const {
|
||||
return _urlLocation.dc() != 0 && _urlLocation.accessHash() != 0;
|
||||
}
|
||||
|
||||
bool DocumentData::isValid() const {
|
||||
return hasRemoteLocation() || !_url.isEmpty();
|
||||
return hasRemoteLocation() || hasWebLocation() || !_url.isEmpty();
|
||||
}
|
||||
|
||||
MTPInputDocument DocumentData::mtpInput() const {
|
||||
@@ -1086,6 +1093,10 @@ void DocumentData::setContentUrl(const QString &url) {
|
||||
_url = url;
|
||||
}
|
||||
|
||||
void DocumentData::setWebLocation(const WebFileLocation &location) {
|
||||
_urlLocation = location;
|
||||
}
|
||||
|
||||
void DocumentData::collectLocalData(DocumentData *local) {
|
||||
if (local == this) return;
|
||||
|
||||
|
@@ -148,7 +148,9 @@ public:
|
||||
bool setRemoteVersion(int32 version); // Returns true if version has changed.
|
||||
void setRemoteLocation(int32 dc, uint64 access);
|
||||
void setContentUrl(const QString &url);
|
||||
void setWebLocation(const WebFileLocation &location);
|
||||
bool hasRemoteLocation() const;
|
||||
bool hasWebLocation() const;
|
||||
bool isValid() const;
|
||||
MTPInputDocument mtpInput() const;
|
||||
|
||||
@@ -198,6 +200,7 @@ private:
|
||||
QString _url;
|
||||
QString _filename;
|
||||
QString _mimeString;
|
||||
WebFileLocation _urlLocation;
|
||||
|
||||
not_null<AuthSession*> _session;
|
||||
|
||||
|
@@ -54,43 +54,9 @@ Invoice ComputeInvoiceData(const MTPDmessageMediaInvoice &data) {
|
||||
if (data.has_receipt_msg_id()) {
|
||||
result.receiptMsgId = data.vreceipt_msg_id.v;
|
||||
}
|
||||
if (data.has_photo() && data.vphoto.type() == mtpc_webDocument) {
|
||||
auto &doc = data.vphoto.c_webDocument();
|
||||
auto imageSize = QSize();
|
||||
for (auto &attribute : doc.vattributes.v) {
|
||||
if (attribute.type() == mtpc_documentAttributeImageSize) {
|
||||
auto &size = attribute.c_documentAttributeImageSize();
|
||||
imageSize = QSize(size.vw.v, size.vh.v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!imageSize.isEmpty()) {
|
||||
auto thumbsize = shrinkToKeepAspect(imageSize.width(), imageSize.height(), 100, 100);
|
||||
auto thumb = ImagePtr(thumbsize.width(), thumbsize.height());
|
||||
|
||||
auto mediumsize = shrinkToKeepAspect(imageSize.width(), imageSize.height(), 320, 320);
|
||||
auto medium = ImagePtr(mediumsize.width(), mediumsize.height());
|
||||
|
||||
// We don't use size from WebDocument, because it is not reliable.
|
||||
// It can be > 0 and different from the real size that we get in upload.WebFile result.
|
||||
auto filesize = 0; // doc.vsize.v;
|
||||
auto full = ImagePtr(
|
||||
WebFileImageLocation(
|
||||
imageSize.width(),
|
||||
imageSize.height(),
|
||||
doc.vdc_id.v,
|
||||
doc.vurl.v,
|
||||
doc.vaccess_hash.v),
|
||||
filesize);
|
||||
auto photoId = rand_value<PhotoId>();
|
||||
result.photo = Auth().data().photo(
|
||||
photoId,
|
||||
uint64(0),
|
||||
unixtime(),
|
||||
thumb,
|
||||
medium,
|
||||
full);
|
||||
}
|
||||
if (data.has_photo()) {
|
||||
const auto thumb = ImagePtr();
|
||||
result.photo = Auth().data().photoFromWeb(data.vphoto, thumb);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@@ -644,6 +644,32 @@ void Session::photoConvert(
|
||||
photoApplyFields(original, data);
|
||||
}
|
||||
|
||||
PhotoData *Session::photoFromWeb(
|
||||
const MTPWebDocument &data,
|
||||
ImagePtr thumb) {
|
||||
const auto full = ImagePtr(data);
|
||||
if (full->isNull()) {
|
||||
return nullptr;
|
||||
}
|
||||
const auto width = full->width();
|
||||
const auto height = full->height();
|
||||
if (thumb->isNull()) {
|
||||
auto thumbsize = shrinkToKeepAspect(width, height, 100, 100);
|
||||
thumb = ImagePtr(thumbsize.width(), thumbsize.height());
|
||||
}
|
||||
|
||||
auto mediumsize = shrinkToKeepAspect(width, height, 320, 320);
|
||||
auto medium = ImagePtr(mediumsize.width(), mediumsize.height());
|
||||
|
||||
return photo(
|
||||
rand_value<PhotoId>(),
|
||||
uint64(0),
|
||||
unixtime(),
|
||||
thumb,
|
||||
medium,
|
||||
full);
|
||||
}
|
||||
|
||||
void Session::photoApplyFields(
|
||||
not_null<PhotoData*> photo,
|
||||
const MTPPhoto &data) {
|
||||
@@ -850,6 +876,59 @@ void Session::documentConvert(
|
||||
}
|
||||
}
|
||||
|
||||
DocumentData *Session::documentFromWeb(
|
||||
const MTPWebDocument &data,
|
||||
ImagePtr thumb) {
|
||||
switch (data.type()) {
|
||||
case mtpc_webDocument:
|
||||
return documentFromWeb(data.c_webDocument(), thumb);
|
||||
|
||||
case mtpc_webDocumentNoProxy:
|
||||
return documentFromWeb(data.c_webDocumentNoProxy(), thumb);
|
||||
|
||||
}
|
||||
Unexpected("Type in Session::documentFromWeb.");
|
||||
}
|
||||
|
||||
DocumentData *Session::documentFromWeb(
|
||||
const MTPDwebDocument &data,
|
||||
ImagePtr thumb) {
|
||||
const auto result = document(
|
||||
rand_value<DocumentId>(),
|
||||
uint64(0),
|
||||
int32(0),
|
||||
unixtime(),
|
||||
data.vattributes.v,
|
||||
data.vmime_type.v,
|
||||
thumb,
|
||||
MTP::maindc(),
|
||||
int32(0), // data.vsize.v
|
||||
StorageImageLocation());
|
||||
result->setWebLocation(WebFileLocation(
|
||||
data.vdc_id.v,
|
||||
data.vurl.v,
|
||||
data.vaccess_hash.v));
|
||||
return result;
|
||||
}
|
||||
|
||||
DocumentData *Session::documentFromWeb(
|
||||
const MTPDwebDocumentNoProxy &data,
|
||||
ImagePtr thumb) {
|
||||
const auto result = document(
|
||||
rand_value<DocumentId>(),
|
||||
uint64(0),
|
||||
int32(0),
|
||||
unixtime(),
|
||||
data.vattributes.v,
|
||||
data.vmime_type.v,
|
||||
thumb,
|
||||
MTP::maindc(),
|
||||
int32(0), // data.vsize.v
|
||||
StorageImageLocation());
|
||||
result->setContentUrl(qs(data.vurl));
|
||||
return result;
|
||||
}
|
||||
|
||||
void Session::documentApplyFields(
|
||||
not_null<DocumentData*> document,
|
||||
const MTPDocument &data) {
|
||||
|
@@ -226,6 +226,7 @@ public:
|
||||
void photoConvert(
|
||||
not_null<PhotoData*> original,
|
||||
const MTPPhoto &data);
|
||||
PhotoData *photoFromWeb(const MTPWebDocument &data, ImagePtr thumb);
|
||||
|
||||
not_null<DocumentData*> document(DocumentId id);
|
||||
not_null<DocumentData*> document(const MTPDocument &data);
|
||||
@@ -247,6 +248,9 @@ public:
|
||||
void documentConvert(
|
||||
not_null<DocumentData*> original,
|
||||
const MTPDocument &data);
|
||||
DocumentData *documentFromWeb(
|
||||
const MTPWebDocument &data,
|
||||
ImagePtr thumb);
|
||||
|
||||
not_null<WebPageData*> webpage(WebPageId id);
|
||||
not_null<WebPageData*> webpage(const MTPWebPage &data);
|
||||
@@ -397,6 +401,12 @@ private:
|
||||
int32 dc,
|
||||
int32 size,
|
||||
const StorageImageLocation &thumbLocation);
|
||||
DocumentData *documentFromWeb(
|
||||
const MTPDwebDocument &data,
|
||||
ImagePtr thumb);
|
||||
DocumentData *documentFromWeb(
|
||||
const MTPDwebDocumentNoProxy &data,
|
||||
ImagePtr thumb);
|
||||
|
||||
void webpageApplyFields(
|
||||
not_null<WebPageData*> page,
|
||||
|
Reference in New Issue
Block a user