mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Fixed edit of long media caption with emoji.
This commit is contained in:
parent
d252427e34
commit
a77c547a62
6 changed files with 49 additions and 45 deletions
|
@ -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>(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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([=] {
|
||||
|
|
|
@ -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([=] {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit d4247511355a666903e9a57d821b1eb58884aade
|
||||
Subproject commit 333587d95edefcae1ebaf8838d3f499639fc2de8
|
Loading…
Add table
Reference in a new issue