tdesktop/Telegram/SourceFiles/boxes/edit_caption_box.cpp

708 lines
20 KiB
C++
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "boxes/edit_caption_box.h"
2019-03-26 21:14:51 +00:00
#include "apiwrap.h"
#include "auth_session.h"
#include "chat_helpers/emoji_suggestions_widget.h"
#include "chat_helpers/message_field.h"
#include "chat_helpers/tabbed_panel.h"
#include "chat_helpers/tabbed_selector.h"
#include "core/event_filter.h"
#include "core/file_utilities.h"
#include "core/mime_type.h"
#include "data/data_document.h"
#include "data/data_media_types.h"
#include "data/data_photo.h"
#include "data/data_user.h"
2019-03-26 21:14:51 +00:00
#include "history/history.h"
#include "history/history_item.h"
#include "lang/lang_keys.h"
#include "layout.h"
2019-03-26 21:14:51 +00:00
#include "mainwidget.h"
#include "media/clip/media_clip_reader.h"
#include "storage/storage_media_prepare.h"
#include "styles/style_boxes.h"
#include "styles/style_chat_helpers.h"
2019-03-26 21:14:51 +00:00
#include "styles/style_history.h"
#include "ui/image/image.h"
#include "ui/special_buttons.h"
#include "ui/text_options.h"
#include "ui/widgets/input_fields.h"
#include "window/window_controller.h"
#include "ui/widgets/checkbox.h"
2019-03-24 12:39:19 +00:00
EditCaptionBox::EditCaptionBox(
QWidget*,
not_null<Window::Controller*> controller,
2018-01-18 13:59:22 +00:00
not_null<HistoryItem*> item)
: _controller(controller)
, _msgId(item->fullId()) {
2018-01-18 13:59:22 +00:00
Expects(item->media() != nullptr);
Expects(item->media()->allowsEditCaption());
QSize dimensions;
auto image = (Image*)nullptr;
DocumentData *doc = nullptr;
2018-01-18 13:59:22 +00:00
const auto media = item->media();
if (const auto photo = media->photo()) {
_photo = true;
dimensions = QSize(photo->width(), photo->height());
image = photo->large();
} else if (const auto document = media->document()) {
image = document->thumbnail();
dimensions = image
? image->size()
: document->dimensions;
if (document->isAnimation()) {
_gifw = document->dimensions.width();
_gifh = document->dimensions.height();
_animated = true;
} else if (document->isVideoFile()) {
_animated = true;
} else {
_doc = true;
}
doc = document;
}
const auto original = item->originalText();
const auto editData = TextWithTags {
original.text,
ConvertEntitiesToTextTags(original.entities)
};
if (!_animated && (dimensions.isEmpty() || doc || !image)) {
if (!image) {
_thumbw = 0;
} else {
2019-03-21 12:28:42 +00:00
const auto tw = image->width(), th = image->height();
if (tw > th) {
_thumbw = (tw * st::msgFileThumbSize) / th;
} else {
_thumbw = st::msgFileThumbSize;
}
_thumbnailImage = image;
_refreshThumbnail = [=] {
2019-03-21 12:28:42 +00:00
const auto options = Images::Option::Smooth
| Images::Option::RoundedSmall
| Images::Option::RoundedTopLeft
| Images::Option::RoundedTopRight
| Images::Option::RoundedBottomLeft
| Images::Option::RoundedBottomRight;
_thumb = App::pixmapFromImageInPlace(Images::prepare(
2018-07-13 21:25:47 +00:00
image->pix(_msgId).toImage(),
_thumbw * cIntRetinaFactor(),
0,
options,
st::msgFileThumbSize,
st::msgFileThumbSize));
};
}
if (doc) {
2019-03-21 12:28:42 +00:00
const auto nameString = doc->isVoiceMessage()
? lang(lng_media_audio)
: doc->composeNameString();
2019-03-26 21:14:51 +00:00
setName(nameString, doc->size);
_isImage = doc->isImage();
_isAudio = (doc->isVoiceMessage() || doc->isAudioFile());
}
if (_refreshThumbnail) {
_refreshThumbnail();
}
} else {
2019-02-17 08:31:04 +00:00
if (!image) {
image = Image::BlankMedia();
}
2019-03-21 12:28:42 +00:00
auto maxW = 0, maxH = 0;
const auto limitW = st::sendMediaPreviewSize;
auto limitH = std::min(st::confirmMaxHeight, _gifh ? _gifh : INT_MAX);
if (_animated) {
2019-03-21 12:28:42 +00:00
maxW = std::max(dimensions.width(), 1);
maxH = std::max(dimensions.height(), 1);
if (maxW * limitH > maxH * limitW) {
if (maxW < limitW) {
maxH = maxH * limitW / maxW;
maxW = limitW;
}
} else {
if (maxH < limitH) {
maxW = maxW * limitH / maxH;
maxH = limitH;
}
}
_thumbnailImage = image;
_refreshThumbnail = [=] {
const auto options = Images::Option::Smooth
| Images::Option::Blurred;
_thumb = image->pixNoCache(
2018-07-13 21:25:47 +00:00
_msgId,
maxW * cIntRetinaFactor(),
maxH * cIntRetinaFactor(),
options,
maxW,
maxH);
};
prepareGifPreview(doc);
} else {
maxW = dimensions.width();
maxH = dimensions.height();
_thumbnailImage = image;
_refreshThumbnail = [=] {
_thumb = image->pixNoCache(
2018-07-13 21:25:47 +00:00
_msgId,
maxW * cIntRetinaFactor(),
maxH * cIntRetinaFactor(),
Images::Option::Smooth,
maxW,
maxH);
};
}
_refreshThumbnail();
const auto resizeDimensions = [&](int &thumbWidth, int &thumbHeight, int &thumbX) {
2019-03-21 12:28:42 +00:00
auto tw = thumbWidth, th = thumbHeight;
if (!tw || !th) {
tw = th = 1;
}
if (thumbWidth < st::sendMediaPreviewSize) {
thumbWidth = (thumbWidth > 20) ? thumbWidth : 20;
} else {
thumbWidth = st::sendMediaPreviewSize;
}
2019-03-21 12:28:42 +00:00
const auto maxThumbHeight = std::min(int(std::round(1.5 * thumbWidth)), limitH);
thumbHeight = int(std::round(th * float64(thumbWidth) / tw));
if (thumbHeight > maxThumbHeight) {
2019-03-21 12:28:42 +00:00
thumbWidth = int(std::round(thumbWidth * float64(maxThumbHeight) / thumbHeight));
thumbHeight = maxThumbHeight;
if (thumbWidth < 10) {
thumbWidth = 10;
}
}
thumbX = (st::boxWideWidth - thumbWidth) / 2;
};
if (doc && doc->isAnimation()) {
resizeDimensions(_gifw, _gifh, _gifx);
}
limitH = std::min(st::confirmMaxHeight, _gifh ? _gifh : INT_MAX);
_thumbw = _thumb.width();
_thumbh = _thumb.height();
// If thumb's and resized gif's sizes are equal,
// Then just take made values.
if (_thumbw == _gifw && _thumbh == _gifh) {
_thumbx = (st::boxWideWidth - _thumbw) / 2;
} else {
resizeDimensions(_thumbw, _thumbh, _thumbx);
}
const auto prepareBasicThumb = _refreshThumbnail;
const auto scaleThumbDown = [=] {
_thumb = App::pixmapFromImageInPlace(_thumb.toImage().scaled(
_thumbw * cIntRetinaFactor(),
_thumbh * cIntRetinaFactor(),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation));
_thumb.setDevicePixelRatio(cRetinaFactor());
};
_refreshThumbnail = [=] {
prepareBasicThumb();
scaleThumbDown();
};
scaleThumbDown();
}
Assert(_animated || _photo || _doc);
_thumbnailImageLoaded = _thumbnailImage
? _thumbnailImage->loaded()
: true;
subscribe(Auth().downloaderTaskFinished(), [=] {
2019-02-17 08:31:04 +00:00
if (!_thumbnailImageLoaded
&& _thumbnailImage
&& _thumbnailImage->loaded()) {
_thumbnailImageLoaded = true;
_refreshThumbnail();
update();
}
if (doc && doc->isAnimation() && doc->loaded() && !_gifPreview) {
prepareGifPreview(doc);
}
});
_field.create(
this,
st::confirmCaptionArea,
Ui::InputField::Mode::MultiLine,
langFactory(lng_photo_caption),
editData);
_field->setMaxLength(Global::CaptionLengthMax());
2018-05-21 21:31:46 +00:00
_field->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
_field->setInstantReplaces(Ui::InstantReplaces::Default());
_field->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
_field->setMarkdownReplacesEnabled(rpl::single(true));
2018-11-04 07:32:26 +00:00
_field->setEditLinkCallback(DefaultEditLinkCallback(_field));
auto r = object_ptr<Ui::SlideWrap<Ui::Checkbox>>(
this,
object_ptr<Ui::Checkbox>(
this,
lang(lng_send_file),
false,
st::defaultBoxCheckbox),
st::editMediaCheckboxMargins);
_wayWrap = r.data();
_wayWrap->toggle(false, anim::type::instant);
r->entity()->checkedChanges(
) | rpl::start_with_next([&](bool checked) {
_asFile = checked;
}, _wayWrap->lifetime());
}
bool EditCaptionBox::emojiFilter(not_null<QEvent*> event) {
const auto type = event->type();
if (type == QEvent::Move || type == QEvent::Resize) {
// updateEmojiPanelGeometry uses not only container geometry, but
// also container children geometries that will be updated later.
crl::on_main(this, [=] { updateEmojiPanelGeometry(); });
}
return false;
}
void EditCaptionBox::updateEmojiPanelGeometry() {
const auto parent = _emojiPanel->parentWidget();
const auto global = _emojiToggle->mapToGlobal({ 0, 0 });
const auto local = parent->mapFromGlobal(global);
_emojiPanel->moveBottomRight(
local.y(),
local.x() + _emojiToggle->width() * 3);
}
void EditCaptionBox::prepareGifPreview(DocumentData* document) {
if (_gifPreview) {
return;
} else if (!document && _newMediaPath.isEmpty()) {
return;
}
const auto callback = [=](Media::Clip::Notification notification) {
clipCallback(notification);
};
if (document && document->isAnimation() && document->loaded()) {
_gifPreview = Media::Clip::MakeReader(
document,
_msgId,
callback);
} else if (!_newMediaPath.isEmpty()) {
_gifPreview = Media::Clip::MakeReader(
_newMediaPath,
callback);
}
if (_gifPreview) _gifPreview->setAutoplay();
}
void EditCaptionBox::clipCallback(Media::Clip::Notification notification) {
using namespace Media::Clip;
switch (notification) {
case NotificationReinit: {
if (_gifPreview && _gifPreview->state() == State::Error) {
_gifPreview.setBad();
}
if (_gifPreview && _gifPreview->ready() && !_gifPreview->started()) {
2019-03-21 12:28:42 +00:00
const auto s = QSize(_gifw, _gifh);
_gifPreview->start(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, RectPart::None);
}
update();
} break;
case NotificationRepaint: {
if (_gifPreview && !_gifPreview->currentDisplayed()) {
update();
}
} break;
}
}
void EditCaptionBox::prepare() {
addButton(langFactory(lng_settings_save), [this] { save(); });
2019-03-24 12:39:19 +00:00
addButton(langFactory(lng_edit_media), [this] {
const auto callback = [=](const FileDialog::OpenResult &result) {
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
return;
}
if (!result.paths.isEmpty()) {
const auto filePath = result.paths.front();
LOG(("FILE PATH: %1").arg(filePath));
_newMediaPath = filePath;
2019-03-26 21:14:51 +00:00
_preparedList = Storage::PrepareMediaList(
QStringList(_newMediaPath),
st::sendMediaPreviewSize);
2019-03-26 21:14:51 +00:00
const auto file = &_preparedList.files.front();
const auto fileMedia = &file->information->media;
const auto fileinfo = QFileInfo(_newMediaPath);
const auto filename = fileinfo.fileName();
_isImage = fileIsImage(filename, Core::MimeTypeForFile(fileinfo).name());
_isAudio = false;
_animated = false;
_photo = false;
_doc = false;
_gifPreview = nullptr;
_thumbw = _thumbh = _thumbx = 0;
_gifw = _gifh = _gifx = 0;
auto isGif = false;
_wayWrap->toggle(_isImage, anim::type::instant);
2019-03-26 21:14:51 +00:00
using Info = FileMediaInformation;
if (const auto image = base::get_if<Info::Image>(fileMedia)
&& _isImage) {
_photo = true;
2019-03-26 21:14:51 +00:00
} else if (const auto video =
base::get_if<Info::Video>(fileMedia)) {
_animated = true;
isGif = video->isGifv;
} else {
2019-03-26 21:14:51 +00:00
auto nameString = filename;
if (const auto song =
base::get_if<Info::Song>(fileMedia)) {
nameString = DocumentData::ComposeNameString(
filename,
song->title,
song->performer);
_isAudio = true;
}
setName(nameString, fileinfo.size());
_doc = true;
}
if (!_doc) {
_thumb = App::pixmapFromImageInPlace(
file->preview.scaled(st::sendMediaPreviewSize,
st::confirmMaxHeight,
Qt::KeepAspectRatio));
_thumbw = _thumb.width();
_thumbh = _thumb.height();
_thumbx = (st::boxWideWidth - _thumbw) / 2;
if (isGif) {
_gifw = _thumbw;
_gifh = _thumbh;
_gifx = _thumbx;
prepareGifPreview();
}
}
captionResized();
2019-03-24 12:39:19 +00:00
}
};
2019-03-26 21:14:51 +00:00
const auto filters = QStringList(FileDialog::AllFilesFilter());
2019-03-24 12:39:19 +00:00
FileDialog::GetOpenPath(
this,
2019-03-26 21:14:51 +00:00
lang(lng_choose_file),
2019-03-24 12:39:19 +00:00
filters.join(qsl(";;")),
crl::guard(this, callback));
});
addButton(langFactory(lng_cancel), [this] { closeBox(); });
updateBoxSize();
connect(_field, &Ui::InputField::submitted, [=] { save(); });
connect(_field, &Ui::InputField::cancelled, [=] { closeBox(); });
connect(_field, &Ui::InputField::resized, [=] { captionResized(); });
2018-11-21 10:09:46 +00:00
Ui::Emoji::SuggestionsController::Init(
getDelegate()->outerContainer(),
_field);
setupEmojiPanel();
auto cursor = _field->textCursor();
cursor.movePosition(QTextCursor::End);
_field->setTextCursor(cursor);
}
void EditCaptionBox::captionResized() {
updateBoxSize();
resizeEvent(0);
updateEmojiPanelGeometry();
update();
}
void EditCaptionBox::setupEmojiPanel() {
const auto container = getDelegate()->outerContainer();
_emojiPanel = base::make_unique_q<ChatHelpers::TabbedPanel>(
container,
_controller,
object_ptr<ChatHelpers::TabbedSelector>(
nullptr,
_controller,
ChatHelpers::TabbedSelector::Mode::EmojiOnly));
_emojiPanel->setDesiredHeightValues(
1.,
st::emojiPanMinHeight / 2,
st::emojiPanMinHeight);
_emojiPanel->hide();
_emojiPanel->getSelector()->emojiChosen(
) | rpl::start_with_next([=](EmojiPtr emoji) {
Ui::InsertEmojiAtCursor(_field->textCursor(), emoji);
}, lifetime());
_emojiFilter.reset(Core::InstallEventFilter(
container,
[=](not_null<QEvent*> event) { return emojiFilter(event); }));
_emojiToggle.create(this, st::boxAttachEmoji);
_emojiToggle->installEventFilter(_emojiPanel);
_emojiToggle->addClickHandler([=] {
_emojiPanel->toggleAnimated();
});
}
void EditCaptionBox::updateBoxSize() {
auto newHeight = st::boxPhotoPadding.top() + st::boxPhotoCaptionSkip + _field->height() + errorTopSkip() + st::normalFont->height;
if (_isImage) {
newHeight += _wayWrap->height() / 2;
}
if (_photo || _animated) {
newHeight += std::max(_thumbh, _gifh);
} else if (_thumbw) {
newHeight += 0 + st::msgFileThumbSize + 0;
} else if (_doc) {
newHeight += 0 + st::msgFileSize + 0;
} else {
newHeight += st::boxTitleFont->height;
}
setDimensions(st::boxWideWidth, newHeight);
}
int EditCaptionBox::errorTopSkip() const {
return (st::boxButtonPadding.top() / 2);
}
void EditCaptionBox::paintEvent(QPaintEvent *e) {
BoxContent::paintEvent(e);
Painter p(this);
if (_photo || _animated) {
const auto th = std::max(_gifh, _thumbh);
if (_thumbx > st::boxPhotoPadding.left()) {
p.fillRect(st::boxPhotoPadding.left(), st::boxPhotoPadding.top(), _thumbx - st::boxPhotoPadding.left(), th, st::confirmBg);
}
if (_thumbx + _thumbw < width() - st::boxPhotoPadding.right()) {
p.fillRect(_thumbx + _thumbw, st::boxPhotoPadding.top(), width() - st::boxPhotoPadding.right() - _thumbx - _thumbw, th, st::confirmBg);
}
if (_gifPreview && _gifPreview->started()) {
2019-03-21 12:28:42 +00:00
const auto s = QSize(_gifw, _gifh);
const auto paused = _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Layer);
const auto frame = _gifPreview->current(s.width(), s.height(), s.width(), s.height(), ImageRoundRadius::None, RectPart::None, paused ? 0 : crl::now());
p.drawPixmap(_gifx, st::boxPhotoPadding.top(), frame);
} else {
const auto offset = _gifh ? ((_gifh - _thumbh) / 2) : 0;
p.drawPixmap(_thumbx, st::boxPhotoPadding.top() + offset, _thumb);
}
if (_animated && !_gifPreview) {
QRect inner(_thumbx + (_thumbw - st::msgFileSize) / 2, st::boxPhotoPadding.top() + (th - st::msgFileSize) / 2, st::msgFileSize, st::msgFileSize);
p.setPen(Qt::NoPen);
p.setBrush(st::msgDateImgBg);
{
PainterHighQualityEnabler hq(p);
p.drawEllipse(inner);
}
2019-03-21 12:28:42 +00:00
const auto icon = &st::historyFileInPlay;
icon->paintInCenter(p, inner);
}
} else if (_doc) {
2019-03-21 12:28:42 +00:00
const auto w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
const auto h = _thumbw ? (0 + st::msgFileThumbSize + 0) : (0 + st::msgFileSize + 0);
auto nameleft = 0, nametop = 0, nameright = 0, statustop = 0;
if (_thumbw) {
nameleft = 0 + st::msgFileThumbSize + st::msgFileThumbPadding.right();
nametop = st::msgFileThumbNameTop - st::msgFileThumbPadding.top();
nameright = 0;
statustop = st::msgFileThumbStatusTop - st::msgFileThumbPadding.top();
} else {
nameleft = 0 + st::msgFileSize + st::msgFilePadding.right();
nametop = st::msgFileNameTop - st::msgFilePadding.top();
nameright = 0;
statustop = st::msgFileStatusTop - st::msgFilePadding.top();
}
2019-03-21 12:28:42 +00:00
const auto namewidth = w - nameleft - 0;
if (namewidth > _statusw) {
//w -= (namewidth - _statusw);
//namewidth = _statusw;
}
2019-03-21 12:28:42 +00:00
const auto x = (width() - w) / 2, y = st::boxPhotoPadding.top();
// App::roundRect(p, x, y, w, h, st::msgInBg, MessageInCorners, &st::msgInShadow);
if (_thumbw) {
QRect rthumb(rtlrect(x + 0, y + 0, st::msgFileThumbSize, st::msgFileThumbSize, width()));
p.drawPixmap(rthumb.topLeft(), _thumb);
} else {
2019-03-21 12:28:42 +00:00
const QRect inner(rtlrect(x + 0, y + 0, st::msgFileSize, st::msgFileSize, width()));
p.setPen(Qt::NoPen);
p.setBrush(st::msgFileInBg);
{
PainterHighQualityEnabler hq(p);
p.drawEllipse(inner);
}
2019-03-21 12:28:42 +00:00
const auto icon = &(_isAudio ? st::historyFileInPlay : _isImage ? st::historyFileInImage : st::historyFileInDocument);
icon->paintInCenter(p, inner);
}
p.setFont(st::semiboldFont);
p.setPen(st::historyFileNameInFg);
_name.drawLeftElided(p, x + nameleft, y + nametop, namewidth, width());
2019-03-21 12:28:42 +00:00
const auto &status = st::mediaInFg;
p.setFont(st::normalFont);
p.setPen(status);
p.drawTextLeft(x + nameleft, y + statustop, width(), _status);
} else {
p.setFont(st::boxTitleFont);
p.setPen(st::boxTextFg);
p.drawTextLeft(_field->x(), st::boxPhotoPadding.top(), width(), lang(lng_edit_message));
}
if (!_error.isEmpty()) {
p.setFont(st::normalFont);
p.setPen(st::boxTextFgError);
p.drawTextLeft(_field->x(), _field->y() + _field->height() + errorTopSkip(), width(), _error);
}
}
void EditCaptionBox::resizeEvent(QResizeEvent *e) {
BoxContent::resizeEvent(e);
if (_isImage) {
_wayWrap->resize(st::sendMediaPreviewSize, _wayWrap->height());
_wayWrap->moveToLeft(
st::boxPhotoPadding.left(),
st::boxPhotoPadding.top() + _thumbh);
}
_field->resize(st::sendMediaPreviewSize, _field->height());
_field->moveToLeft(st::boxPhotoPadding.left(), height() - st::normalFont->height - errorTopSkip() - _field->height());
_emojiToggle->moveToLeft(
(st::boxPhotoPadding.left()
+ st::sendMediaPreviewSize
- _emojiToggle->width()),
_field->y() + st::boxAttachEmojiTop);
}
void EditCaptionBox::setInnerFocus() {
_field->setFocusFast();
}
void EditCaptionBox::save() {
if (_saveRequestId) return;
2019-03-21 12:28:42 +00:00
const auto item = App::histItemById(_msgId);
if (!item) {
_error = lang(lng_edit_deleted);
update();
return;
}
auto flags = MTPmessages_EditMessage::Flag::f_message | 0;
if (_previewCancelled) {
flags |= MTPmessages_EditMessage::Flag::f_no_webpage;
}
const auto textWithTags = _field->getTextWithAppliedMarkdown();
auto sending = TextWithEntities{
textWithTags.text,
ConvertTextTagsToEntities(textWithTags.tags)
};
const auto prepareFlags = Ui::ItemTextOptions(
item->history(),
Auth().user()).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;
}
2019-03-24 12:39:19 +00:00
if (!_newMediaPath.isEmpty()) {
App::main()->setEditMedia(item->fullId());
const auto textWithTags = _field->getTextWithAppliedMarkdown();
auto sending = TextWithEntities{
textWithTags.text,
ConvertTextTagsToEntities(textWithTags.tags)
};
item->setText(sending);
Auth().api().editMedia(
2019-03-26 21:14:51 +00:00
std::move(_preparedList),
(!_asFile && _isImage) ? SendMediaType::Photo : SendMediaType::File,
2019-03-24 12:39:19 +00:00
_field->getTextWithAppliedMarkdown(),
ApiWrap::SendOptions(item->history()));
closeBox();
return;
}
_saveRequestId = MTP::send(
MTPmessages_EditMessage(
MTP_flags(flags),
item->history()->peer->input,
MTP_int(item->id),
MTP_string(sending.text),
MTPInputMedia(),
MTPReplyMarkup(),
2018-12-17 07:43:47 +00:00
sentEntities),
rpcDone(&EditCaptionBox::saveDone),
rpcFail(&EditCaptionBox::saveFail));
}
void EditCaptionBox::saveDone(const MTPUpdates &updates) {
_saveRequestId = 0;
closeBox();
Auth().api().applyUpdates(updates);
}
bool EditCaptionBox::saveFail(const RPCError &error) {
if (MTP::isDefaultHandledError(error)) return false;
_saveRequestId = 0;
QString err = error.type();
if (err == qstr("MESSAGE_ID_INVALID") || err == qstr("CHAT_ADMIN_REQUIRED") || err == qstr("MESSAGE_EDIT_TIME_EXPIRED")) {
_error = lang(lng_edit_error);
} else if (err == qstr("MESSAGE_NOT_MODIFIED")) {
closeBox();
return true;
} else if (err == qstr("MESSAGE_EMPTY")) {
_field->setFocus();
_field->showError();
} else {
_error = lang(lng_edit_error);
}
update();
return true;
}
2019-03-26 21:14:51 +00:00
void EditCaptionBox::setName(QString nameString, qint64 size) {
_name.setText(
st::semiboldTextStyle,
nameString,
Ui::NameTextOptions());
_status = formatSizeText(size);
_statusw = std::max(
_name.maxWidth(),
st::normalFont->width(_status));
}