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