Added search messages to HistoryWidget.

This commit is contained in:
23rd 2022-03-22 16:18:36 +03:00 committed by John Preston
parent a141a9404f
commit df38dde296
6 changed files with 136 additions and 24 deletions

View file

@ -76,6 +76,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_inner_widget.h"
#include "history/history_item_components.h"
#include "history/history_unread_things.h"
#include "history/view/controls/history_view_compose_search.h"
#include "history/view/controls/history_view_voice_record_bar.h"
#include "history/view/controls/history_view_ttl_button.h"
#include "history/view/history_view_cursor_state.h"
@ -246,10 +247,10 @@ HistoryWidget::HistoryWidget(
, _botKeyboardHide(this, st::historyBotKeyboardHide)
, _botCommandStart(this, st::historyBotCommandStart)
, _voiceRecordBar(std::make_unique<HistoryWidget::VoiceRecordBar>(
this,
controller,
_send,
st::historySendSize.height()))
this,
controller,
_send,
st::historySendSize.height()))
, _field(
this,
st::historyComposeField,
@ -801,6 +802,10 @@ HistoryWidget::HistoryWidget(
) | rpl::start_with_next([=] {
setChooseReportMessagesDetails({}, nullptr);
}, _topBar->lifetime());
_topBar->searchRequest(
) | rpl::start_with_next([=] {
searchInChat();
}, _topBar->lifetime());
session().api().sendActions(
) | rpl::filter([=](const Api::SendAction &action) {
@ -1795,7 +1800,7 @@ void HistoryWidget::setupShortcuts() {
using Command = Shortcuts::Command;
if (_history) {
request->check(Command::Search, 1) && request->handle([=] {
controller()->content()->searchInChat(_history);
searchInChat();
return true;
});
if (session().supportMode()) {
@ -2072,6 +2077,7 @@ void HistoryWidget::showHistory(
} else {
session().data().sponsoredMessages().clearItems(_history);
session().data().hideShownSpoilers();
_composeSearch = nullptr;
}
session().sendProgressManager().update(
_history,
@ -2525,8 +2531,15 @@ bool HistoryWidget::contentOverlapped(const QRect &globalRect) {
}
bool HistoryWidget::canWriteMessage() const {
if (!_history || !_canSendMessages) return false;
if (isBlocked() || isJoinChannel() || isMuteUnmute() || isBotStart()) return false;
if (!_history || !_canSendMessages) {
return false;
}
if (isBlocked() || isJoinChannel() || isMuteUnmute() || isBotStart()) {
return false;
}
if (isSearching()) {
return false;
}
return true;
}
@ -2567,7 +2580,8 @@ void HistoryWidget::updateControlsVisibility() {
}
if (isChoosingTheme()
|| (!editingMessage()
&& (isBlocked()
&& (isSearching()
|| isBlocked()
|| isJoinChannel()
|| isMuteUnmute()
|| isBotStart()
@ -2736,6 +2750,9 @@ void HistoryWidget::updateControlsVisibility() {
if (_voiceRecordBar) {
_voiceRecordBar->hideFast();
}
if (_composeSearch) {
_composeSearch->hideAnimated();
}
if (_inlineResults) {
_inlineResults->hide();
}
@ -3606,6 +3623,9 @@ void HistoryWidget::hideChildWidgets() {
if (_voiceRecordBar) {
_voiceRecordBar->hideFast();
}
if (_composeSearch) {
_composeSearch->hideAnimated();
}
if (_chooseTheme) {
_chooseTheme->hide();
}
@ -4297,6 +4317,10 @@ bool HistoryWidget::isMuteUnmute() const {
|| _peer->isRepliesChat());
}
bool HistoryWidget::isSearching() const {
return _composeSearch != nullptr;
}
bool HistoryWidget::showRecordButton() const {
return Media::Capture::instance()->available()
&& !_voiceRecordBar->isListenState()
@ -4353,6 +4377,37 @@ bool HistoryWidget::updateCmdStartShown() {
return false;
}
void HistoryWidget::searchInChat() {
if (!_history) {
return;
}
if (controller()->isPrimary()) {
controller()->content()->searchInChat(_history);
} else {
const auto update = [=] {
updateControlsVisibility();
updateBotKeyboard();
updateFieldPlaceholder();
updateControlsGeometry();
};
_composeSearch = std::make_unique<HistoryView::ComposeSearch>(
this,
controller(),
_history);
update();
_composeSearch->destroyRequests(
) | rpl::take(
1
) | rpl::start_with_next([=] {
_composeSearch = nullptr;
update();
}, _composeSearch->lifetime());
}
}
bool HistoryWidget::kbWasHidden() const {
return _history
&& (_keyboard->forMsgId()
@ -5260,7 +5315,8 @@ void HistoryWidget::updateHistoryGeometry(
if (isChoosingTheme()) {
newScrollHeight -= _chooseTheme->height();
} else if (!editingMessage()
&& (isBlocked()
&& (isSearching()
|| isBlocked()
|| isBotStart()
|| isJoinChannel()
|| isMuteUnmute()
@ -5532,7 +5588,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) {
&& _history->lastKeyboardUsed) {
_history->lastKeyboardHiddenId = _history->lastKeyboardId;
}
if (!isBotStart() && !isBlocked() && _canSendMessages && (wasVisible || (_replyToId && _replyEditMsg) || (!HasSendText(_field) && !kbWasHidden()))) {
if (!isSearching() && !isBotStart() && !isBlocked() && _canSendMessages && (wasVisible || (_replyToId && _replyEditMsg) || (!HasSendText(_field) && !kbWasHidden()))) {
if (!_a_show.animating()) {
if (hasMarkup) {
_kbScroll->show();
@ -6574,6 +6630,9 @@ void HistoryWidget::replyToMessage(not_null<HistoryItem*> item) {
}
session().data().cancelForwarding(_history);
if (_composeSearch) {
_composeSearch->hideAnimated();
}
if (_editMsgId) {
if (auto localDraft = _history->localDraft()) {
@ -6621,6 +6680,8 @@ void HistoryWidget::editMessage(not_null<HistoryItem*> item) {
controller()->show(
Ui::MakeInformBox(tr::lng_edit_caption_voice()));
return;
} else if (_composeSearch) {
_composeSearch->hideAnimated();
}
if (isRecording()) {
@ -7140,6 +7201,10 @@ void HistoryWidget::updateTopBarSelection() {
|| selectedState.textSelected;
_topBar->showSelected(selectedState);
if ((selectedState.count > 0) && _composeSearch) {
_composeSearch->hideAnimated();
}
const auto transparent = Qt::WA_TransparentForMouseEvents;
if (selectedState.count == 0) {
_reportMessages->clearState();

View file

@ -105,6 +105,7 @@ class TopBarWidget;
class ContactStatus;
class Element;
class PinnedTracker;
class ComposeSearch;
namespace Controls {
class RecordLock;
class VoiceRecordBar;
@ -609,6 +610,7 @@ private:
void inlineBotResolveFail(const MTP::Error &error, const QString &username);
[[nodiscard]] bool isRecording() const;
[[nodiscard]] bool isSearching() const;
[[nodiscard]] bool isBotStart() const;
[[nodiscard]] bool isBlocked() const;
@ -630,6 +632,8 @@ private:
bool kbWasHidden() const;
void searchInChat();
MTP::Sender _api;
MsgId _replyToId = 0;
Ui::Text::String _replyToName;
@ -743,6 +747,7 @@ private:
object_ptr<Ui::IconButton> _scheduled = { nullptr };
std::unique_ptr<HistoryView::Controls::TTLButton> _ttlInfo;
const std::unique_ptr<VoiceRecordBar> _voiceRecordBar;
std::unique_ptr<HistoryView::ComposeSearch> _composeSearch;
bool _cmdStartShown = false;
object_ptr<Ui::InputField> _field;
bool _inReplyEditForward = false;

View file

@ -252,6 +252,7 @@ public:
[[nodiscard]] rpl::producer<SearchRequest> searchRequests() const;
[[nodiscard]] rpl::producer<PeerData*> fromValue() const;
[[nodiscard]] rpl::producer<> queryChanges() const;
[[nodiscard]] rpl::producer<> closeRequests() const;
void setFrom(PeerData *peer);
@ -346,6 +347,10 @@ rpl::producer<> TopBar::queryChanges() const {
return _queryChanges.events();
}
rpl::producer<> TopBar::closeRequests() const {
return _cancel->clicks() | rpl::to_empty;
}
rpl::producer<PeerData*> TopBar::fromValue() const {
return _from.value();
}
@ -688,9 +693,13 @@ public:
not_null<History*> history);
~Inner();
void hideAnimated();
[[nodiscard]] rpl::producer<> destroyRequests() const;
[[nodiscard]] rpl::lifetime &lifetime();
private:
void showAnimated();
void hideAnimated();
void hideList();
const not_null<Window::SessionController*> _window;
@ -709,6 +718,8 @@ private:
rpl::event_stream<BottomBar::Index> jumps;
} _pendingJump;
rpl::event_stream<> _destroyRequests;
};
ComposeSearch::Inner::Inner(
@ -746,6 +757,11 @@ ComposeSearch::Inner::Inner(
hideList();
}, _topBar->lifetime());
_topBar->closeRequests(
) | rpl::start_with_next([=] {
hideAnimated();
}, _topBar->lifetime());
_apiSearch.newFounds(
) | rpl::start_with_next([=] {
const auto &apiData = _apiSearch.messages();
@ -854,7 +870,10 @@ void ComposeSearch::Inner::showAnimated() {
}
void ComposeSearch::Inner::hideAnimated() {
hideList();
Ui::Animations::HideWidgets({ _topBar.get(), _bottomBar.get() });
_destroyRequests.fire({});
}
void ComposeSearch::Inner::hideList() {
@ -863,6 +882,14 @@ void ComposeSearch::Inner::hideList() {
}
}
rpl::producer<> ComposeSearch::Inner::destroyRequests() const {
return _destroyRequests.events();
}
rpl::lifetime &ComposeSearch::Inner::lifetime() {
return _topBar->lifetime();
}
ComposeSearch::Inner::~Inner() {
}
@ -876,4 +903,16 @@ ComposeSearch::ComposeSearch(
ComposeSearch::~ComposeSearch() {
}
void ComposeSearch::hideAnimated() {
_inner->hideAnimated();
}
rpl::producer<> ComposeSearch::destroyRequests() const {
return _inner->destroyRequests();
}
rpl::lifetime &ComposeSearch::lifetime() {
return _inner->lifetime();
}
} // namespace HistoryView

View file

@ -27,6 +27,12 @@ public:
not_null<History*> history);
~ComposeSearch();
void hideAnimated();
[[nodiscard]] rpl::producer<> destroyRequests() const;
[[nodiscard]] rpl::lifetime &lifetime();
private:
class Inner;
const std::unique_ptr<Inner> _inner;

View file

@ -112,7 +112,6 @@ TopBarWidget::TopBarWidget(
_clear->setClickedCallback([=] { _clearSelection.fire({}); });
_call->setClickedCallback([=] { call(); });
_groupCall->setClickedCallback([=] { groupCall(); });
_search->setClickedCallback([=] { search(); });
_menuToggle->setClickedCallback([=] { showPeerMenu(); });
_infoToggle->setClickedCallback([=] { toggleInfoSection(); });
_back->addClickHandler([=] { backClicked(); });
@ -230,12 +229,6 @@ void TopBarWidget::refreshLang() {
InvokeQueued(this, [this] { updateControlsGeometry(); });
}
void TopBarWidget::search() {
if (_activeChat.key) {
_controller->content()->searchInChat(_activeChat.key);
}
}
void TopBarWidget::call() {
if (const auto peer = _activeChat.key.peer()) {
if (const auto user = peer->asUser()) {
@ -262,6 +255,10 @@ void TopBarWidget::clearChooseMessagesForReport() {
setChooseForReportReason(std::nullopt);
}
rpl::producer<> TopBarWidget::searchRequest() const {
return _search->clicks() | rpl::to_empty;
}
void TopBarWidget::setChooseForReportReason(
std::optional<Ui::ReportReason> reason) {
if (_chooseForReportReason == reason) {

View file

@ -71,21 +71,22 @@ public:
void showChooseMessagesForReport(Ui::ReportReason reason);
void clearChooseMessagesForReport();
rpl::producer<> forwardSelectionRequest() const {
[[nodiscard]] rpl::producer<> forwardSelectionRequest() const {
return _forwardSelection.events();
}
rpl::producer<> sendNowSelectionRequest() const {
[[nodiscard]] rpl::producer<> sendNowSelectionRequest() const {
return _sendNowSelection.events();
}
rpl::producer<> deleteSelectionRequest() const {
[[nodiscard]] rpl::producer<> deleteSelectionRequest() const {
return _deleteSelection.events();
}
rpl::producer<> clearSelectionRequest() const {
[[nodiscard]] rpl::producer<> clearSelectionRequest() const {
return _clearSelection.events();
}
rpl::producer<> cancelChooseForReportRequest() const {
[[nodiscard]] rpl::producer<> cancelChooseForReportRequest() const {
return _cancelChooseForReport.events();
}
[[nodiscard]] rpl::producer<> searchRequest() const;
protected:
void paintEvent(QPaintEvent *e) override;
@ -108,7 +109,6 @@ private:
void call();
void groupCall();
void startGroupCall(not_null<ChannelData*> megagroup, bool confirmed);
void search();
void showPeerMenu();
void showGroupCallMenu(not_null<PeerData*> peer);
void toggleInfoSection();