2018-01-04 19:54:35 +00:00
|
|
|
/*
|
|
|
|
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 "dialogs/dialogs_key.h"
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
#include "data/data_folder.h"
|
2022-09-20 18:12:30 +00:00
|
|
|
#include "data/data_forum_topic.h"
|
2023-12-27 01:09:20 +00:00
|
|
|
#include "data/data_saved_sublist.h"
|
2024-06-05 06:42:20 +00:00
|
|
|
#include "dialogs/ui/chat_search_in.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2018-01-04 19:54:35 +00:00
|
|
|
|
|
|
|
namespace Dialogs {
|
|
|
|
|
2020-06-12 14:09:04 +00:00
|
|
|
Key::Key(History *history) : _value(history) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Key::Key(Data::Folder *folder) : _value(folder) {
|
|
|
|
}
|
|
|
|
|
2022-10-17 16:29:48 +00:00
|
|
|
Key::Key(Data::Thread *thread) : _value(thread) {
|
|
|
|
}
|
|
|
|
|
2022-09-23 19:21:31 +00:00
|
|
|
Key::Key(Data::ForumTopic *topic) : _value(topic) {
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
2023-12-27 01:09:20 +00:00
|
|
|
Key::Key(Data::SavedSublist *sublist) : _value(sublist) {
|
|
|
|
}
|
|
|
|
|
2020-06-12 14:09:04 +00:00
|
|
|
Key::Key(not_null<History*> history) : _value(history) {
|
|
|
|
}
|
|
|
|
|
2022-10-17 16:29:48 +00:00
|
|
|
Key::Key(not_null<Data::Thread*> thread) : _value(thread) {
|
|
|
|
}
|
|
|
|
|
2020-06-12 14:09:04 +00:00
|
|
|
Key::Key(not_null<Data::Folder*> folder) : _value(folder) {
|
|
|
|
}
|
|
|
|
|
2022-09-23 19:21:31 +00:00
|
|
|
Key::Key(not_null<Data::ForumTopic*> topic) : _value(topic) {
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
2023-12-27 01:09:20 +00:00
|
|
|
Key::Key(not_null<Data::SavedSublist*> sublist) : _value(sublist) {
|
|
|
|
}
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
not_null<Entry*> Key::entry() const {
|
2020-06-12 14:09:04 +00:00
|
|
|
Expects(_value != nullptr);
|
|
|
|
|
|
|
|
return _value;
|
2018-01-04 19:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
History *Key::history() const {
|
2020-06-12 14:09:04 +00:00
|
|
|
return _value ? _value->asHistory() : nullptr;
|
2018-01-04 19:54:35 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 10:32:03 +00:00
|
|
|
Data::Folder *Key::folder() const {
|
2020-06-12 14:09:04 +00:00
|
|
|
return _value ? _value->asFolder() : nullptr;
|
2018-01-04 19:54:35 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 10:32:03 +00:00
|
|
|
Data::ForumTopic *Key::topic() const {
|
2022-09-23 19:21:31 +00:00
|
|
|
return _value ? _value->asTopic() : nullptr;
|
2022-09-20 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 10:32:03 +00:00
|
|
|
Data::Thread *Key::thread() const {
|
|
|
|
return _value ? _value->asThread() : nullptr;
|
|
|
|
}
|
|
|
|
|
2023-12-27 01:09:20 +00:00
|
|
|
Data::SavedSublist *Key::sublist() const {
|
|
|
|
return _value ? _value->asSublist() : nullptr;
|
|
|
|
}
|
|
|
|
|
2022-10-13 17:34:04 +00:00
|
|
|
History *Key::owningHistory() const {
|
|
|
|
if (const auto thread = this->thread()) {
|
|
|
|
return thread->owningHistory();
|
2022-09-27 12:05:47 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-22 16:42:25 +00:00
|
|
|
PeerData *Key::peer() const {
|
2022-10-13 17:34:04 +00:00
|
|
|
if (const auto history = owningHistory()) {
|
2020-06-12 14:09:04 +00:00
|
|
|
return history->peer;
|
2018-01-22 16:42:25 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2024-05-17 10:56:56 +00:00
|
|
|
[[nodiscard]] bool SearchState::empty() const {
|
|
|
|
return !inChat
|
2024-05-21 09:16:08 +00:00
|
|
|
&& tags.empty()
|
2024-05-17 10:56:56 +00:00
|
|
|
&& QStringView(query).trimmed().isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
ChatSearchTab SearchState::defaultTabForMe() const {
|
|
|
|
return inChat.topic()
|
|
|
|
? ChatSearchTab::ThisTopic
|
2024-05-20 13:38:18 +00:00
|
|
|
: (inChat.history() || inChat.sublist())
|
2024-05-17 10:56:56 +00:00
|
|
|
? ChatSearchTab::ThisPeer
|
|
|
|
: ChatSearchTab::MyMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchState::filterChatsList() const {
|
2024-07-02 05:53:56 +00:00
|
|
|
using Tab = ChatSearchTab;
|
|
|
|
return !inChat // ThisPeer can be in opened forum.
|
|
|
|
&& (tab == Tab::MyMessages || tab == Tab::ThisPeer);
|
2024-05-17 10:56:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 19:54:35 +00:00
|
|
|
} // namespace Dialogs
|