mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 13:17:08 +02:00
Add search in saved sublist.
This commit is contained in:
parent
9c151ca151
commit
f5fcfaba0c
6 changed files with 79 additions and 21 deletions
|
@ -43,6 +43,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_changes.h"
|
||||
#include "data/data_message_reactions.h"
|
||||
#include "data/data_saved_messages.h"
|
||||
#include "data/data_saved_sublist.h"
|
||||
#include "data/data_stories.h"
|
||||
#include "data/stickers/data_stickers.h"
|
||||
#include "data/data_send_action.h"
|
||||
|
@ -502,7 +503,7 @@ int InnerWidget::searchInChatSkip() const {
|
|||
if (_searchInChat) {
|
||||
result += st::searchedBarHeight + st::dialogsSearchInHeight;
|
||||
}
|
||||
if (_searchFromPeer) {
|
||||
if (_searchFromShown) {
|
||||
if (_searchInChat) {
|
||||
result += st::lineWidth;
|
||||
}
|
||||
|
@ -1139,7 +1140,7 @@ void InnerWidget::paintSearchInChat(
|
|||
auto fullRect = QRect(0, top, width(), height - top);
|
||||
p.fillRect(fullRect, currentBg());
|
||||
if (_searchInChat) {
|
||||
if (_searchFromPeer) {
|
||||
if (_searchFromShown) {
|
||||
p.fillRect(QRect(0, top + st::dialogsSearchInHeight, width(), st::lineWidth), st::shadowFg);
|
||||
}
|
||||
p.setPen(st::dialogsNameFg);
|
||||
|
@ -1153,15 +1154,17 @@ void InnerWidget::paintSearchInChat(
|
|||
} else {
|
||||
paintSearchInPeer(p, peer, _searchInChatUserpic, top, _searchInChatText);
|
||||
}
|
||||
} else if (const auto sublist = _searchInChat.sublist()) {
|
||||
paintSearchInSaved(p, top, _searchInChatText);
|
||||
} else {
|
||||
Unexpected("Empty Key in paintSearchInChat.");
|
||||
}
|
||||
top += st::dialogsSearchInHeight + st::lineWidth;
|
||||
}
|
||||
if (_searchFromPeer) {
|
||||
if (_searchFromShown) {
|
||||
p.setPen(st::dialogsTextFg);
|
||||
p.setTextPalette(st::dialogsSearchFromPalette);
|
||||
paintSearchInPeer(p, _searchFromPeer, _searchFromUserUserpic, top, _searchFromUserText);
|
||||
paintSearchInPeer(p, _searchFromShown, _searchFromUserUserpic, top, _searchFromUserText);
|
||||
p.restoreTextPalette();
|
||||
}
|
||||
}
|
||||
|
@ -2967,7 +2970,9 @@ bool InnerWidget::hasFilteredResults() const {
|
|||
|
||||
void InnerWidget::searchInChat(Key key, PeerData *from) {
|
||||
_searchInMigrated = nullptr;
|
||||
if (const auto peer = key.peer()) {
|
||||
const auto sublist = key.sublist();
|
||||
const auto peer = sublist ? session().user().get() : key.peer();
|
||||
if (peer) {
|
||||
if (const auto migrateTo = peer->migrateTo()) {
|
||||
return searchInChat(peer->owner().history(migrateTo), from);
|
||||
} else if (const auto migrateFrom = peer->migrateFrom()) {
|
||||
|
@ -3013,15 +3018,16 @@ void InnerWidget::searchInChat(Key key, PeerData *from) {
|
|||
}
|
||||
_searchInChat = key;
|
||||
_searchFromPeer = from;
|
||||
_searchFromShown = key.sublist() ? key.sublist()->peer().get() : from;
|
||||
if (_searchInChat) {
|
||||
onHashtagFilterUpdate(QStringView());
|
||||
_cancelSearchInChat->show();
|
||||
} else {
|
||||
_cancelSearchInChat->hide();
|
||||
}
|
||||
if (_searchFromPeer) {
|
||||
if (_searchFromShown) {
|
||||
_cancelSearchFromUser->show();
|
||||
_searchFromUserUserpic = _searchFromPeer->createUserpicView();
|
||||
_searchFromUserUserpic = _searchFromShown->createUserpicView();
|
||||
} else {
|
||||
_cancelSearchFromUser->hide();
|
||||
_searchFromUserUserpic = {};
|
||||
|
@ -3030,7 +3036,7 @@ void InnerWidget::searchInChat(Key key, PeerData *from) {
|
|||
refreshSearchInChatLabel();
|
||||
}
|
||||
|
||||
if (const auto peer = _searchInChat.peer()) {
|
||||
if (peer) {
|
||||
_searchInChatUserpic = peer->createUserpicView();
|
||||
} else {
|
||||
_searchInChatUserpic = {};
|
||||
|
@ -3059,6 +3065,8 @@ void InnerWidget::refreshSearchInChatLabel() {
|
|||
return tr::lng_replies_messages(tr::now);
|
||||
}
|
||||
return peer->name();
|
||||
} else if (_searchInChat.sublist()) {
|
||||
return tr::lng_saved_messages(tr::now);
|
||||
}
|
||||
return QString();
|
||||
}();
|
||||
|
@ -3068,7 +3076,7 @@ void InnerWidget::refreshSearchInChatLabel() {
|
|||
dialog,
|
||||
Ui::DialogTextOptions());
|
||||
}
|
||||
const auto from = _searchFromPeer ? _searchFromPeer->name() : QString();
|
||||
const auto from = _searchFromShown ? _searchFromShown->name() : u""_q;
|
||||
if (!from.isEmpty()) {
|
||||
const auto fromUserText = tr::lng_dlg_search_from(
|
||||
tr::now,
|
||||
|
|
|
@ -483,6 +483,7 @@ private:
|
|||
Key _searchInChat;
|
||||
History *_searchInMigrated = nullptr;
|
||||
PeerData *_searchFromPeer = nullptr;
|
||||
PeerData *_searchFromShown = nullptr;
|
||||
mutable Ui::PeerUserpicView _searchInChatUserpic;
|
||||
mutable Ui::PeerUserpicView _searchFromUserUserpic;
|
||||
Ui::Text::String _searchInChatText;
|
||||
|
|
|
@ -67,6 +67,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_changes.h"
|
||||
#include "data/data_download_manager.h"
|
||||
#include "data/data_chat_filters.h"
|
||||
#include "data/data_saved_sublist.h"
|
||||
#include "data/data_stories.h"
|
||||
#include "info/downloads/info_downloads_widget.h"
|
||||
#include "info/info_memento.h"
|
||||
|
@ -1756,21 +1757,27 @@ bool Widget::searchMessages(bool searchCache) {
|
|||
auto &histories = session().data().histories();
|
||||
const auto type = Data::Histories::RequestType::History;
|
||||
const auto history = session().data().history(peer);
|
||||
const auto sublist = _openedForum
|
||||
? nullptr
|
||||
: _searchInChat.sublist();
|
||||
const auto fromPeer = sublist ? nullptr : _searchQueryFrom;
|
||||
const auto savedPeer = sublist
|
||||
? sublist->peer().get()
|
||||
: nullptr;
|
||||
_searchInHistoryRequest = histories.sendRequest(history, type, [=](Fn<void()> finish) {
|
||||
const auto type = SearchRequestType::PeerFromStart;
|
||||
using Flag = MTPmessages_Search::Flag;
|
||||
_searchRequest = session().api().request(MTPmessages_Search(
|
||||
MTP_flags((topic ? Flag::f_top_msg_id : Flag())
|
||||
| (_searchQueryFrom ? Flag::f_from_id : Flag())
|
||||
| (fromPeer ? Flag::f_from_id : Flag())
|
||||
| (savedPeer ? Flag::f_saved_peer_id : Flag())
|
||||
| (_searchQueryTags.empty()
|
||||
? Flag()
|
||||
: Flag::f_saved_reaction)),
|
||||
peer->input,
|
||||
MTP_string(_searchQuery),
|
||||
(_searchQueryFrom
|
||||
? _searchQueryFrom->input
|
||||
: MTP_inputPeerEmpty()),
|
||||
MTPInputPeer(), // saved_peer_id
|
||||
(fromPeer ? fromPeer->input : MTP_inputPeerEmpty()),
|
||||
(savedPeer ? savedPeer->input : MTP_inputPeerEmpty()),
|
||||
MTP_vector_from_range(
|
||||
_searchQueryTags | ranges::views::transform(
|
||||
Data::ReactionToMTP
|
||||
|
@ -1922,6 +1929,7 @@ void Widget::searchMessages(const QString &query, Key inChat) {
|
|||
const auto inChatChanged = [&] {
|
||||
const auto inPeer = inChat.peer();
|
||||
const auto inTopic = inChat.topic();
|
||||
const auto inSublist = inChat.sublist();
|
||||
if (!inTopic
|
||||
&& _openedForum
|
||||
&& inPeer == _openedForum->channel()
|
||||
|
@ -1931,7 +1939,7 @@ void Widget::searchMessages(const QString &query, Key inChat) {
|
|||
} else if ((inTopic || (inPeer && !inPeer->isForum()))
|
||||
&& (inChat == _searchInChat)) {
|
||||
return false;
|
||||
} else if (const auto inPeer = inChat.peer()) {
|
||||
} else if (inPeer) {
|
||||
if (const auto to = inPeer->migrateTo()) {
|
||||
if (to == _searchInChat.peer() && !_searchInChat.topic()) {
|
||||
return false;
|
||||
|
@ -2005,6 +2013,13 @@ void Widget::searchMore() {
|
|||
const auto topic = searchInTopic();
|
||||
const auto type = Data::Histories::RequestType::History;
|
||||
const auto history = session().data().history(peer);
|
||||
const auto sublist = _openedForum
|
||||
? nullptr
|
||||
: _searchInChat.sublist();
|
||||
const auto fromPeer = sublist ? nullptr : _searchQueryFrom;
|
||||
const auto savedPeer = sublist
|
||||
? sublist->peer().get()
|
||||
: nullptr;
|
||||
_searchInHistoryRequest = histories.sendRequest(history, type, [=](Fn<void()> finish) {
|
||||
const auto type = _lastSearchId
|
||||
? SearchRequestType::PeerFromOffset
|
||||
|
@ -2012,16 +2027,15 @@ void Widget::searchMore() {
|
|||
using Flag = MTPmessages_Search::Flag;
|
||||
_searchRequest = session().api().request(MTPmessages_Search(
|
||||
MTP_flags((topic ? Flag::f_top_msg_id : Flag())
|
||||
| (_searchQueryFrom ? Flag::f_from_id : Flag())
|
||||
| (fromPeer ? Flag::f_from_id : Flag())
|
||||
| (savedPeer ? Flag::f_saved_peer_id : Flag())
|
||||
| (_searchQueryTags.empty()
|
||||
? Flag()
|
||||
: Flag::f_saved_reaction)),
|
||||
peer->input,
|
||||
MTP_string(_searchQuery),
|
||||
(_searchQueryFrom
|
||||
? _searchQueryFrom->input
|
||||
: MTP_inputPeerEmpty()),
|
||||
MTPInputPeer(), // saved_peer_id
|
||||
(fromPeer ? fromPeer->input : MTP_inputPeerEmpty()),
|
||||
(savedPeer ? savedPeer->input : MTP_inputPeerEmpty()),
|
||||
MTP_vector_from_range(
|
||||
_searchQueryTags | ranges::views::transform(
|
||||
Data::ReactionToMTP
|
||||
|
@ -2590,6 +2604,7 @@ bool Widget::setSearchInChat(Key chat, PeerData *from) {
|
|||
}
|
||||
const auto peer = chat.peer();
|
||||
const auto topic = chat.topic();
|
||||
const auto sublist = chat.sublist();
|
||||
const auto forum = peer ? peer->forum() : nullptr;
|
||||
if (chat.folder() || (forum && !topic)) {
|
||||
chat = Key();
|
||||
|
@ -3083,6 +3098,8 @@ void Widget::cancelSearchRequest() {
|
|||
PeerData *Widget::searchInPeer() const {
|
||||
return _openedForum
|
||||
? _openedForum->channel().get()
|
||||
: _searchInChat.sublist()
|
||||
? session().user().get()
|
||||
: _searchInChat.peer();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/history_view_sublist_section.h"
|
||||
|
||||
#include "main/main_session.h"
|
||||
#include "core/application.h"
|
||||
#include "core/shortcuts.h"
|
||||
#include "data/data_saved_messages.h"
|
||||
#include "data/data_saved_sublist.h"
|
||||
#include "data/data_session.h"
|
||||
|
@ -19,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "mainwidget.h"
|
||||
#include "ui/chat/chat_style.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
|
@ -115,6 +118,10 @@ SublistWidget::SublistWidget(
|
|||
) | rpl::start_with_next([=] {
|
||||
clearSelected();
|
||||
}, _topBar->lifetime());
|
||||
_topBar->searchRequest(
|
||||
) | rpl::start_with_next([=] {
|
||||
searchInSublist();
|
||||
}, _topBar->lifetime());
|
||||
|
||||
_translateBar->raise();
|
||||
_topBarShadow->raise();
|
||||
|
@ -134,6 +141,7 @@ SublistWidget::SublistWidget(
|
|||
onScroll();
|
||||
}, lifetime());
|
||||
|
||||
setupShortcuts();
|
||||
setupTranslateBar();
|
||||
}
|
||||
|
||||
|
@ -658,4 +666,24 @@ void SublistWidget::clearSelected() {
|
|||
_inner->cancelSelection();
|
||||
}
|
||||
|
||||
void SublistWidget::setupShortcuts() {
|
||||
Shortcuts::Requests(
|
||||
) | rpl::filter([=] {
|
||||
return Ui::AppInFocus()
|
||||
&& Ui::InFocusChain(this)
|
||||
&& !controller()->isLayerShown()
|
||||
&& (Core::App().activeWindow() == &controller()->window());
|
||||
}) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
|
||||
using Command = Shortcuts::Command;
|
||||
request->check(Command::Search, 1) && request->handle([=] {
|
||||
searchInSublist();
|
||||
return true;
|
||||
});
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void SublistWidget::searchInSublist() {
|
||||
controller()->content()->searchInChat(_sublist);
|
||||
}
|
||||
|
||||
} // namespace HistoryView
|
||||
|
|
|
@ -167,11 +167,13 @@ private:
|
|||
void setupOpenChatButton();
|
||||
void setupAboutHiddenAuthor();
|
||||
void setupTranslateBar();
|
||||
void setupShortcuts();
|
||||
|
||||
void confirmDeleteSelected();
|
||||
void confirmForwardSelected();
|
||||
void clearSelected();
|
||||
void recountChatWidth();
|
||||
void searchInSublist();
|
||||
|
||||
const not_null<Data::SavedSublist*> _sublist;
|
||||
const not_null<History*> _history;
|
||||
|
|
|
@ -928,7 +928,9 @@ int TopBarWidget::countSelectedButtonsTop(float64 selectedShown) {
|
|||
void TopBarWidget::updateSearchVisibility() {
|
||||
const auto searchAllowedMode = (_activeChat.section == Section::History)
|
||||
|| (_activeChat.section == Section::Replies
|
||||
&& _activeChat.key.topic());
|
||||
&& _activeChat.key.topic())
|
||||
|| (_activeChat.section == Section::SavedSublist
|
||||
&& _activeChat.key.sublist());
|
||||
_search->setVisible(searchAllowedMode && !_chooseForReportReason);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue