2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-05 09:05:14 +00:00

Allow apply spoiler when editing to another media.

This commit is contained in:
John Preston
2022-12-13 17:31:54 +04:00
parent 5bee6310c0
commit bd1d7f4d96
11 changed files with 77 additions and 16 deletions

View File

@@ -175,12 +175,15 @@ void EditCaptionBox::rebuildPreview() {
Window::GifPauseReason::Layer);
};
applyChanges();
_previewHasSpoiler = nullptr;
if (_preparedList.files.empty()) {
const auto media = _historyItem->media();
const auto photo = media->photo();
const auto document = media->document();
_isPhoto = (photo != nullptr);
if (photo || document->isVideoFile() || document->isAnimation()) {
_isPhoto = (photo != nullptr);
const auto media = Ui::CreateChild<Ui::ItemSingleMediaPreview>(
this,
gifPaused,
@@ -189,7 +192,6 @@ void EditCaptionBox::rebuildPreview() {
_photoMedia = media->sharedPhotoMedia();
_content.reset(media);
} else {
_isPhoto = false;
_content.reset(Ui::CreateChild<Ui::ItemSingleFilePreview>(
this,
_historyItem,
@@ -203,11 +205,12 @@ void EditCaptionBox::rebuildPreview() {
gifPaused,
file,
Ui::AttachControls::Type::EditOnly);
if (media) {
_isPhoto = media->isPhoto();
_isPhoto = (media && media->isPhoto());
const auto withCheckbox = _isPhoto && CanBeCompressed(_albumType);
if (media && (!withCheckbox || !_asFile)) {
_previewHasSpoiler = [media] { return media->hasSpoiler(); };
_content.reset(media);
} else {
_isPhoto = false;
_content.reset(Ui::CreateChild<Ui::SingleFilePreview>(
this,
file,
@@ -299,7 +302,7 @@ void EditCaptionBox::setupControls() {
{}
) | rpl::map([=] {
return _controller->session().settings().photoEditorHintShown()
? _isPhoto
? (_isPhoto && !_asFile)
: false;
});
@@ -329,7 +332,9 @@ void EditCaptionBox::setupControls() {
anim::type::instant
)->entity()->checkedChanges(
) | rpl::start_with_next([&](bool checked) {
applyChanges();
_asFile = !checked;
rebuildPreview();
}, _controls->lifetime());
_controls->resizeToWidth(st::sendMediaPreviewSize);
@@ -430,6 +435,8 @@ void EditCaptionBox::setupPhotoEditorEventHandler() {
return;
}
auto copy = large->original();
const auto wasSpoiler = hasSpoiler();
_preparedList = Storage::PrepareMediaFromImage(
std::move(copy),
QByteArray(),
@@ -437,6 +444,7 @@ void EditCaptionBox::setupPhotoEditorEventHandler() {
using ImageInfo = Ui::PreparedFileInformation::Image;
auto &file = _preparedList.files.front();
file.spoiler = wasSpoiler;
const auto image = std::get_if<ImageInfo>(
&file.information->media);
@@ -581,11 +589,20 @@ bool EditCaptionBox::setPreparedList(Ui::PreparedList &&list) {
tr::lng_edit_media_album_error(tr::now));
return false;
}
const auto wasSpoiler = hasSpoiler();
_preparedList = std::move(list);
_preparedList.files.front().spoiler = wasSpoiler;
rebuildPreview();
return true;
}
bool EditCaptionBox::hasSpoiler() const {
return _preparedList.files.empty()
? (_historyItem->media()
&& _historyItem->media()->hasSpoiler())
: _preparedList.files.front().spoiler;
}
void EditCaptionBox::captionResized() {
updateBoxSize();
resizeEvent(0);
@@ -690,6 +707,12 @@ bool EditCaptionBox::validateLength(const QString &text) const {
return false;
}
void EditCaptionBox::applyChanges() {
if (!_preparedList.files.empty() && _previewHasSpoiler) {
_preparedList.files.front().spoiler = _previewHasSpoiler();
}
}
void EditCaptionBox::save() {
if (_saveRequestId) {
return;
@@ -727,10 +750,14 @@ void EditCaptionBox::save() {
action.replaceMediaOf = item->fullId().msg;
Storage::ApplyModifications(_preparedList);
if (!_preparedList.files.empty()) {
_preparedList.files.front().spoiler = false;
applyChanges();
}
_controller->session().api().editMedia(
std::move(_preparedList),
(!_asFile && _isPhoto && CanBeCompressed(_albumType))
(_isPhoto && !_asFile && CanBeCompressed(_albumType))
? SendMediaType::Photo
: SendMediaType::File,
_field->getTextWithAppliedMarkdown(),