mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-03 16:05:57 +00:00
Fixed edit of long media caption with emoji.
This commit is contained in:
@@ -1953,6 +1953,7 @@ bool HistoryWidget::applyDraft(FieldHistoryAction fieldHistoryAction) {
|
|||||||
updateControlsVisibility();
|
updateControlsVisibility();
|
||||||
updateControlsGeometry();
|
updateControlsGeometry();
|
||||||
refreshTopBarActiveChat();
|
refreshTopBarActiveChat();
|
||||||
|
checkCharsLimitation();
|
||||||
if (_editMsgId) {
|
if (_editMsgId) {
|
||||||
updateReplyEditTexts();
|
updateReplyEditTexts();
|
||||||
if (!_replyEditMsg) {
|
if (!_replyEditMsg) {
|
||||||
@@ -3869,17 +3870,12 @@ void HistoryWidget::saveEditMsg() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto webPageDraft = _preview->draft();
|
const auto webPageDraft = _preview->draft();
|
||||||
auto left = prepareTextForEditMsg();
|
const auto sending = prepareTextForEditMsg();
|
||||||
auto sending = TextWithEntities();
|
|
||||||
|
|
||||||
const auto originalLeftSize = left.text.size();
|
|
||||||
const auto hasMediaWithCaption = item
|
const auto hasMediaWithCaption = item
|
||||||
&& item->media()
|
&& item->media()
|
||||||
&& item->media()->allowsEditCaption();
|
&& item->media()->allowsEditCaption();
|
||||||
const auto maxCaptionSize = !hasMediaWithCaption
|
if (sending.text.isEmpty()
|
||||||
? MaxMessageSize
|
|
||||||
: Data::PremiumLimits(&session()).captionLengthCurrent();
|
|
||||||
if (!TextUtilities::CutPart(sending, left, maxCaptionSize)
|
|
||||||
&& (webPageDraft.removed
|
&& (webPageDraft.removed
|
||||||
|| webPageDraft.url.isEmpty()
|
|| webPageDraft.url.isEmpty()
|
||||||
|| !webPageDraft.manual)
|
|| !webPageDraft.manual)
|
||||||
@@ -3888,11 +3884,16 @@ void HistoryWidget::saveEditMsg() {
|
|||||||
controller()->show(
|
controller()->show(
|
||||||
Box<DeleteMessagesBox>(item, suggestModerateActions));
|
Box<DeleteMessagesBox>(item, suggestModerateActions));
|
||||||
return;
|
return;
|
||||||
} else if (!left.text.isEmpty()) {
|
} else {
|
||||||
const auto remove = originalLeftSize - maxCaptionSize;
|
const auto maxCaptionSize = !hasMediaWithCaption
|
||||||
controller()->showToast(
|
? MaxMessageSize
|
||||||
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
|
: Data::PremiumLimits(&session()).captionLengthCurrent();
|
||||||
return;
|
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);
|
const auto weak = Ui::MakeWeak(this);
|
||||||
@@ -7319,9 +7320,8 @@ void HistoryWidget::checkCharsLimitation() {
|
|||||||
_charsLimitation = nullptr;
|
_charsLimitation = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto limits = Data::PremiumLimits(&session());
|
const auto remove = Ui::FieldCharacterCount(_field)
|
||||||
const auto left = prepareTextForEditMsg();
|
- Data::PremiumLimits(&session()).captionLengthCurrent();
|
||||||
const auto remove = left.text.size() - limits.captionLengthCurrent();
|
|
||||||
if (remove > 0) {
|
if (remove > 0) {
|
||||||
if (!_charsLimitation) {
|
if (!_charsLimitation) {
|
||||||
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(
|
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(
|
||||||
|
@@ -3150,6 +3150,10 @@ not_null<Ui::RpWidget*> ComposeControls::likeAnimationTarget() const {
|
|||||||
return _like;
|
return _like;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ComposeControls::fieldCharacterCount() const {
|
||||||
|
return Ui::FieldCharacterCount(_field);
|
||||||
|
}
|
||||||
|
|
||||||
bool ComposeControls::preventsClose(Fn<void()> &&continueCallback) const {
|
bool ComposeControls::preventsClose(Fn<void()> &&continueCallback) const {
|
||||||
if (_voiceRecordBar->isActive()) {
|
if (_voiceRecordBar->isActive()) {
|
||||||
_voiceRecordBar->showDiscardBox(std::move(continueCallback));
|
_voiceRecordBar->showDiscardBox(std::move(continueCallback));
|
||||||
@@ -3323,9 +3327,8 @@ void ComposeControls::checkCharsLimitation() {
|
|||||||
_charsLimitation = nullptr;
|
_charsLimitation = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto limits = Data::PremiumLimits(&session());
|
const auto remove = Ui::FieldCharacterCount(_field)
|
||||||
const auto left = prepareTextForEditMsg();
|
- Data::PremiumLimits(&session()).captionLengthCurrent();
|
||||||
const auto remove = left.text.size() - limits.captionLengthCurrent();
|
|
||||||
if (remove > 0) {
|
if (remove > 0) {
|
||||||
if (!_charsLimitation) {
|
if (!_charsLimitation) {
|
||||||
using namespace Controls;
|
using namespace Controls;
|
||||||
|
@@ -228,6 +228,7 @@ public:
|
|||||||
[[nodiscard]] rpl::producer<bool> hasSendTextValue() const;
|
[[nodiscard]] rpl::producer<bool> hasSendTextValue() const;
|
||||||
[[nodiscard]] rpl::producer<bool> fieldMenuShownValue() const;
|
[[nodiscard]] rpl::producer<bool> fieldMenuShownValue() const;
|
||||||
[[nodiscard]] not_null<Ui::RpWidget*> likeAnimationTarget() const;
|
[[nodiscard]] not_null<Ui::RpWidget*> likeAnimationTarget() const;
|
||||||
|
[[nodiscard]] int fieldCharacterCount() const;
|
||||||
|
|
||||||
[[nodiscard]] TextWithEntities prepareTextForEditMsg() const;
|
[[nodiscard]] TextWithEntities prepareTextForEditMsg() const;
|
||||||
|
|
||||||
|
@@ -1170,29 +1170,29 @@ void RepliesWidget::edit(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto webpage = _composeControls->webPageDraft();
|
const auto webpage = _composeControls->webPageDraft();
|
||||||
auto sending = TextWithEntities();
|
const auto sending = _composeControls->prepareTextForEditMsg();
|
||||||
auto left = _composeControls->prepareTextForEditMsg();
|
|
||||||
|
|
||||||
const auto originalLeftSize = left.text.size();
|
|
||||||
const auto hasMediaWithCaption = item
|
const auto hasMediaWithCaption = item
|
||||||
&& item->media()
|
&& item->media()
|
||||||
&& item->media()->allowsEditCaption();
|
&& item->media()->allowsEditCaption();
|
||||||
const auto maxCaptionSize = !hasMediaWithCaption
|
if (sending.text.isEmpty() && !hasMediaWithCaption) {
|
||||||
? MaxMessageSize
|
|
||||||
: Data::PremiumLimits(&session()).captionLengthCurrent();
|
|
||||||
if (!TextUtilities::CutPart(sending, left, maxCaptionSize)
|
|
||||||
&& !hasMediaWithCaption) {
|
|
||||||
if (item) {
|
if (item) {
|
||||||
controller()->show(Box<DeleteMessagesBox>(item, false));
|
controller()->show(Box<DeleteMessagesBox>(item, false));
|
||||||
} else {
|
} else {
|
||||||
doSetInnerFocus();
|
doSetInnerFocus();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (!left.text.isEmpty()) {
|
} else {
|
||||||
const auto remove = originalLeftSize - maxCaptionSize;
|
const auto maxCaptionSize = !hasMediaWithCaption
|
||||||
controller()->showToast(
|
? MaxMessageSize
|
||||||
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
|
: Data::PremiumLimits(&session()).captionLengthCurrent();
|
||||||
return;
|
const auto remove = _composeControls->fieldCharacterCount()
|
||||||
|
- maxCaptionSize;
|
||||||
|
if (remove > 0) {
|
||||||
|
controller()->showToast(
|
||||||
|
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lifetime().add([=] {
|
lifetime().add([=] {
|
||||||
|
@@ -635,29 +635,29 @@ void ScheduledWidget::edit(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto webpage = _composeControls->webPageDraft();
|
const auto webpage = _composeControls->webPageDraft();
|
||||||
auto sending = TextWithEntities();
|
const auto sending = _composeControls->prepareTextForEditMsg();
|
||||||
auto left = _composeControls->prepareTextForEditMsg();
|
|
||||||
|
|
||||||
const auto originalLeftSize = left.text.size();
|
|
||||||
const auto hasMediaWithCaption = item
|
const auto hasMediaWithCaption = item
|
||||||
&& item->media()
|
&& item->media()
|
||||||
&& item->media()->allowsEditCaption();
|
&& item->media()->allowsEditCaption();
|
||||||
const auto maxCaptionSize = !hasMediaWithCaption
|
if (sending.text.isEmpty() && !hasMediaWithCaption) {
|
||||||
? MaxMessageSize
|
|
||||||
: Data::PremiumLimits(&session()).captionLengthCurrent();
|
|
||||||
if (!TextUtilities::CutPart(sending, left, maxCaptionSize)
|
|
||||||
&& !hasMediaWithCaption) {
|
|
||||||
if (item) {
|
if (item) {
|
||||||
controller()->show(Box<DeleteMessagesBox>(item, false));
|
controller()->show(Box<DeleteMessagesBox>(item, false));
|
||||||
} else {
|
} else {
|
||||||
_composeControls->focus();
|
_composeControls->focus();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (!left.text.isEmpty()) {
|
} else {
|
||||||
const auto remove = originalLeftSize - maxCaptionSize;
|
const auto maxCaptionSize = !hasMediaWithCaption
|
||||||
controller()->showToast(
|
? MaxMessageSize
|
||||||
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
|
: Data::PremiumLimits(&session()).captionLengthCurrent();
|
||||||
return;
|
const auto remove = _composeControls->fieldCharacterCount()
|
||||||
|
- maxCaptionSize;
|
||||||
|
if (remove > 0) {
|
||||||
|
controller()->showToast(
|
||||||
|
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lifetime().add([=] {
|
lifetime().add([=] {
|
||||||
|
Submodule Telegram/lib_ui updated: d424751135...333587d95e
Reference in New Issue
Block a user