2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Fixed edit of long media caption with emoji.

This commit is contained in:
23rd
2024-02-27 04:19:15 +03:00
committed by John Preston
parent d252427e34
commit a77c547a62
6 changed files with 49 additions and 45 deletions

View File

@@ -1953,6 +1953,7 @@ bool HistoryWidget::applyDraft(FieldHistoryAction fieldHistoryAction) {
updateControlsVisibility();
updateControlsGeometry();
refreshTopBarActiveChat();
checkCharsLimitation();
if (_editMsgId) {
updateReplyEditTexts();
if (!_replyEditMsg) {
@@ -3869,17 +3870,12 @@ void HistoryWidget::saveEditMsg() {
return;
}
const auto webPageDraft = _preview->draft();
auto left = prepareTextForEditMsg();
auto sending = TextWithEntities();
const auto sending = prepareTextForEditMsg();
const auto originalLeftSize = left.text.size();
const auto hasMediaWithCaption = item
&& item->media()
&& item->media()->allowsEditCaption();
const auto maxCaptionSize = !hasMediaWithCaption
? MaxMessageSize
: Data::PremiumLimits(&session()).captionLengthCurrent();
if (!TextUtilities::CutPart(sending, left, maxCaptionSize)
if (sending.text.isEmpty()
&& (webPageDraft.removed
|| webPageDraft.url.isEmpty()
|| !webPageDraft.manual)
@@ -3888,11 +3884,16 @@ void HistoryWidget::saveEditMsg() {
controller()->show(
Box<DeleteMessagesBox>(item, suggestModerateActions));
return;
} else if (!left.text.isEmpty()) {
const auto remove = originalLeftSize - maxCaptionSize;
controller()->showToast(
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
return;
} else {
const auto maxCaptionSize = !hasMediaWithCaption
? MaxMessageSize
: Data::PremiumLimits(&session()).captionLengthCurrent();
const auto remove = Ui::FieldCharacterCount(_field) - maxCaptionSize;
if (remove > 0) {
controller()->showToast(
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
return;
}
}
const auto weak = Ui::MakeWeak(this);
@@ -7319,9 +7320,8 @@ void HistoryWidget::checkCharsLimitation() {
_charsLimitation = nullptr;
return;
}
const auto limits = Data::PremiumLimits(&session());
const auto left = prepareTextForEditMsg();
const auto remove = left.text.size() - limits.captionLengthCurrent();
const auto remove = Ui::FieldCharacterCount(_field)
- Data::PremiumLimits(&session()).captionLengthCurrent();
if (remove > 0) {
if (!_charsLimitation) {
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(

View File

@@ -3150,6 +3150,10 @@ not_null<Ui::RpWidget*> ComposeControls::likeAnimationTarget() const {
return _like;
}
int ComposeControls::fieldCharacterCount() const {
return Ui::FieldCharacterCount(_field);
}
bool ComposeControls::preventsClose(Fn<void()> &&continueCallback) const {
if (_voiceRecordBar->isActive()) {
_voiceRecordBar->showDiscardBox(std::move(continueCallback));
@@ -3323,9 +3327,8 @@ void ComposeControls::checkCharsLimitation() {
_charsLimitation = nullptr;
return;
}
const auto limits = Data::PremiumLimits(&session());
const auto left = prepareTextForEditMsg();
const auto remove = left.text.size() - limits.captionLengthCurrent();
const auto remove = Ui::FieldCharacterCount(_field)
- Data::PremiumLimits(&session()).captionLengthCurrent();
if (remove > 0) {
if (!_charsLimitation) {
using namespace Controls;

View File

@@ -228,6 +228,7 @@ public:
[[nodiscard]] rpl::producer<bool> hasSendTextValue() const;
[[nodiscard]] rpl::producer<bool> fieldMenuShownValue() const;
[[nodiscard]] not_null<Ui::RpWidget*> likeAnimationTarget() const;
[[nodiscard]] int fieldCharacterCount() const;
[[nodiscard]] TextWithEntities prepareTextForEditMsg() const;

View File

@@ -1170,29 +1170,29 @@ void RepliesWidget::edit(
return;
}
const auto webpage = _composeControls->webPageDraft();
auto sending = TextWithEntities();
auto left = _composeControls->prepareTextForEditMsg();
const auto sending = _composeControls->prepareTextForEditMsg();
const auto originalLeftSize = left.text.size();
const auto hasMediaWithCaption = item
&& item->media()
&& item->media()->allowsEditCaption();
const auto maxCaptionSize = !hasMediaWithCaption
? MaxMessageSize
: Data::PremiumLimits(&session()).captionLengthCurrent();
if (!TextUtilities::CutPart(sending, left, maxCaptionSize)
&& !hasMediaWithCaption) {
if (sending.text.isEmpty() && !hasMediaWithCaption) {
if (item) {
controller()->show(Box<DeleteMessagesBox>(item, false));
} else {
doSetInnerFocus();
}
return;
} else if (!left.text.isEmpty()) {
const auto remove = originalLeftSize - maxCaptionSize;
controller()->showToast(
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
return;
} else {
const auto maxCaptionSize = !hasMediaWithCaption
? MaxMessageSize
: Data::PremiumLimits(&session()).captionLengthCurrent();
const auto remove = _composeControls->fieldCharacterCount()
- maxCaptionSize;
if (remove > 0) {
controller()->showToast(
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
return;
}
}
lifetime().add([=] {

View File

@@ -635,29 +635,29 @@ void ScheduledWidget::edit(
return;
}
const auto webpage = _composeControls->webPageDraft();
auto sending = TextWithEntities();
auto left = _composeControls->prepareTextForEditMsg();
const auto sending = _composeControls->prepareTextForEditMsg();
const auto originalLeftSize = left.text.size();
const auto hasMediaWithCaption = item
&& item->media()
&& item->media()->allowsEditCaption();
const auto maxCaptionSize = !hasMediaWithCaption
? MaxMessageSize
: Data::PremiumLimits(&session()).captionLengthCurrent();
if (!TextUtilities::CutPart(sending, left, maxCaptionSize)
&& !hasMediaWithCaption) {
if (sending.text.isEmpty() && !hasMediaWithCaption) {
if (item) {
controller()->show(Box<DeleteMessagesBox>(item, false));
} else {
_composeControls->focus();
}
return;
} else if (!left.text.isEmpty()) {
const auto remove = originalLeftSize - maxCaptionSize;
controller()->showToast(
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
return;
} else {
const auto maxCaptionSize = !hasMediaWithCaption
? MaxMessageSize
: Data::PremiumLimits(&session()).captionLengthCurrent();
const auto remove = _composeControls->fieldCharacterCount()
- maxCaptionSize;
if (remove > 0) {
controller()->showToast(
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
return;
}
}
lifetime().add([=] {