2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Support markdown and replaces in media captions.

This commit is contained in:
John Preston
2018-05-24 16:03:21 +03:00
parent 6f6ec217e3
commit 5e7642b42a
22 changed files with 133 additions and 63 deletions

View File

@@ -329,6 +329,9 @@ void GroupInfoBox::prepare() {
langFactory(lng_create_group_description));
_description->show();
_description->setMaxLength(kMaxChannelDescription);
_description->setInstantReplaces(Ui::InstantReplaces::Default());
_description->setInstantReplacesEnabled(
Global::ReplaceEmojiValue());
connect(_description, SIGNAL(resized()), this, SLOT(onDescriptionResized()));
connect(_description, SIGNAL(submitted(bool)), this, SLOT(onNext()));
@@ -1080,6 +1083,7 @@ void EditBioBox::prepare() {
connect(_bio, &Ui::InputField::resized, this, [this] { updateMaxHeight(); });
connect(_bio, &Ui::InputField::changed, this, [this] { handleBioUpdated(); });
_bio->setInstantReplaces(Ui::InstantReplaces::Default());
_bio->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
handleBioUpdated();
updateMaxHeight();
}
@@ -1161,6 +1165,8 @@ void EditChannelBox::prepare() {
_title->setMaxLength(kMaxGroupChannelTitle);
_description->setMaxLength(kMaxChannelDescription);
_description->setInstantReplaces(Ui::InstantReplaces::Default());
_description->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
connect(_description, SIGNAL(resized()), this, SLOT(onDescriptionResized()));
connect(_description, SIGNAL(submitted(bool)), this, SLOT(onSave()));

View File

@@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_photo.h"
#include "data/data_document.h"
#include "lang/lang_keys.h"
#include "chat_helpers/message_field.h"
#include "window/window_controller.h"
#include "mainwidget.h"
#include "layout.h"
@@ -50,7 +51,11 @@ EditCaptionBox::EditCaptionBox(
}
doc = document;
}
auto caption = item->originalText().text;
const auto original = item->originalText();
const auto editData = TextWithTags {
original.text,
ConvertEntitiesToTextTags(original.entities)
};
if (!_animated && (dimensions.isEmpty() || doc || image->isNull())) {
if (image->isNull()) {
@@ -135,10 +140,12 @@ EditCaptionBox::EditCaptionBox(
st::confirmCaptionArea,
Ui::InputField::Mode::MultiLine,
langFactory(lng_photo_caption),
caption);
editData);
_field->setMaxLength(MaxPhotoCaption);
_field->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
_field->setInstantReplaces(Ui::InstantReplaces::Default());
_field->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
_field->setMarkdownReplacesEnabled(Global::ReplaceEmojiValue());
}
void EditCaptionBox::prepareGifPreview(DocumentData *document) {
@@ -338,17 +345,29 @@ void EditCaptionBox::save() {
if (_previewCancelled) {
flags |= MTPmessages_EditMessage::Flag::f_no_webpage;
}
MTPVector<MTPMessageEntity> sentEntities;
const auto textWithTags = _field->getTextWithTags();
auto sending = TextWithEntities{
textWithTags.text,
ConvertTextTagsToEntities(textWithTags.tags)
};
const auto prepareFlags = Ui::ItemTextOptions(
item->history(),
App::self()).flags;
TextUtilities::PrepareForSending(sending, prepareFlags);
TextUtilities::Trim(sending);
const auto sentEntities = TextUtilities::EntitiesToMTP(
sending.entities,
TextUtilities::ConvertOption::SkipLocal);
if (!sentEntities.v.isEmpty()) {
flags |= MTPmessages_EditMessage::Flag::f_entities;
}
auto text = TextUtilities::PrepareForSending(_field->getLastText(), TextUtilities::PrepareTextOption::CheckLinks);
_saveRequestId = MTP::send(
MTPmessages_EditMessage(
MTP_flags(flags),
item->history()->peer->input,
MTP_int(item->id),
MTP_string(text),
MTP_string(sending.text),
MTPnullMarkup,
sentEntities,
MTP_inputGeoPointEmpty()),

View File

@@ -328,6 +328,8 @@ object_ptr<Ui::RpWidget> Controller::createDescriptionEdit() {
st::editPeerDescriptionMargins);
result->entity()->setMaxLength(kMaxChannelDescription);
result->entity()->setInstantReplaces(Ui::InstantReplaces::Default());
result->entity()->setInstantReplacesEnabled(
Global::ReplaceEmojiValue());
QObject::connect(
result->entity(),

View File

@@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/storage_media_prepare.h"
#include "mainwidget.h"
#include "history/history_media_types.h"
#include "chat_helpers/message_field.h"
#include "core/file_utilities.h"
#include "ui/widgets/checkbox.h"
#include "ui/widgets/buttons.h"
@@ -1578,6 +1579,8 @@ void SendFilesBox::setupCaption() {
Unexpected("action in MimeData hook.");
});
_caption->setInstantReplaces(Ui::InstantReplaces::Default());
_caption->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
_caption->setMarkdownReplacesEnabled(Global::ReplaceEmojiValue());
}
void SendFilesBox::captionResized() {
@@ -1789,10 +1792,8 @@ void SendFilesBox::send(bool ctrlShiftEnter) {
_confirmed = true;
if (_confirmedCallback) {
auto caption = _caption
? TextUtilities::PrepareForSending(
_caption->getLastText(),
TextUtilities::PrepareTextOption::CheckLinks)
: QString();
? _caption->getTextWithTags()
: TextWithTags();
_confirmedCallback(
std::move(_list),
way,

View File

@@ -39,7 +39,7 @@ public:
base::lambda<void(
Storage::PreparedList &&list,
SendFilesWay way,
const QString &caption,
TextWithTags &&caption,
bool ctrlShiftEnter)> callback) {
_confirmedCallback = std::move(callback);
}
@@ -98,7 +98,7 @@ private:
base::lambda<void(
Storage::PreparedList &&list,
SendFilesWay way,
const QString &caption,
TextWithTags &&caption,
bool ctrlShiftEnter)> _confirmedCallback;
base::lambda<void()> _cancelledCallback;
bool _confirmed = false;