mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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();
|
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([=] {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit d4247511355a666903e9a57d821b1eb58884aade
|
Subproject commit 333587d95edefcae1ebaf8838d3f499639fc2de8
|
Loading…
Add table
Reference in a new issue