Display consistent caption/comment placeholder.

After latest PRs regarding sticker sending with comment (#5500)
and album sending with caption (#4869) the input field placeholder
in SendFilesBox was inconsistent with the sending behaviour. Fix it.
This commit is contained in:
John Preston 2018-12-26 10:47:03 +04:00
parent 0b87db8b45
commit 096c310e0e
5 changed files with 33 additions and 15 deletions

View File

@ -4302,14 +4302,10 @@ void ApiWrap::sendFiles(
TextWithTags &&caption, TextWithTags &&caption,
std::shared_ptr<SendingAlbum> album, std::shared_ptr<SendingAlbum> album,
const SendOptions &options) { const SendOptions &options) {
const auto isSticker = [&] { const auto haveCaption = !caption.text.isEmpty();
if (list.files.empty() || type != SendMediaType::File) { const auto isAlbum = (album != nullptr);
return false; const auto compressImages = (type == SendMediaType::Photo);
} if (haveCaption && !list.canAddCaption(isAlbum, compressImages)) {
return list.files.front().mime == qstr("image/webp");
};
if ((list.files.size() > 1 || isSticker())
&& !caption.text.isEmpty() && !album) {
auto message = MessageToSend(options.history); auto message = MessageToSend(options.history);
message.textWithTags = std::move(caption); message.textWithTags = std::move(caption);
message.replyTo = options.replyTo; message.replyTo = options.replyTo;

View File

@ -896,10 +896,14 @@ rpl::producer<int> SingleFilePreview::desiredHeightValue() const {
return rpl::single(st::boxPhotoPadding.top() + h + st::msgShadow); return rpl::single(st::boxPhotoPadding.top() + h + st::msgShadow);
} }
Fn<QString()> FieldPlaceholder(const Storage::PreparedList &list) { Fn<QString()> FieldPlaceholder(
return langFactory(list.files.size() > 1 const Storage::PreparedList &list,
? lng_photos_comment SendFilesWay way) {
: lng_photo_caption); const auto isAlbum = (way == SendFilesWay::Album);
const auto compressImages = (way != SendFilesWay::Files);
return langFactory(list.canAddCaption(isAlbum, compressImages)
? lng_photo_caption
: lng_photos_comment);
} }
} // namespace } // namespace
@ -1339,7 +1343,7 @@ SendFilesBox::SendFilesBox(
this, this,
st::confirmCaptionArea, st::confirmCaptionArea,
Ui::InputField::Mode::MultiLine, Ui::InputField::Mode::MultiLine,
FieldPlaceholder(_list), nullptr,
caption) { caption) {
} }
@ -1433,8 +1437,8 @@ void SendFilesBox::setupShadows(
void SendFilesBox::prepare() { void SendFilesBox::prepare() {
_send = addButton(langFactory(lng_send_button), [this] { send(); }); _send = addButton(langFactory(lng_send_button), [this] { send(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); }); addButton(langFactory(lng_cancel), [this] { closeBox(); });
setupCaption();
initSendWay(); initSendWay();
setupCaption();
preparePreview(); preparePreview();
boxClosing() | rpl::start_with_next([=] { boxClosing() | rpl::start_with_next([=] {
if (!_confirmed && _cancelledCallback) { if (!_confirmed && _cancelledCallback) {
@ -1469,6 +1473,7 @@ void SendFilesBox::initSendWay() {
}(); }();
_sendWay = std::make_shared<Ui::RadioenumGroup<SendFilesWay>>(value); _sendWay = std::make_shared<Ui::RadioenumGroup<SendFilesWay>>(value);
_sendWay->setChangedCallback([this](SendFilesWay value) { _sendWay->setChangedCallback([this](SendFilesWay value) {
updateCaptionPlaceholder();
applyAlbumOrder(); applyAlbumOrder();
if (_albumPreview) { if (_albumPreview) {
_albumPreview->setSendWay(value); _albumPreview->setSendWay(value);
@ -1477,6 +1482,10 @@ void SendFilesBox::initSendWay() {
}); });
} }
void SendFilesBox::updateCaptionPlaceholder() {
_caption->setPlaceholder(FieldPlaceholder(_list, _sendWay->value()));
}
void SendFilesBox::refreshAlbumMediaCount() { void SendFilesBox::refreshAlbumMediaCount() {
_albumVideosCount = _list.albumIsPossible _albumVideosCount = _list.albumIsPossible
? ranges::count( ? ranges::count(
@ -1505,7 +1514,6 @@ void SendFilesBox::preparePreview() {
void SendFilesBox::setupControls() { void SendFilesBox::setupControls() {
setupTitleText(); setupTitleText();
setupSendWayControls(); setupSendWayControls();
_caption->setPlaceholder(FieldPlaceholder(_list));
} }
void SendFilesBox::setupSendWayControls() { void SendFilesBox::setupSendWayControls() {
@ -1593,6 +1601,7 @@ void SendFilesBox::setupCaption() {
getDelegate()->outerContainer(), getDelegate()->outerContainer(),
_caption); _caption);
updateCaptionPlaceholder();
setupEmojiPanel(); setupEmojiPanel();
} }

View File

@ -101,6 +101,7 @@ private:
void setupTitleText(); void setupTitleText();
void updateBoxSize(); void updateBoxSize();
void updateControlsGeometry(); void updateControlsGeometry();
void updateCaptionPlaceholder();
bool canAddFiles(not_null<const QMimeData*> data) const; bool canAddFiles(not_null<const QMimeData*> data) const;
bool canAddUrls(const QList<QUrl> &urls) const; bool canAddUrls(const QList<QUrl> &urls) const;

View File

@ -311,6 +311,16 @@ void PreparedList::mergeToEnd(PreparedList &&other) {
} }
} }
bool PreparedList::canAddCaption(bool isAlbum, bool compressImages) const {
const auto isSticker = [&] {
if (files.empty() || compressImages) {
return false;
}
return (files.front().mime == qstr("image/webp"));
};
return isAlbum || (files.size() == 1 && !isSticker());
}
int MaxAlbumItems() { int MaxAlbumItems() {
return kMaxAlbumCount; return kMaxAlbumCount;
} }

View File

@ -61,6 +61,8 @@ struct PreparedList {
std::vector<int> order); std::vector<int> order);
void mergeToEnd(PreparedList &&other); void mergeToEnd(PreparedList &&other);
bool canAddCaption(bool isAlbum, bool compressImages) const;
Error error = Error::None; Error error = Error::None;
QString errorData; QString errorData;
std::vector<PreparedFile> files; std::vector<PreparedFile> files;