Added sending info of stickered photos.

This commit is contained in:
23rd 2021-03-14 12:46:17 +03:00
parent bc316a2536
commit e05343d721
15 changed files with 113 additions and 28 deletions

View File

@ -165,22 +165,30 @@ void EditMessageWithUploadedDocument(
HistoryItem *item,
const MTPInputFile &file,
const std::optional<MTPInputFile> &thumb,
SendOptions options) {
SendOptions options,
std::vector<MTPInputDocument> attachedStickers) {
if (!item || !item->media() || !item->media()->document()) {
return;
}
const auto media = PrepareUploadedDocument(item, file, thumb);
const auto media = PrepareUploadedDocument(
item,
file,
thumb,
std::move(attachedStickers));
EditMessageWithUploadedMedia(item, options, media);
}
void EditMessageWithUploadedPhoto(
HistoryItem *item,
const MTPInputFile &file,
SendOptions options) {
SendOptions options,
std::vector<MTPInputDocument> attachedStickers) {
if (!item || !item->media() || !item->media()->photo()) {
return;
}
const auto media = PrepareUploadedPhoto(file);
const auto media = PrepareUploadedPhoto(
file,
std::move(attachedStickers));
EditMessageWithUploadedMedia(item, options, media);
}

View File

@ -31,12 +31,14 @@ void EditMessageWithUploadedDocument(
HistoryItem *item,
const MTPInputFile &file,
const std::optional<MTPInputFile> &thumb,
SendOptions options);
SendOptions options,
std::vector<MTPInputDocument> attachedStickers);
void EditMessageWithUploadedPhoto(
HistoryItem *item,
const MTPInputFile &file,
SendOptions options);
SendOptions options,
std::vector<MTPInputDocument> attachedStickers);
mtpRequestId EditCaption(
not_null<HistoryItem*> item,

View File

@ -73,18 +73,24 @@ MTPVector<MTPDocumentAttribute> ComposeSendingDocumentAttributes(
} // namespace
MTPInputMedia PrepareUploadedPhoto(const MTPInputFile &file) {
MTPInputMedia PrepareUploadedPhoto(
const MTPInputFile &file,
std::vector<MTPInputDocument> attachedStickers) {
const auto flags = attachedStickers.empty()
? MTPDinputMediaUploadedPhoto::Flags(0)
: MTPDinputMediaUploadedPhoto::Flag::f_stickers;
return MTP_inputMediaUploadedPhoto(
MTP_flags(0),
MTP_flags(flags),
file,
MTPVector<MTPInputDocument>(),
MTP_vector<MTPInputDocument>(ranges::to<QVector>(attachedStickers)),
MTP_int(0));
}
MTPInputMedia PrepareUploadedDocument(
not_null<HistoryItem*> item,
const MTPInputFile &file,
const std::optional<MTPInputFile> &thumb) {
const std::optional<MTPInputFile> &thumb,
std::vector<MTPInputDocument> attachedStickers) {
if (!item || !item->media() || !item->media()->document()) {
return MTP_inputMediaEmpty();
}
@ -92,7 +98,8 @@ MTPInputMedia PrepareUploadedDocument(
using DocFlags = MTPDinputMediaUploadedDocument::Flag;
const auto flags = emptyFlag
| (thumb ? DocFlags::f_thumb : emptyFlag)
| (item->groupId() ? DocFlags::f_nosound_video : emptyFlag);
| (item->groupId() ? DocFlags::f_nosound_video : emptyFlag)
| (attachedStickers.empty() ? DocFlags::f_stickers : emptyFlag);
const auto document = item->media()->document();
return MTP_inputMediaUploadedDocument(
MTP_flags(flags),
@ -100,7 +107,7 @@ MTPInputMedia PrepareUploadedDocument(
thumb.value_or(MTPInputFile()),
MTP_string(document->mimeString()),
ComposeSendingDocumentAttributes(document),
MTPVector<MTPInputDocument>(),
MTP_vector<MTPInputDocument>(ranges::to<QVector>(attachedStickers)),
MTP_int(0));
}

View File

@ -11,11 +11,14 @@ class HistoryItem;
namespace Api {
MTPInputMedia PrepareUploadedPhoto(const MTPInputFile &file);
MTPInputMedia PrepareUploadedPhoto(
const MTPInputFile &file,
std::vector<MTPInputDocument> attachedStickers);
MTPInputMedia PrepareUploadedDocument(
not_null<HistoryItem*> item,
const MTPInputFile &file,
const std::optional<MTPInputFile> &thumb);
const std::optional<MTPInputFile> &thumb,
std::vector<MTPInputDocument> attachedStickers);
} // namespace Api

View File

@ -3947,9 +3947,12 @@ void ApiWrap::sendFile(
void ApiWrap::sendUploadedPhoto(
FullMsgId localId,
const MTPInputFile &file,
Api::SendOptions options) {
Api::SendOptions options,
std::vector<MTPInputDocument> attachedStickers) {
if (const auto item = _session->data().message(localId)) {
const auto media = Api::PrepareUploadedPhoto(file);
const auto media = Api::PrepareUploadedPhoto(
file,
std::move(attachedStickers));
if (const auto groupId = item->groupId()) {
uploadAlbumMedia(item, groupId, media);
} else {
@ -3962,12 +3965,17 @@ void ApiWrap::sendUploadedDocument(
FullMsgId localId,
const MTPInputFile &file,
const std::optional<MTPInputFile> &thumb,
Api::SendOptions options) {
Api::SendOptions options,
std::vector<MTPInputDocument> attachedStickers) {
if (const auto item = _session->data().message(localId)) {
if (!item->media() || !item->media()->document()) {
return;
}
const auto media = Api::PrepareUploadedDocument(item, file, thumb);
const auto media = Api::PrepareUploadedDocument(
item,
file,
thumb,
std::move(attachedStickers));
const auto groupId = item->groupId();
if (groupId) {
uploadAlbumMedia(item, groupId, media);

View File

@ -410,12 +410,14 @@ public:
void sendUploadedPhoto(
FullMsgId localId,
const MTPInputFile &file,
Api::SendOptions options);
Api::SendOptions options,
std::vector<MTPInputDocument> attachedStickers);
void sendUploadedDocument(
FullMsgId localId,
const MTPInputFile &file,
const std::optional<MTPInputFile> &thumb,
Api::SendOptions options);
Api::SendOptions options,
std::vector<MTPInputDocument> attachedStickers);
void cancelLocalItem(not_null<HistoryItem*> item);

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "editor/scene_item_canvas.h"
#include "editor/scene_item_line.h"
#include "editor/scene_item_sticker.h"
#include "ui/rp_widget.h"
#include <QGraphicsSceneMouseEvent>
@ -99,6 +100,18 @@ std::vector<QGraphicsItem*> Scene::items(Qt::SortOrder order) const {
return filteredItems;
}
std::vector<MTPInputDocument> Scene::attachedStickers() const {
const auto allItems = items();
return ranges::views::all(
allItems
) | ranges::views::filter([](QGraphicsItem *i) {
return i->isVisible() && (i->type() == ItemSticker::Type);
}) | ranges::views::transform([](QGraphicsItem *i) {
return qgraphicsitem_cast<ItemSticker*>(i)->sticker();
}) | ranges::to_vector;
}
Scene::~Scene() {
}

View File

@ -34,6 +34,7 @@ public:
[[nodiscard]] rpl::producer<> addsItem() const;
[[nodiscard]] rpl::producer<> mousePresses() const;
[[nodiscard]] std::vector<MTPInputDocument> attachedStickers() const;
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;

View File

@ -35,6 +35,7 @@ public:
QPainter *p,
const QStyleOptionGraphicsItem *option,
QWidget *widget) override;
int type() const override;
protected:
enum HandleType {
None,
@ -46,7 +47,6 @@ protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
int type() const override;
QRectF innerRect() const;
int size() const;

View File

@ -85,4 +85,12 @@ void ItemSticker::paint(
ItemBase::paint(p, option, w);
}
MTPInputDocument ItemSticker::sticker() const {
return _document->mtpInput();
}
int ItemSticker::type() const {
return Type;
}
} // namespace Editor

View File

@ -21,7 +21,7 @@ namespace Editor {
class ItemSticker : public ItemBase {
public:
enum { Type = ItemBase::Type + 1 };
enum { Type = ItemBase::Type + 2 };
ItemSticker(
not_null<DocumentData*> document,
@ -33,6 +33,8 @@ public:
QPainter *p,
const QStyleOptionGraphicsItem *option,
QWidget *widget) override;
MTPInputDocument sticker() const;
int type() const override;
private:
const not_null<DocumentData*> _document;
const std::shared_ptr<Data::DocumentMedia> _mediaView;

View File

@ -161,12 +161,17 @@ Uploader::Uploader(not_null<ApiWrap*> api)
) | rpl::start_with_next([=](const UploadedPhoto &data) {
if (data.edit) {
const auto item = session->data().message(data.fullId);
Api::EditMessageWithUploadedPhoto(item, data.file, data.options);
Api::EditMessageWithUploadedPhoto(
item,
data.file,
data.options,
data.attachedStickers);
} else {
_api->sendUploadedPhoto(
data.fullId,
data.file,
data.options);
data.options,
data.attachedStickers);
}
}, _lifetime);
@ -178,13 +183,15 @@ Uploader::Uploader(not_null<ApiWrap*> api)
item,
data.file,
data.thumb,
data.options);
data.options,
data.attachedStickers);
} else {
_api->sendUploadedDocument(
data.fullId,
data.file,
data.thumb,
data.options);
data.options,
data.attachedStickers);
}
}, _lifetime);
@ -448,6 +455,9 @@ void Uploader::sendNext() {
: Api::SendOptions();
const auto edit = uploadingData.file &&
uploadingData.file->to.replaceMediaOf;
const auto attachedStickers = uploadingData.file
? uploadingData.file->attachedStickers
: std::vector<MTPInputDocument>();
if (uploadingData.type() == SendMediaType::Photo) {
auto photoFilename = uploadingData.filename();
if (!photoFilename.endsWith(qstr(".jpg"), Qt::CaseInsensitive)) {
@ -464,7 +474,12 @@ void Uploader::sendNext() {
MTP_int(uploadingData.partsCount),
MTP_string(photoFilename),
MTP_bytes(md5));
_photoReady.fire({ uploadingId, options, file, edit });
_photoReady.fire({
uploadingId,
options,
file,
edit,
attachedStickers });
} else if (uploadingData.type() == SendMediaType::File
|| uploadingData.type() == SendMediaType::ThemeFile
|| uploadingData.type() == SendMediaType::Audio) {
@ -502,7 +517,8 @@ void Uploader::sendNext() {
options,
file,
thumb,
edit });
edit,
attachedStickers });
} else if (uploadingData.type() == SendMediaType::Secure) {
_secureReady.fire({
uploadingId,

View File

@ -33,6 +33,7 @@ struct UploadedPhoto {
Api::SendOptions options;
MTPInputFile file;
bool edit = false;
std::vector<MTPInputDocument> attachedStickers;
};
struct UploadedDocument {
@ -41,6 +42,7 @@ struct UploadedDocument {
MTPInputFile file;
std::optional<MTPInputFile> thumb;
bool edit = false;
std::vector<MTPInputDocument> attachedStickers;
};
struct UploadSecureProgress {

View File

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/mime_type.h"
#include "base/unixtime.h"
#include "base/qt_adapters.h"
#include "editor/scene.h" // Editor::Scene::attachedStickers
#include "media/audio/media_audio.h"
#include "media/clip/media_clip_reader.h"
#include "mtproto/facade.h"
@ -952,6 +953,16 @@ void FileLoadTask::process(Args &&args) {
_type = SendMediaType::File;
}
if (_information) {
if (auto image = std::get_if<Ui::PreparedFileInformation::Image>(
&_information->media)) {
if (image->modifications.paint) {
_result->attachedStickers =
image->modifications.paint->attachedStickers();
}
}
}
_result->type = _type;
_result->filepath = _filepath;
_result->content = _content;

View File

@ -267,6 +267,8 @@ struct FileLoadResult {
PreparedPhotoThumbs photoThumbs;
TextWithTags caption;
std::vector<MTPInputDocument> attachedStickers;
void setFileData(const QByteArray &filedata);
void setThumbData(const QByteArray &thumbdata);