Changed behavior to hide field buttons in HistoryWidget with typed text.
This commit is contained in:
parent
58caec8d05
commit
24498bc95f
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
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 "chat_helpers/field_characters_count_manager.h"
|
||||||
|
|
||||||
|
FieldCharsCountManager::FieldCharsCountManager() = default;
|
||||||
|
|
||||||
|
void FieldCharsCountManager::setCount(int count) {
|
||||||
|
_previous = _current;
|
||||||
|
_current = count;
|
||||||
|
if (_previous != _current) {
|
||||||
|
constexpr auto kMax = 15;
|
||||||
|
const auto was = (_previous > kMax);
|
||||||
|
const auto now = (_current > kMax);
|
||||||
|
if (was != now) {
|
||||||
|
_isLimitExceeded = now;
|
||||||
|
_limitExceeds.fire({});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int FieldCharsCountManager::count() const {
|
||||||
|
return _current;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FieldCharsCountManager::isLimitExceeded() const {
|
||||||
|
return _isLimitExceeded;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> FieldCharsCountManager::limitExceeds() const {
|
||||||
|
return _limitExceeds.events();
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
class FieldCharsCountManager final {
|
||||||
|
public:
|
||||||
|
FieldCharsCountManager();
|
||||||
|
|
||||||
|
void setCount(int count);
|
||||||
|
[[nodiscard]] int count() const;
|
||||||
|
[[nodiscard]] bool isLimitExceeded() const;
|
||||||
|
[[nodiscard]] rpl::producer<> limitExceeds() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int _current = 0;
|
||||||
|
int _previous = 0;
|
||||||
|
bool _isLimitExceeded = false;
|
||||||
|
|
||||||
|
rpl::event_stream<> _limitExceeds;
|
||||||
|
|
||||||
|
};
|
|
@ -423,6 +423,22 @@ HistoryWidget::HistoryWidget(
|
||||||
});
|
});
|
||||||
InitMessageFieldFade(_field, st::historyComposeField.textBg);
|
InitMessageFieldFade(_field, st::historyComposeField.textBg);
|
||||||
|
|
||||||
|
_fieldCharsCountManager.limitExceeds(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
const auto hide = _fieldCharsCountManager.isLimitExceeded();
|
||||||
|
if (_silent) {
|
||||||
|
_silent->setVisible(!hide);
|
||||||
|
}
|
||||||
|
if (_ttlInfo) {
|
||||||
|
_ttlInfo->setVisible(!hide);
|
||||||
|
}
|
||||||
|
if (_scheduled) {
|
||||||
|
_scheduled->setVisible(!hide);
|
||||||
|
}
|
||||||
|
updateFieldSize();
|
||||||
|
moveFieldControls();
|
||||||
|
}, lifetime());
|
||||||
|
|
||||||
_keyboard->sendCommandRequests(
|
_keyboard->sendCommandRequests(
|
||||||
) | rpl::start_with_next([=](Bot::SendCommandRequest r) {
|
) | rpl::start_with_next([=](Bot::SendCommandRequest r) {
|
||||||
sendBotCommand(r);
|
sendBotCommand(r);
|
||||||
|
@ -1673,7 +1689,7 @@ void HistoryWidget::fieldChanged() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
checkCharsLimitation();
|
checkCharsCount();
|
||||||
|
|
||||||
updateSendButtonType();
|
updateSendButtonType();
|
||||||
if (!HasSendText(_field)) {
|
if (!HasSendText(_field)) {
|
||||||
|
@ -1998,7 +2014,6 @@ bool HistoryWidget::applyDraft(FieldHistoryAction fieldHistoryAction) {
|
||||||
updateControlsVisibility();
|
updateControlsVisibility();
|
||||||
updateControlsGeometry();
|
updateControlsGeometry();
|
||||||
refreshTopBarActiveChat();
|
refreshTopBarActiveChat();
|
||||||
checkCharsLimitation();
|
|
||||||
if (_editMsgId) {
|
if (_editMsgId) {
|
||||||
updateReplyEditTexts();
|
updateReplyEditTexts();
|
||||||
if (!_replyEditMsg) {
|
if (!_replyEditMsg) {
|
||||||
|
@ -2388,6 +2403,7 @@ void HistoryWidget::showHistory(
|
||||||
if (!applyDraft()) {
|
if (!applyDraft()) {
|
||||||
clearFieldText();
|
clearFieldText();
|
||||||
}
|
}
|
||||||
|
checkCharsCount();
|
||||||
_send->finishAnimating();
|
_send->finishAnimating();
|
||||||
|
|
||||||
updateControlsGeometry();
|
updateControlsGeometry();
|
||||||
|
@ -2813,6 +2829,7 @@ bool HistoryWidget::canWriteMessage() const {
|
||||||
|
|
||||||
void HistoryWidget::updateControlsVisibility() {
|
void HistoryWidget::updateControlsVisibility() {
|
||||||
auto fieldDisabledRemoved = (_fieldDisabled != nullptr);
|
auto fieldDisabledRemoved = (_fieldDisabled != nullptr);
|
||||||
|
const auto hideExtraButtons = _fieldCharsCountManager.isLimitExceeded();
|
||||||
const auto guard = gsl::finally([&] {
|
const auto guard = gsl::finally([&] {
|
||||||
if (fieldDisabledRemoved) {
|
if (fieldDisabledRemoved) {
|
||||||
_fieldDisabled = nullptr;
|
_fieldDisabled = nullptr;
|
||||||
|
@ -2999,7 +3016,7 @@ void HistoryWidget::updateControlsVisibility() {
|
||||||
auto rightButtonsChanged = false;
|
auto rightButtonsChanged = false;
|
||||||
if (_silent) {
|
if (_silent) {
|
||||||
const auto was = _silent->isVisible();
|
const auto was = _silent->isVisible();
|
||||||
const auto now = (!_editMsgId);
|
const auto now = (!_editMsgId) && (!hideExtraButtons);
|
||||||
if (was != now) {
|
if (was != now) {
|
||||||
_silent->setVisible(now);
|
_silent->setVisible(now);
|
||||||
rightButtonsChanged = true;
|
rightButtonsChanged = true;
|
||||||
|
@ -3007,7 +3024,7 @@ void HistoryWidget::updateControlsVisibility() {
|
||||||
}
|
}
|
||||||
if (_scheduled) {
|
if (_scheduled) {
|
||||||
const auto was = _scheduled->isVisible();
|
const auto was = _scheduled->isVisible();
|
||||||
const auto now = (!_editMsgId);
|
const auto now = (!_editMsgId) && (!hideExtraButtons);
|
||||||
if (was != now) {
|
if (was != now) {
|
||||||
_scheduled->setVisible(now);
|
_scheduled->setVisible(now);
|
||||||
rightButtonsChanged = true;
|
rightButtonsChanged = true;
|
||||||
|
@ -3015,7 +3032,7 @@ void HistoryWidget::updateControlsVisibility() {
|
||||||
}
|
}
|
||||||
if (_ttlInfo) {
|
if (_ttlInfo) {
|
||||||
const auto was = _ttlInfo->isVisible();
|
const auto was = _ttlInfo->isVisible();
|
||||||
const auto now = (!_editMsgId);
|
const auto now = (!_editMsgId) && (!hideExtraButtons);
|
||||||
if (was != now) {
|
if (was != now) {
|
||||||
_ttlInfo->setVisible(now);
|
_ttlInfo->setVisible(now);
|
||||||
rightButtonsChanged = true;
|
rightButtonsChanged = true;
|
||||||
|
@ -3936,7 +3953,7 @@ void HistoryWidget::saveEditMsg() {
|
||||||
const auto maxCaptionSize = !hasMediaWithCaption
|
const auto maxCaptionSize = !hasMediaWithCaption
|
||||||
? MaxMessageSize
|
? MaxMessageSize
|
||||||
: Data::PremiumLimits(&session()).captionLengthCurrent();
|
: Data::PremiumLimits(&session()).captionLengthCurrent();
|
||||||
const auto remove = Ui::FieldCharacterCount(_field) - maxCaptionSize;
|
const auto remove = _fieldCharsCountManager.count() - maxCaptionSize;
|
||||||
if (remove > 0) {
|
if (remove > 0) {
|
||||||
controller()->showToast(
|
controller()->showToast(
|
||||||
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
|
tr::lng_edit_limit_reached(tr::now, lt_count, remove));
|
||||||
|
@ -4826,7 +4843,7 @@ bool HistoryWidget::updateCmdStartShown() {
|
||||||
} else if (!_botMenu.button) {
|
} else if (!_botMenu.button) {
|
||||||
buttonChanged = true;
|
buttonChanged = true;
|
||||||
_botMenu.text = bot->botInfo->botMenuButtonText;
|
_botMenu.text = bot->botInfo->botMenuButtonText;
|
||||||
_botMenu.small = (Ui::FieldCharacterCount(_field) > kSmallMenuAfter);
|
_botMenu.small = (_fieldCharsCountManager.count() > kSmallMenuAfter);
|
||||||
if (_botMenu.small) {
|
if (_botMenu.small) {
|
||||||
if (const auto e = FirstEmoji(_botMenu.text); !e.isEmpty()) {
|
if (const auto e = FirstEmoji(_botMenu.text); !e.isEmpty()) {
|
||||||
_botMenu.text = e;
|
_botMenu.text = e;
|
||||||
|
@ -4863,7 +4880,7 @@ bool HistoryWidget::updateCmdStartShown() {
|
||||||
}
|
}
|
||||||
}, _botMenu.button->lifetime());
|
}, _botMenu.button->lifetime());
|
||||||
}
|
}
|
||||||
const auto textSmall = Ui::FieldCharacterCount(_field) > kSmallMenuAfter;
|
const auto textSmall = _fieldCharsCountManager.count() > kSmallMenuAfter;
|
||||||
const auto textChanged = _botMenu.button
|
const auto textChanged = _botMenu.button
|
||||||
&& ((_botMenu.text != bot->botInfo->botMenuButtonText)
|
&& ((_botMenu.text != bot->botInfo->botMenuButtonText)
|
||||||
|| (_botMenu.small != textSmall));
|
|| (_botMenu.small != textSmall));
|
||||||
|
@ -7378,6 +7395,11 @@ void HistoryWidget::showPremiumToast(not_null<DocumentData*> document) {
|
||||||
_stickerToast->showFor(document);
|
_stickerToast->showFor(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HistoryWidget::checkCharsCount() {
|
||||||
|
_fieldCharsCountManager.setCount(Ui::FieldCharacterCount(_field));
|
||||||
|
checkCharsLimitation();
|
||||||
|
}
|
||||||
|
|
||||||
void HistoryWidget::checkCharsLimitation() {
|
void HistoryWidget::checkCharsLimitation() {
|
||||||
if (!_history || !_editMsgId) {
|
if (!_history || !_editMsgId) {
|
||||||
_charsLimitation = nullptr;
|
_charsLimitation = nullptr;
|
||||||
|
@ -7393,7 +7415,7 @@ void HistoryWidget::checkCharsLimitation() {
|
||||||
const auto maxCaptionSize = !hasMediaWithCaption
|
const auto maxCaptionSize = !hasMediaWithCaption
|
||||||
? MaxMessageSize
|
? MaxMessageSize
|
||||||
: Data::PremiumLimits(&session()).captionLengthCurrent();
|
: Data::PremiumLimits(&session()).captionLengthCurrent();
|
||||||
const auto remove = Ui::FieldCharacterCount(_field) - maxCaptionSize;
|
const auto remove = _fieldCharsCountManager.count() - maxCaptionSize;
|
||||||
if (remove > 0) {
|
if (remove > 0) {
|
||||||
if (!_charsLimitation) {
|
if (!_charsLimitation) {
|
||||||
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(
|
_charsLimitation = base::make_unique_q<CharactersLimitLabel>(
|
||||||
|
@ -7425,7 +7447,7 @@ void HistoryWidget::setFieldText(
|
||||||
_textUpdateEvents = TextUpdateEvent::SaveDraft
|
_textUpdateEvents = TextUpdateEvent::SaveDraft
|
||||||
| TextUpdateEvent::SendTyping;
|
| TextUpdateEvent::SendTyping;
|
||||||
|
|
||||||
checkCharsLimitation();
|
checkCharsCount();
|
||||||
|
|
||||||
if (_preview) {
|
if (_preview) {
|
||||||
_preview->checkNow(false);
|
_preview->checkNow(false);
|
||||||
|
|
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/history_view_top_toast.h"
|
#include "history/history_view_top_toast.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "chat_helpers/field_autocomplete.h"
|
#include "chat_helpers/field_autocomplete.h"
|
||||||
|
#include "chat_helpers/field_characters_count_manager.h"
|
||||||
#include "window/section_widget.h"
|
#include "window/section_widget.h"
|
||||||
#include "ui/widgets/fields/input_field.h"
|
#include "ui/widgets/fields/input_field.h"
|
||||||
#include "mtproto/sender.h"
|
#include "mtproto/sender.h"
|
||||||
|
@ -646,6 +647,7 @@ private:
|
||||||
|
|
||||||
void switchToSearch(QString query);
|
void switchToSearch(QString query);
|
||||||
|
|
||||||
|
void checkCharsCount();
|
||||||
void checkCharsLimitation();
|
void checkCharsLimitation();
|
||||||
|
|
||||||
MTP::Sender _api;
|
MTP::Sender _api;
|
||||||
|
@ -785,6 +787,8 @@ private:
|
||||||
object_ptr<Ui::ScrollArea> _kbScroll;
|
object_ptr<Ui::ScrollArea> _kbScroll;
|
||||||
const not_null<BotKeyboard*> _keyboard;
|
const not_null<BotKeyboard*> _keyboard;
|
||||||
|
|
||||||
|
FieldCharsCountManager _fieldCharsCountManager;
|
||||||
|
|
||||||
std::unique_ptr<Ui::ChooseThemeController> _chooseTheme;
|
std::unique_ptr<Ui::ChooseThemeController> _chooseTheme;
|
||||||
|
|
||||||
object_ptr<Ui::InnerDropdown> _membersDropdown = { nullptr };
|
object_ptr<Ui::InnerDropdown> _membersDropdown = { nullptr };
|
||||||
|
|
|
@ -63,6 +63,8 @@ PRIVATE
|
||||||
calls/group/ui/desktop_capture_choose_source.cpp
|
calls/group/ui/desktop_capture_choose_source.cpp
|
||||||
calls/group/ui/desktop_capture_choose_source.h
|
calls/group/ui/desktop_capture_choose_source.h
|
||||||
|
|
||||||
|
chat_helpers/field_characters_count_manager.cpp
|
||||||
|
chat_helpers/field_characters_count_manager.h
|
||||||
chat_helpers/stickers_emoji_image_loader.cpp
|
chat_helpers/stickers_emoji_image_loader.cpp
|
||||||
chat_helpers/stickers_emoji_image_loader.h
|
chat_helpers/stickers_emoji_image_loader.h
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue