mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 13:47:05 +02:00
Improve editing messages with webpage previews.
This commit is contained in:
parent
c035ec6917
commit
3b91e2dee4
7 changed files with 54 additions and 21 deletions
|
@ -68,7 +68,7 @@ mtpRequestId EditMessage(
|
|||
|
||||
const auto emptyFlag = MTPmessages_EditMessage::Flag(0);
|
||||
const auto flags = emptyFlag
|
||||
| (!text.isEmpty() || media
|
||||
| ((!text.isEmpty() || media)
|
||||
? MTPmessages_EditMessage::Flag::f_message
|
||||
: emptyFlag)
|
||||
| ((media && inputMedia.has_value())
|
||||
|
@ -98,7 +98,7 @@ mtpRequestId EditMessage(
|
|||
item->history()->peer->input,
|
||||
MTP_int(id),
|
||||
MTP_string(text),
|
||||
inputMedia.value_or(Data::WebPageForMTP(webpage)),
|
||||
inputMedia.value_or(Data::WebPageForMTP(webpage, text.isEmpty())),
|
||||
MTPReplyMarkup(),
|
||||
sentEntities,
|
||||
MTP_int(options.scheduled)
|
||||
|
|
|
@ -2158,7 +2158,9 @@ void ApiWrap::saveDraftsToCloud() {
|
|||
history->peer->input,
|
||||
MTP_string(textWithTags.text),
|
||||
entities,
|
||||
Data::WebPageForMTP(cloudDraft->webpage)
|
||||
Data::WebPageForMTP(
|
||||
cloudDraft->webpage,
|
||||
textWithTags.text.isEmpty())
|
||||
)).done([=](const MTPBool &result, const MTP::Response &response) {
|
||||
const auto requestId = response.requestId;
|
||||
history->finishSavingCloudDraft(
|
||||
|
|
|
@ -1587,9 +1587,6 @@ void HistoryWidget::fieldChanged() {
|
|||
|
||||
updateSendButtonType();
|
||||
if (!HasSendText(_field)) {
|
||||
if (_preview) {
|
||||
_preview->apply({});
|
||||
}
|
||||
_fieldIsEmpty = true;
|
||||
} else if (_fieldIsEmpty) {
|
||||
_fieldIsEmpty = false;
|
||||
|
@ -1887,7 +1884,7 @@ bool HistoryWidget::applyDraft(FieldHistoryAction fieldHistoryAction) {
|
|||
_processingReplyTo = _replyTo = FullReplyTo();
|
||||
setEditMsgId(0);
|
||||
if (_preview) {
|
||||
_preview->apply({});
|
||||
_preview->apply({ .removed = true });
|
||||
}
|
||||
if (fieldWillBeHiddenAfterEdit) {
|
||||
updateControlsVisibility();
|
||||
|
@ -1923,7 +1920,17 @@ bool HistoryWidget::applyDraft(FieldHistoryAction fieldHistoryAction) {
|
|||
}
|
||||
|
||||
if (_preview) {
|
||||
_preview->apply(draft->webpage, !_editMsgId);
|
||||
_preview->setDisabled(_editMsgId
|
||||
&& _replyEditMsg
|
||||
&& _replyEditMsg->media()
|
||||
&& !_replyEditMsg->media()->webpage());
|
||||
if (!_editMsgId) {
|
||||
_preview->apply(draft->webpage, true);
|
||||
} else if (!_replyEditMsg
|
||||
|| !_replyEditMsg->media()
|
||||
|| _replyEditMsg->media()->webpage()) {
|
||||
_preview->apply(draft->webpage, false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -2503,6 +2510,9 @@ void HistoryWidget::setEditMsgId(MsgId msgId) {
|
|||
_editMsgId = msgId;
|
||||
if (!msgId) {
|
||||
_canReplaceMedia = false;
|
||||
if (_preview) {
|
||||
_preview->setDisabled(false);
|
||||
}
|
||||
}
|
||||
if (_history) {
|
||||
refreshSendAsToggle();
|
||||
|
@ -3775,6 +3785,7 @@ void HistoryWidget::saveEditMsg() {
|
|||
cancelEdit();
|
||||
return;
|
||||
}
|
||||
const auto webPageDraft = _preview->draft();
|
||||
const auto textWithTags = _field->getTextWithAppliedMarkdown();
|
||||
const auto prepareFlags = Ui::ItemTextOptions(
|
||||
_history,
|
||||
|
@ -3785,8 +3796,12 @@ void HistoryWidget::saveEditMsg() {
|
|||
TextUtilities::ConvertTextTagsToEntities(textWithTags.tags) };
|
||||
TextUtilities::PrepareForSending(left, prepareFlags);
|
||||
|
||||
const auto media = item->media();
|
||||
if (!TextUtilities::CutPart(sending, left, MaxMessageSize)
|
||||
&& (!item->media() || !item->media()->allowsEditCaption())) {
|
||||
&& (webPageDraft.removed
|
||||
|| webPageDraft.url.isEmpty()
|
||||
|| !webPageDraft.manual)
|
||||
&& (!media || !media->allowsEditCaption())) {
|
||||
const auto suggestModerateActions = false;
|
||||
controller()->show(
|
||||
Box<DeleteMessagesBox>(item, suggestModerateActions));
|
||||
|
@ -3844,7 +3859,7 @@ void HistoryWidget::saveEditMsg() {
|
|||
_saveEditMsgRequestId = Api::EditTextMessage(
|
||||
item,
|
||||
sending,
|
||||
_preview->draft(),
|
||||
webPageDraft,
|
||||
options,
|
||||
done,
|
||||
fail);
|
||||
|
@ -6267,9 +6282,7 @@ void HistoryWidget::editDraftOptions() {
|
|||
} else {
|
||||
cancelReply();
|
||||
}
|
||||
if (_preview->draft() != webpage) {
|
||||
_preview->apply(webpage);
|
||||
}
|
||||
_preview->apply(webpage);
|
||||
};
|
||||
const auto highlight = [=] {
|
||||
controller()->showPeerHistory(
|
||||
|
@ -7693,6 +7706,12 @@ void HistoryWidget::messageDataReceived(
|
|||
} else if (_editMsgId == msgId
|
||||
|| (_replyTo.messageId == FullMsgId(peer->id, msgId))) {
|
||||
updateReplyEditTexts(true);
|
||||
if (_editMsgId == msgId) {
|
||||
_preview->setDisabled(_editMsgId
|
||||
&& _replyEditMsg
|
||||
&& _replyEditMsg->media()
|
||||
&& !_replyEditMsg->media()->webpage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1758,9 +1758,6 @@ void ComposeControls::fieldChanged() {
|
|||
&& (_textUpdateEvents & TextUpdateEvent::SendTyping));
|
||||
updateSendButtonType();
|
||||
_hasSendText = HasSendText(_field);
|
||||
if (!_hasSendText.current() && _preview && !_preview->draft().manual) {
|
||||
_preview->apply({ .removed = true });
|
||||
}
|
||||
if (updateBotCommandShown() || updateLikeShown()) {
|
||||
updateControlsVisibility();
|
||||
updateControlsGeometry(_wrap->size());
|
||||
|
@ -1930,7 +1927,7 @@ void ComposeControls::applyDraft(FieldHistoryAction fieldHistoryAction) {
|
|||
_header->editMessage({});
|
||||
_header->replyToMessage({});
|
||||
if (_preview) {
|
||||
_preview->apply({});
|
||||
_preview->apply({ .removed = true });
|
||||
}
|
||||
_canReplaceMedia = false;
|
||||
_photoEditMedia = nullptr;
|
||||
|
|
|
@ -252,6 +252,7 @@ rpl::producer<QString> PreviewWrap::showLinkSelector(
|
|||
_history->nextNonHistoryEntryId(),
|
||||
(MessageFlag::FakeHistoryItem
|
||||
| MessageFlag::Outgoing
|
||||
| MessageFlag::HasFromId
|
||||
| (webpage.invert ? MessageFlag::InvertMedia : MessageFlag())),
|
||||
UserId(), // via
|
||||
FullReplyTo(),
|
||||
|
|
|
@ -163,13 +163,15 @@ void WebpageProcessor::apply(Data::WebPageDraft draft, bool reparse) {
|
|||
_link = QString();
|
||||
_parsed = WebpageParsed();
|
||||
updateFromData();
|
||||
} else if (draft.manual && draft.id && !draft.url.isEmpty()) {
|
||||
} else if (draft.manual && !draft.url.isEmpty()) {
|
||||
_draft = draft;
|
||||
_parsedLinks = QStringList();
|
||||
_links = QStringList();
|
||||
_link = _draft.url;
|
||||
const auto page = _history->owner().webpage(draft.id);
|
||||
if (page->url == draft.url) {
|
||||
const auto page = draft.id
|
||||
? _history->owner().webpage(draft.id).get()
|
||||
: nullptr;
|
||||
if (page && page->url == draft.url) {
|
||||
_data = page;
|
||||
updateFromData();
|
||||
} else {
|
||||
|
@ -220,7 +222,9 @@ void WebpageProcessor::request() {
|
|||
page->failed = true;
|
||||
}
|
||||
_cache.emplace(link, page->failed ? nullptr : page.get());
|
||||
if (_link == link && !_draft.removed && !_draft.manual) {
|
||||
if (_link == link
|
||||
&& !_draft.removed
|
||||
&& (!_draft.manual || _draft.url == link)) {
|
||||
_data = (page->id && !page->failed)
|
||||
? page.get()
|
||||
: nullptr;
|
||||
|
@ -258,6 +262,15 @@ void WebpageProcessor::request() {
|
|||
}).send();
|
||||
}
|
||||
|
||||
void WebpageProcessor::setDisabled(bool disabled) {
|
||||
_parser.setDisabled(disabled);
|
||||
if (disabled) {
|
||||
apply({ .removed = true });
|
||||
} else {
|
||||
checkNow(false);
|
||||
}
|
||||
}
|
||||
|
||||
void WebpageProcessor::checkNow(bool force) {
|
||||
_parser.parseNow();
|
||||
if (force) {
|
||||
|
|
|
@ -53,6 +53,7 @@ public:
|
|||
not_null<History*> history,
|
||||
not_null<Ui::InputField*> field);
|
||||
|
||||
void setDisabled(bool disabled);
|
||||
void checkNow(bool force);
|
||||
|
||||
// If editing a message without a preview we don't want to show
|
||||
|
|
Loading…
Add table
Reference in a new issue