mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Allow apply spoiler when editing to another media.
This commit is contained in:
parent
5bee6310c0
commit
bd1d7f4d96
11 changed files with 77 additions and 16 deletions
|
@ -175,12 +175,15 @@ void EditCaptionBox::rebuildPreview() {
|
||||||
Window::GifPauseReason::Layer);
|
Window::GifPauseReason::Layer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
applyChanges();
|
||||||
|
|
||||||
|
_previewHasSpoiler = nullptr;
|
||||||
if (_preparedList.files.empty()) {
|
if (_preparedList.files.empty()) {
|
||||||
const auto media = _historyItem->media();
|
const auto media = _historyItem->media();
|
||||||
const auto photo = media->photo();
|
const auto photo = media->photo();
|
||||||
const auto document = media->document();
|
const auto document = media->document();
|
||||||
|
_isPhoto = (photo != nullptr);
|
||||||
if (photo || document->isVideoFile() || document->isAnimation()) {
|
if (photo || document->isVideoFile() || document->isAnimation()) {
|
||||||
_isPhoto = (photo != nullptr);
|
|
||||||
const auto media = Ui::CreateChild<Ui::ItemSingleMediaPreview>(
|
const auto media = Ui::CreateChild<Ui::ItemSingleMediaPreview>(
|
||||||
this,
|
this,
|
||||||
gifPaused,
|
gifPaused,
|
||||||
|
@ -189,7 +192,6 @@ void EditCaptionBox::rebuildPreview() {
|
||||||
_photoMedia = media->sharedPhotoMedia();
|
_photoMedia = media->sharedPhotoMedia();
|
||||||
_content.reset(media);
|
_content.reset(media);
|
||||||
} else {
|
} else {
|
||||||
_isPhoto = false;
|
|
||||||
_content.reset(Ui::CreateChild<Ui::ItemSingleFilePreview>(
|
_content.reset(Ui::CreateChild<Ui::ItemSingleFilePreview>(
|
||||||
this,
|
this,
|
||||||
_historyItem,
|
_historyItem,
|
||||||
|
@ -203,11 +205,12 @@ void EditCaptionBox::rebuildPreview() {
|
||||||
gifPaused,
|
gifPaused,
|
||||||
file,
|
file,
|
||||||
Ui::AttachControls::Type::EditOnly);
|
Ui::AttachControls::Type::EditOnly);
|
||||||
if (media) {
|
_isPhoto = (media && media->isPhoto());
|
||||||
_isPhoto = media->isPhoto();
|
const auto withCheckbox = _isPhoto && CanBeCompressed(_albumType);
|
||||||
|
if (media && (!withCheckbox || !_asFile)) {
|
||||||
|
_previewHasSpoiler = [media] { return media->hasSpoiler(); };
|
||||||
_content.reset(media);
|
_content.reset(media);
|
||||||
} else {
|
} else {
|
||||||
_isPhoto = false;
|
|
||||||
_content.reset(Ui::CreateChild<Ui::SingleFilePreview>(
|
_content.reset(Ui::CreateChild<Ui::SingleFilePreview>(
|
||||||
this,
|
this,
|
||||||
file,
|
file,
|
||||||
|
@ -299,7 +302,7 @@ void EditCaptionBox::setupControls() {
|
||||||
{}
|
{}
|
||||||
) | rpl::map([=] {
|
) | rpl::map([=] {
|
||||||
return _controller->session().settings().photoEditorHintShown()
|
return _controller->session().settings().photoEditorHintShown()
|
||||||
? _isPhoto
|
? (_isPhoto && !_asFile)
|
||||||
: false;
|
: false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -329,7 +332,9 @@ void EditCaptionBox::setupControls() {
|
||||||
anim::type::instant
|
anim::type::instant
|
||||||
)->entity()->checkedChanges(
|
)->entity()->checkedChanges(
|
||||||
) | rpl::start_with_next([&](bool checked) {
|
) | rpl::start_with_next([&](bool checked) {
|
||||||
|
applyChanges();
|
||||||
_asFile = !checked;
|
_asFile = !checked;
|
||||||
|
rebuildPreview();
|
||||||
}, _controls->lifetime());
|
}, _controls->lifetime());
|
||||||
|
|
||||||
_controls->resizeToWidth(st::sendMediaPreviewSize);
|
_controls->resizeToWidth(st::sendMediaPreviewSize);
|
||||||
|
@ -430,6 +435,8 @@ void EditCaptionBox::setupPhotoEditorEventHandler() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto copy = large->original();
|
auto copy = large->original();
|
||||||
|
const auto wasSpoiler = hasSpoiler();
|
||||||
|
|
||||||
_preparedList = Storage::PrepareMediaFromImage(
|
_preparedList = Storage::PrepareMediaFromImage(
|
||||||
std::move(copy),
|
std::move(copy),
|
||||||
QByteArray(),
|
QByteArray(),
|
||||||
|
@ -437,6 +444,7 @@ void EditCaptionBox::setupPhotoEditorEventHandler() {
|
||||||
|
|
||||||
using ImageInfo = Ui::PreparedFileInformation::Image;
|
using ImageInfo = Ui::PreparedFileInformation::Image;
|
||||||
auto &file = _preparedList.files.front();
|
auto &file = _preparedList.files.front();
|
||||||
|
file.spoiler = wasSpoiler;
|
||||||
const auto image = std::get_if<ImageInfo>(
|
const auto image = std::get_if<ImageInfo>(
|
||||||
&file.information->media);
|
&file.information->media);
|
||||||
|
|
||||||
|
@ -581,11 +589,20 @@ bool EditCaptionBox::setPreparedList(Ui::PreparedList &&list) {
|
||||||
tr::lng_edit_media_album_error(tr::now));
|
tr::lng_edit_media_album_error(tr::now));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const auto wasSpoiler = hasSpoiler();
|
||||||
_preparedList = std::move(list);
|
_preparedList = std::move(list);
|
||||||
|
_preparedList.files.front().spoiler = wasSpoiler;
|
||||||
rebuildPreview();
|
rebuildPreview();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EditCaptionBox::hasSpoiler() const {
|
||||||
|
return _preparedList.files.empty()
|
||||||
|
? (_historyItem->media()
|
||||||
|
&& _historyItem->media()->hasSpoiler())
|
||||||
|
: _preparedList.files.front().spoiler;
|
||||||
|
}
|
||||||
|
|
||||||
void EditCaptionBox::captionResized() {
|
void EditCaptionBox::captionResized() {
|
||||||
updateBoxSize();
|
updateBoxSize();
|
||||||
resizeEvent(0);
|
resizeEvent(0);
|
||||||
|
@ -690,6 +707,12 @@ bool EditCaptionBox::validateLength(const QString &text) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditCaptionBox::applyChanges() {
|
||||||
|
if (!_preparedList.files.empty() && _previewHasSpoiler) {
|
||||||
|
_preparedList.files.front().spoiler = _previewHasSpoiler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EditCaptionBox::save() {
|
void EditCaptionBox::save() {
|
||||||
if (_saveRequestId) {
|
if (_saveRequestId) {
|
||||||
return;
|
return;
|
||||||
|
@ -727,10 +750,14 @@ void EditCaptionBox::save() {
|
||||||
action.replaceMediaOf = item->fullId().msg;
|
action.replaceMediaOf = item->fullId().msg;
|
||||||
|
|
||||||
Storage::ApplyModifications(_preparedList);
|
Storage::ApplyModifications(_preparedList);
|
||||||
|
if (!_preparedList.files.empty()) {
|
||||||
|
_preparedList.files.front().spoiler = false;
|
||||||
|
applyChanges();
|
||||||
|
}
|
||||||
|
|
||||||
_controller->session().api().editMedia(
|
_controller->session().api().editMedia(
|
||||||
std::move(_preparedList),
|
std::move(_preparedList),
|
||||||
(!_asFile && _isPhoto && CanBeCompressed(_albumType))
|
(_isPhoto && !_asFile && CanBeCompressed(_albumType))
|
||||||
? SendMediaType::Photo
|
? SendMediaType::Photo
|
||||||
: SendMediaType::File,
|
: SendMediaType::File,
|
||||||
_field->getTextWithAppliedMarkdown(),
|
_field->getTextWithAppliedMarkdown(),
|
||||||
|
|
|
@ -64,11 +64,13 @@ private:
|
||||||
void setupDragArea();
|
void setupDragArea();
|
||||||
|
|
||||||
bool validateLength(const QString &text) const;
|
bool validateLength(const QString &text) const;
|
||||||
|
void applyChanges();
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
bool fileFromClipboard(not_null<const QMimeData*> data);
|
bool fileFromClipboard(not_null<const QMimeData*> data);
|
||||||
|
|
||||||
int errorTopSkip() const;
|
[[nodiscard]] int errorTopSkip() const;
|
||||||
|
[[nodiscard]] bool hasSpoiler() const;
|
||||||
|
|
||||||
bool setPreparedList(Ui::PreparedList &&list);
|
bool setPreparedList(Ui::PreparedList &&list);
|
||||||
|
|
||||||
|
@ -83,6 +85,7 @@ private:
|
||||||
const base::unique_qptr<Ui::EmojiButton> _emojiToggle;
|
const base::unique_qptr<Ui::EmojiButton> _emojiToggle;
|
||||||
|
|
||||||
base::unique_qptr<Ui::AbstractSinglePreview> _content;
|
base::unique_qptr<Ui::AbstractSinglePreview> _content;
|
||||||
|
Fn<bool()> _previewHasSpoiler;
|
||||||
base::unique_qptr<ChatHelpers::TabbedPanel> _emojiPanel;
|
base::unique_qptr<ChatHelpers::TabbedPanel> _emojiPanel;
|
||||||
base::unique_qptr<QObject> _emojiFilter;
|
base::unique_qptr<QObject> _emojiFilter;
|
||||||
|
|
||||||
|
|
|
@ -232,16 +232,20 @@ void SendFilesBox::Block::applyChanges() {
|
||||||
if (_isSingleMedia) {
|
if (_isSingleMedia) {
|
||||||
const auto media = static_cast<Ui::SingleMediaPreview*>(
|
const auto media = static_cast<Ui::SingleMediaPreview*>(
|
||||||
_preview.get());
|
_preview.get());
|
||||||
(*_items)[_from].spoiler = media->hasSpoiler();
|
if (media->canHaveSpoiler()) {
|
||||||
|
(*_items)[_from].spoiler = media->hasSpoiler();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto album = static_cast<Ui::AlbumPreview*>(_preview.get());
|
const auto album = static_cast<Ui::AlbumPreview*>(_preview.get());
|
||||||
const auto order = album->takeOrder();
|
const auto order = album->takeOrder();
|
||||||
const auto spoilered = album->collectSpoileredIndices();
|
|
||||||
const auto guard = gsl::finally([&] {
|
const auto guard = gsl::finally([&] {
|
||||||
|
const auto spoilered = album->collectSpoileredIndices();
|
||||||
for (auto i = 0, count = int(order.size()); i != count; ++i) {
|
for (auto i = 0, count = int(order.size()); i != count; ++i) {
|
||||||
(*_items)[_from + i].spoiler = spoilered.contains(i);
|
if (album->canHaveSpoiler(i)) {
|
||||||
|
(*_items)[_from + i].spoiler = spoilered.contains(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const auto isIdentity = [&] {
|
const auto isIdentity = [&] {
|
||||||
|
@ -1095,6 +1099,9 @@ void SendFilesBox::send(
|
||||||
saveSendWaySettings();
|
saveSendWaySettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto &item : _list.files) {
|
||||||
|
item.spoiler = false;
|
||||||
|
}
|
||||||
for (auto &block : _blocks) {
|
for (auto &block : _blocks) {
|
||||||
block.applyChanges();
|
block.applyChanges();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,12 +51,14 @@ rpl::producer<> AbstractSingleMediaPreview::modifyRequests() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractSingleMediaPreview::setSendWay(SendFilesWay way) {
|
void AbstractSingleMediaPreview::setSendWay(SendFilesWay way) {
|
||||||
if (_sendWay != way) {
|
_sendWay = way;
|
||||||
_sendWay = way;
|
|
||||||
}
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendFilesWay AbstractSingleMediaPreview::sendWay() const {
|
||||||
|
return _sendWay;
|
||||||
|
}
|
||||||
|
|
||||||
void AbstractSingleMediaPreview::setSpoiler(bool spoiler) {
|
void AbstractSingleMediaPreview::setSpoiler(bool spoiler) {
|
||||||
_spoiler = spoiler
|
_spoiler = spoiler
|
||||||
? std::make_unique<SpoilerAnimation>([=] { update(); })
|
? std::make_unique<SpoilerAnimation>([=] { update(); })
|
||||||
|
@ -68,6 +70,10 @@ bool AbstractSingleMediaPreview::hasSpoiler() const {
|
||||||
return _spoiler != nullptr;
|
return _spoiler != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AbstractSingleMediaPreview::canHaveSpoiler() const {
|
||||||
|
return supportsSpoilers();
|
||||||
|
}
|
||||||
|
|
||||||
void AbstractSingleMediaPreview::preparePreview(QImage preview) {
|
void AbstractSingleMediaPreview::preparePreview(QImage preview) {
|
||||||
auto maxW = 0;
|
auto maxW = 0;
|
||||||
auto maxH = 0;
|
auto maxH = 0;
|
||||||
|
@ -149,7 +155,7 @@ void AbstractSingleMediaPreview::resizeEvent(QResizeEvent *e) {
|
||||||
void AbstractSingleMediaPreview::paintEvent(QPaintEvent *e) {
|
void AbstractSingleMediaPreview::paintEvent(QPaintEvent *e) {
|
||||||
auto p = QPainter(this);
|
auto p = QPainter(this);
|
||||||
|
|
||||||
auto takenSpoiler = (drawBackground() || _sendWay.sendImagesAsPhotos())
|
auto takenSpoiler = supportsSpoilers()
|
||||||
? nullptr
|
? nullptr
|
||||||
: base::take(_spoiler);
|
: base::take(_spoiler);
|
||||||
const auto guard = gsl::finally([&] {
|
const auto guard = gsl::finally([&] {
|
||||||
|
@ -251,7 +257,7 @@ void AbstractSingleMediaPreview::applyCursor(style::cursor cursor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractSingleMediaPreview::showContextMenu(QPoint position) {
|
void AbstractSingleMediaPreview::showContextMenu(QPoint position) {
|
||||||
if (!_sendWay.sendImagesAsPhotos()) {
|
if (!_sendWay.sendImagesAsPhotos() || !supportsSpoilers()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_menu = base::make_unique_q<Ui::PopupMenu>(
|
_menu = base::make_unique_q<Ui::PopupMenu>(
|
||||||
|
|
|
@ -22,6 +22,7 @@ public:
|
||||||
~AbstractSingleMediaPreview();
|
~AbstractSingleMediaPreview();
|
||||||
|
|
||||||
void setSendWay(SendFilesWay way);
|
void setSendWay(SendFilesWay way);
|
||||||
|
[[nodiscard]] SendFilesWay sendWay() const;
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<> deleteRequests() const override;
|
[[nodiscard]] rpl::producer<> deleteRequests() const override;
|
||||||
[[nodiscard]] rpl::producer<> editRequests() const override;
|
[[nodiscard]] rpl::producer<> editRequests() const override;
|
||||||
|
@ -31,8 +32,10 @@ public:
|
||||||
|
|
||||||
void setSpoiler(bool spoiler);
|
void setSpoiler(bool spoiler);
|
||||||
[[nodiscard]] bool hasSpoiler() const;
|
[[nodiscard]] bool hasSpoiler() const;
|
||||||
|
[[nodiscard]] bool canHaveSpoiler() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool supportsSpoilers() const = 0;
|
||||||
virtual bool drawBackground() const = 0;
|
virtual bool drawBackground() const = 0;
|
||||||
virtual bool tryPaintAnimation(QPainter &p) = 0;
|
virtual bool tryPaintAnimation(QPainter &p) = 0;
|
||||||
virtual bool isAnimatedPreviewReady() const = 0;
|
virtual bool isAnimatedPreviewReady() const = 0;
|
||||||
|
|
|
@ -77,6 +77,10 @@ base::flat_set<int> AlbumPreview::collectSpoileredIndices() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AlbumPreview::canHaveSpoiler(int index) const {
|
||||||
|
return _sendWay.sendImagesAsPhotos();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<int> AlbumPreview::takeOrder() {
|
std::vector<int> AlbumPreview::takeOrder() {
|
||||||
//Expects(_thumbs.size() == _order.size());
|
//Expects(_thumbs.size() == _order.size());
|
||||||
//Expects(_itemsShownDimensions.size() == _order.size());
|
//Expects(_itemsShownDimensions.size() == _order.size());
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
void setSendWay(SendFilesWay way);
|
void setSendWay(SendFilesWay way);
|
||||||
|
|
||||||
[[nodiscard]] base::flat_set<int> collectSpoileredIndices();
|
[[nodiscard]] base::flat_set<int> collectSpoileredIndices();
|
||||||
|
[[nodiscard]] bool canHaveSpoiler(int index) const;
|
||||||
[[nodiscard]] std::vector<int> takeOrder();
|
[[nodiscard]] std::vector<int> takeOrder();
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<int> thumbDeleted() const {
|
[[nodiscard]] rpl::producer<int> thumbDeleted() const {
|
||||||
|
|
|
@ -190,6 +190,10 @@ void ItemSingleMediaPreview::startStreamedPlayer() {
|
||||||
_streamed->play(options);
|
_streamed->play(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ItemSingleMediaPreview::supportsSpoilers() const {
|
||||||
|
return false; // We are not allowed to change existing spoiler setting.
|
||||||
|
}
|
||||||
|
|
||||||
bool ItemSingleMediaPreview::drawBackground() const {
|
bool ItemSingleMediaPreview::drawBackground() const {
|
||||||
return true; // A sticker can't be here.
|
return true; // A sticker can't be here.
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
std::shared_ptr<::Data::PhotoMedia> sharedPhotoMedia() const;
|
std::shared_ptr<::Data::PhotoMedia> sharedPhotoMedia() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool supportsSpoilers() const override;
|
||||||
bool drawBackground() const override;
|
bool drawBackground() const override;
|
||||||
bool tryPaintAnimation(QPainter &p) override;
|
bool tryPaintAnimation(QPainter &p) override;
|
||||||
bool isAnimatedPreviewReady() const override;
|
bool isAnimatedPreviewReady() const override;
|
||||||
|
|
|
@ -72,6 +72,10 @@ SingleMediaPreview::SingleMediaPreview(
|
||||||
setSpoiler(spoiler);
|
setSpoiler(spoiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SingleMediaPreview::supportsSpoilers() const {
|
||||||
|
return !_sticker || sendWay().sendImagesAsPhotos();
|
||||||
|
}
|
||||||
|
|
||||||
bool SingleMediaPreview::drawBackground() const {
|
bool SingleMediaPreview::drawBackground() const {
|
||||||
return !_sticker;
|
return !_sticker;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
AttachControls::Type type);
|
AttachControls::Type type);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool supportsSpoilers() const override;
|
||||||
bool drawBackground() const override;
|
bool drawBackground() const override;
|
||||||
bool tryPaintAnimation(QPainter &p) override;
|
bool tryPaintAnimation(QPainter &p) override;
|
||||||
bool isAnimatedPreviewReady() const override;
|
bool isAnimatedPreviewReady() const override;
|
||||||
|
|
Loading…
Add table
Reference in a new issue