Added counter label of characters limit to send files box.

This commit is contained in:
23rd 2024-02-15 09:37:11 +03:00
parent d1eaf284b1
commit 6de471db17
6 changed files with 64 additions and 8 deletions

View file

@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "chat_helpers/tabbed_selector.h"
#include "editor/photo_editor_layer_widget.h"
#include "history/history_drag_area.h"
#include "history/view/controls/history_view_characters_limit.h"
#include "history/view/history_view_schedule_box.h"
#include "core/file_utilities.h"
#include "core/mime_type.h"
@ -48,6 +49,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lottie/lottie_single_player.h"
#include "data/data_document.h"
#include "data/data_user.h"
#include "data/data_peer_values.h" // Data::AmPremiumValue.
#include "data/data_premium_limits.h"
#include "data/stickers/data_stickers.h"
#include "data/stickers/data_custom_emoji.h"
@ -1060,6 +1062,39 @@ void SendFilesBox::setupCaption() {
updateCaptionPlaceholder();
setupEmojiPanel();
rpl::single(rpl::empty_value()) | rpl::then(
_caption->changes()
) | rpl::start_with_next([=] {
checkCharsLimitation();
}, _caption->lifetime());
}
void SendFilesBox::checkCharsLimitation() {
const auto limits = Data::PremiumLimits(&_show->session());
const auto caption = (_caption && !_caption->isHidden())
? _caption->getTextWithAppliedMarkdown()
: TextWithTags();
const auto remove = caption.text.size() - limits.captionLengthCurrent();
if ((remove > 0) && _emojiToggle) {
if (!_charsLimitation) {
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(
this,
_emojiToggle.data(),
style::al_top);
_charsLimitation->show();
Data::AmPremiumValue(
&_show->session()
) | rpl::start_with_next([=] {
checkCharsLimitation();
}, _charsLimitation->lifetime());
}
_charsLimitation->setLeft(remove);
} else {
if (_charsLimitation) {
_charsLimitation = nullptr;
}
}
}
void SendFilesBox::setupEmojiPanel() {

View file

@ -50,6 +50,10 @@ namespace SendMenu {
enum class Type;
} // namespace SendMenu
namespace HistoryView::Controls {
class CharactersLimitLabel;
} // namespace HistoryView::Controls
enum class SendFilesAllow {
OnlyOne = (1 << 0),
Photos = (1 << 1),
@ -221,6 +225,8 @@ private:
void enqueueNextPrepare();
void addPreparedAsyncFile(Ui::PreparedFile &&file);
void checkCharsLimitation();
const std::shared_ptr<ChatHelpers::Show> _show;
const style::ComposeControls &_st;
const Api::SendType _sendType = Api::SendType();
@ -244,6 +250,8 @@ private:
object_ptr<Ui::EmojiButton> _emojiToggle = { nullptr };
base::unique_qptr<ChatHelpers::TabbedPanel> _emojiPanel;
base::unique_qptr<QObject> _emojiFilter;
using CharactersLimitLabel = HistoryView::Controls::CharactersLimitLabel;
base::unique_qptr<CharactersLimitLabel> _charsLimitation;
object_ptr<Ui::Checkbox> _groupFiles = { nullptr };
object_ptr<Ui::Checkbox> _sendImagesAsPhotos = { nullptr };

View file

@ -7319,7 +7319,8 @@ void HistoryWidget::checkCharsLimitation() {
if (!_charsLimitation) {
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(
this,
_send.get());
_send.get(),
style::al_bottom);
_charsLimitation->show();
Data::AmPremiumValue(
&session()

View file

@ -7,20 +7,30 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "history/view/controls/history_view_characters_limit.h"
#include "ui/rect.h"
#include "styles/style_chat_helpers.h"
namespace HistoryView::Controls {
CharactersLimitLabel::CharactersLimitLabel(
not_null<Ui::RpWidget*> parent,
not_null<Ui::RpWidget*> widgetBelow)
not_null<Ui::RpWidget*> widgetToAlign,
style::align align)
: Ui::FlatLabel(parent, st::historyCharsLimitationLabel) {
Expects((align == style::al_top) || align == style::al_bottom);
const auto w = st::historyCharsLimitationLabel.minWidth;
using F = Fn<void(int, const QRect &)>;
const auto position = (align == style::al_top)
? F([=](int height, const QRect &g) {
move(g.x() + (g.width() - w) / 2, rect::bottom(g));
})
: F([=](int height, const QRect &g) {
move(g.x() + (g.width() - w) / 2, g.y() - height);
});
rpl::combine(
Ui::RpWidget::heightValue(),
widgetBelow->positionValue()
) | rpl::start_with_next([=](int height, const QPoint &p) {
move(p.x(), p.y() - height);
}, lifetime());
widgetToAlign->geometryValue()
) | rpl::start_with_next(position, lifetime());
}
void CharactersLimitLabel::setLeft(int value) {

View file

@ -15,7 +15,8 @@ class CharactersLimitLabel final : public Ui::FlatLabel {
public:
CharactersLimitLabel(
not_null<Ui::RpWidget*> parent,
not_null<Ui::RpWidget*> widgetBelow);
not_null<Ui::RpWidget*> widgetToAlign,
style::align align);
void setLeft(int value);

View file

@ -3322,7 +3322,8 @@ void ComposeControls::checkCharsLimitation() {
using namespace Controls;
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(
_wrap.get(),
_send.get());
_send.get(),
style::al_bottom);
_charsLimitation->show();
Data::AmPremiumValue(
&session()