mirror of https://github.com/procxx/kepka.git
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:
parent
0b87db8b45
commit
096c310e0e
|
@ -4302,14 +4302,10 @@ void ApiWrap::sendFiles(
|
|||
TextWithTags &&caption,
|
||||
std::shared_ptr<SendingAlbum> album,
|
||||
const SendOptions &options) {
|
||||
const auto isSticker = [&] {
|
||||
if (list.files.empty() || type != SendMediaType::File) {
|
||||
return false;
|
||||
}
|
||||
return list.files.front().mime == qstr("image/webp");
|
||||
};
|
||||
if ((list.files.size() > 1 || isSticker())
|
||||
&& !caption.text.isEmpty() && !album) {
|
||||
const auto haveCaption = !caption.text.isEmpty();
|
||||
const auto isAlbum = (album != nullptr);
|
||||
const auto compressImages = (type == SendMediaType::Photo);
|
||||
if (haveCaption && !list.canAddCaption(isAlbum, compressImages)) {
|
||||
auto message = MessageToSend(options.history);
|
||||
message.textWithTags = std::move(caption);
|
||||
message.replyTo = options.replyTo;
|
||||
|
|
|
@ -896,10 +896,14 @@ rpl::producer<int> SingleFilePreview::desiredHeightValue() const {
|
|||
return rpl::single(st::boxPhotoPadding.top() + h + st::msgShadow);
|
||||
}
|
||||
|
||||
Fn<QString()> FieldPlaceholder(const Storage::PreparedList &list) {
|
||||
return langFactory(list.files.size() > 1
|
||||
? lng_photos_comment
|
||||
: lng_photo_caption);
|
||||
Fn<QString()> FieldPlaceholder(
|
||||
const Storage::PreparedList &list,
|
||||
SendFilesWay way) {
|
||||
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
|
||||
|
@ -1339,7 +1343,7 @@ SendFilesBox::SendFilesBox(
|
|||
this,
|
||||
st::confirmCaptionArea,
|
||||
Ui::InputField::Mode::MultiLine,
|
||||
FieldPlaceholder(_list),
|
||||
nullptr,
|
||||
caption) {
|
||||
}
|
||||
|
||||
|
@ -1433,8 +1437,8 @@ void SendFilesBox::setupShadows(
|
|||
void SendFilesBox::prepare() {
|
||||
_send = addButton(langFactory(lng_send_button), [this] { send(); });
|
||||
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
||||
setupCaption();
|
||||
initSendWay();
|
||||
setupCaption();
|
||||
preparePreview();
|
||||
boxClosing() | rpl::start_with_next([=] {
|
||||
if (!_confirmed && _cancelledCallback) {
|
||||
|
@ -1469,6 +1473,7 @@ void SendFilesBox::initSendWay() {
|
|||
}();
|
||||
_sendWay = std::make_shared<Ui::RadioenumGroup<SendFilesWay>>(value);
|
||||
_sendWay->setChangedCallback([this](SendFilesWay value) {
|
||||
updateCaptionPlaceholder();
|
||||
applyAlbumOrder();
|
||||
if (_albumPreview) {
|
||||
_albumPreview->setSendWay(value);
|
||||
|
@ -1477,6 +1482,10 @@ void SendFilesBox::initSendWay() {
|
|||
});
|
||||
}
|
||||
|
||||
void SendFilesBox::updateCaptionPlaceholder() {
|
||||
_caption->setPlaceholder(FieldPlaceholder(_list, _sendWay->value()));
|
||||
}
|
||||
|
||||
void SendFilesBox::refreshAlbumMediaCount() {
|
||||
_albumVideosCount = _list.albumIsPossible
|
||||
? ranges::count(
|
||||
|
@ -1505,7 +1514,6 @@ void SendFilesBox::preparePreview() {
|
|||
void SendFilesBox::setupControls() {
|
||||
setupTitleText();
|
||||
setupSendWayControls();
|
||||
_caption->setPlaceholder(FieldPlaceholder(_list));
|
||||
}
|
||||
|
||||
void SendFilesBox::setupSendWayControls() {
|
||||
|
@ -1593,6 +1601,7 @@ void SendFilesBox::setupCaption() {
|
|||
getDelegate()->outerContainer(),
|
||||
_caption);
|
||||
|
||||
updateCaptionPlaceholder();
|
||||
setupEmojiPanel();
|
||||
}
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ private:
|
|||
void setupTitleText();
|
||||
void updateBoxSize();
|
||||
void updateControlsGeometry();
|
||||
void updateCaptionPlaceholder();
|
||||
|
||||
bool canAddFiles(not_null<const QMimeData*> data) const;
|
||||
bool canAddUrls(const QList<QUrl> &urls) const;
|
||||
|
|
|
@ -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() {
|
||||
return kMaxAlbumCount;
|
||||
}
|
||||
|
|
|
@ -61,6 +61,8 @@ struct PreparedList {
|
|||
std::vector<int> order);
|
||||
void mergeToEnd(PreparedList &&other);
|
||||
|
||||
bool canAddCaption(bool isAlbum, bool compressImages) const;
|
||||
|
||||
Error error = Error::None;
|
||||
QString errorData;
|
||||
std::vector<PreparedFile> files;
|
||||
|
|
Loading…
Reference in New Issue