dialogs_search_from_controllers.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_search_from_controllers.h"
  8. #include "lang/lang_keys.h"
  9. #include "data/data_peer_values.h"
  10. #include "data/data_channel.h"
  11. #include "data/data_chat.h"
  12. #include "data/data_user.h"
  13. #include "main/main_session.h"
  14. #include "apiwrap.h"
  15. namespace Dialogs {
  16. object_ptr<Ui::BoxContent> SearchFromBox(
  17. not_null<PeerData*> peer,
  18. Fn<void(not_null<PeerData*>)> callback,
  19. Fn<void()> closedCallback) {
  20. auto createController = [
  21. peer,
  22. callback = std::move(callback)
  23. ]() -> std::unique_ptr<PeerListController> {
  24. if (peer && (peer->isChat() || peer->isMegagroup())) {
  25. return std::make_unique<Dialogs::SearchFromController>(
  26. peer,
  27. std::move(callback));
  28. }
  29. return nullptr;
  30. };
  31. if (auto controller = createController()) {
  32. auto subscription = std::make_shared<rpl::lifetime>();
  33. auto box = Box<PeerListBox>(
  34. std::move(controller),
  35. [subscription](not_null<PeerListBox*> box) {
  36. box->addButton(tr::lng_cancel(), [box, subscription] {
  37. box->closeBox();
  38. });
  39. });
  40. box->boxClosing() | rpl::start_with_next(
  41. std::move(closedCallback),
  42. *subscription);
  43. return box;
  44. }
  45. return nullptr;
  46. }
  47. SearchFromController::SearchFromController(
  48. not_null<PeerData*> peer,
  49. Fn<void(not_null<PeerData*>)> callback)
  50. : AddSpecialBoxController(
  51. peer,
  52. ParticipantsBoxController::Role::Members,
  53. AdminDoneCallback(),
  54. BannedDoneCallback())
  55. , _callback(std::move(callback)) {
  56. _excludeSelf = false;
  57. }
  58. void SearchFromController::prepare() {
  59. AddSpecialBoxController::prepare();
  60. delegate()->peerListSetTitle(tr::lng_search_messages_from());
  61. if (const auto megagroup = peer()->asMegagroup()) {
  62. if (!delegate()->peerListFindRow(megagroup->id.value)) {
  63. delegate()->peerListAppendRow(
  64. std::make_unique<PeerListRow>(megagroup));
  65. setDescriptionText({});
  66. delegate()->peerListRefreshRows();
  67. }
  68. }
  69. }
  70. void SearchFromController::rowClicked(not_null<PeerListRow*> row) {
  71. if (const auto onstack = base::duplicate(_callback)) {
  72. onstack(row->peer());
  73. }
  74. }
  75. } // namespace Dialogs