dialogs_key.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "dialogs/dialogs_key.h"
  8. #include "data/data_folder.h"
  9. #include "data/data_forum_topic.h"
  10. #include "data/data_saved_sublist.h"
  11. #include "dialogs/ui/chat_search_in.h"
  12. #include "history/history.h"
  13. namespace Dialogs {
  14. Key::Key(History *history) : _value(history) {
  15. }
  16. Key::Key(Data::Folder *folder) : _value(folder) {
  17. }
  18. Key::Key(Data::Thread *thread) : _value(thread) {
  19. }
  20. Key::Key(Data::ForumTopic *topic) : _value(topic) {
  21. }
  22. Key::Key(Data::SavedSublist *sublist) : _value(sublist) {
  23. }
  24. Key::Key(not_null<History*> history) : _value(history) {
  25. }
  26. Key::Key(not_null<Data::Thread*> thread) : _value(thread) {
  27. }
  28. Key::Key(not_null<Data::Folder*> folder) : _value(folder) {
  29. }
  30. Key::Key(not_null<Data::ForumTopic*> topic) : _value(topic) {
  31. }
  32. Key::Key(not_null<Data::SavedSublist*> sublist) : _value(sublist) {
  33. }
  34. not_null<Entry*> Key::entry() const {
  35. Expects(_value != nullptr);
  36. return _value;
  37. }
  38. History *Key::history() const {
  39. return _value ? _value->asHistory() : nullptr;
  40. }
  41. Data::Folder *Key::folder() const {
  42. return _value ? _value->asFolder() : nullptr;
  43. }
  44. Data::ForumTopic *Key::topic() const {
  45. return _value ? _value->asTopic() : nullptr;
  46. }
  47. Data::Thread *Key::thread() const {
  48. return _value ? _value->asThread() : nullptr;
  49. }
  50. Data::SavedSublist *Key::sublist() const {
  51. return _value ? _value->asSublist() : nullptr;
  52. }
  53. History *Key::owningHistory() const {
  54. if (const auto thread = this->thread()) {
  55. return thread->owningHistory();
  56. }
  57. return nullptr;
  58. }
  59. PeerData *Key::peer() const {
  60. if (const auto history = owningHistory()) {
  61. return history->peer;
  62. }
  63. return nullptr;
  64. }
  65. [[nodiscard]] bool SearchState::empty() const {
  66. return !inChat
  67. && tags.empty()
  68. && QStringView(query).trimmed().isEmpty();
  69. }
  70. ChatSearchTab SearchState::defaultTabForMe() const {
  71. return inChat.topic()
  72. ? ChatSearchTab::ThisTopic
  73. : (inChat.history() || inChat.sublist())
  74. ? ChatSearchTab::ThisPeer
  75. : ChatSearchTab::MyMessages;
  76. }
  77. bool SearchState::filterChatsList() const {
  78. using Tab = ChatSearchTab;
  79. return !inChat // ThisPeer can be in opened forum.
  80. && (tab == Tab::MyMessages || tab == Tab::ThisPeer);
  81. }
  82. } // namespace Dialogs