2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-22 18:27:17 +00:00
tdesktop/Telegram/SourceFiles/dialogs/ui/dialogs_suggestions.h

301 lines
8.2 KiB
C
Raw Normal View History

2024-04-09 19:04:18 +04: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
*/
#pragma once
#include "base/object_ptr.h"
#include "base/timer.h"
2024-04-09 19:04:18 +04:00
#include "dialogs/ui/top_peers_strip.h"
#include "ui/controls/swipe_handler_data.h"
2024-04-12 19:18:07 +04:00
#include "ui/effects/animations.h"
2024-04-09 19:04:18 +04:00
#include "ui/rp_widget.h"
2024-07-25 16:09:46 +02:00
class PeerListContent;
namespace Data {
class Thread;
} // namespace Data
2024-12-17 21:16:38 +04:00
namespace Info {
class WrapWidget;
} // namespace Info
2024-04-09 19:04:18 +04:00
namespace Main {
class Session;
} // namespace Main
2024-12-17 21:16:38 +04:00
namespace Storage {
enum class SharedMediaType : signed char;
} // namespace Storage
namespace Ui::Controls {
struct SwipeHandlerArgs;
} // namespace Ui::Controls
namespace Ui {
class BoxContent;
class ScrollArea;
2024-04-09 19:04:18 +04:00
class ElasticScroll;
class SettingsSlider;
2024-04-09 19:04:18 +04:00
class VerticalLayout;
template <typename Widget>
class SlideWrap;
} // namespace Ui
2024-04-11 13:12:57 +04:00
namespace Window {
class SessionController;
} // namespace Window
2024-04-09 19:04:18 +04:00
namespace Dialogs {
class InnerWidget;
class PostsSearch;
class PostsSearchIntro;
struct PostsSearchIntroState;
enum class SearchEmptyIcon;
2024-04-12 12:25:37 +04:00
struct RecentPeersList {
std::vector<not_null<PeerData*>> list;
};
2024-04-09 19:04:18 +04:00
class Suggestions final : public Ui::RpWidget {
public:
Suggestions(
not_null<QWidget*> parent,
2024-04-11 13:12:57 +04:00
not_null<Window::SessionController*> controller,
2024-04-12 12:25:37 +04:00
rpl::producer<TopPeersList> topPeers,
RecentPeersList recentPeers);
2024-04-09 19:04:18 +04:00
~Suggestions();
void selectJump(Qt::Key direction, int pageSize = 0);
2024-04-11 13:55:38 +04:00
void chooseRow();
bool consumeSearchQuery(const QString &query);
[[nodiscard]] rpl::producer<> clearSearchQueryRequests() const;
[[nodiscard]] Data::Thread *updateFromParentDrag(QPoint globalPosition);
void dragLeft();
2024-04-12 19:18:07 +04:00
void show(anim::type animated, Fn<void()> finish);
void hide(anim::type animated, Fn<void()> finish);
[[nodiscard]] float64 shownOpacity() const;
2024-04-19 16:10:42 +04:00
[[nodiscard]] bool persist() const;
void clearPersistance();
2024-04-12 12:25:37 +04:00
[[nodiscard]] rpl::producer<not_null<PeerData*>> topPeerChosen() const {
2024-04-09 19:04:18 +04:00
return _topPeerChosen.events();
}
[[nodiscard]] auto recentPeerChosen() const
-> rpl::producer<not_null<PeerData*>> {
2024-07-25 16:09:46 +02:00
return _recent->chosen.events();
2024-04-12 12:25:37 +04:00
}
[[nodiscard]] auto myChannelChosen() const
-> rpl::producer<not_null<PeerData*>> {
2024-07-25 16:09:46 +02:00
return _myChannels->chosen.events();
}
[[nodiscard]] auto recommendationChosen() const
-> rpl::producer<not_null<PeerData*>> {
2024-07-25 16:09:46 +02:00
return _recommendations->chosen.events();
}
2024-07-25 18:08:22 +02:00
[[nodiscard]] auto recentAppChosen() const
-> rpl::producer<not_null<PeerData*>> {
return _recentApps->chosen.events();
}
[[nodiscard]] auto popularAppChosen() const
-> rpl::producer<not_null<PeerData*>> {
return _popularApps->chosen.events();
}
[[nodiscard]] auto openBotMainAppRequests() const
-> rpl::producer<not_null<PeerData*>> {
return _openBotMainAppRequests.events();
}
2024-04-09 19:04:18 +04:00
2024-07-25 16:09:46 +02:00
class ObjectListController;
2024-04-09 19:04:18 +04:00
private:
2024-12-17 21:16:38 +04:00
using MediaType = Storage::SharedMediaType;
enum class Tab : uchar {
Chats,
Channels,
2024-07-25 18:08:22 +02:00
Apps,
Posts,
2024-12-17 21:16:38 +04:00
Media,
Downloads,
};
enum class JumpResult : uchar {
NotApplied,
Applied,
AppliedAndOut,
};
2024-12-17 21:16:38 +04:00
struct Key {
Tab tab = Tab::Chats;
MediaType mediaType = {};
friend inline auto operator<=>(Key, Key) = default;
friend inline bool operator==(Key, Key) = default;
};
2024-07-25 16:09:46 +02:00
struct ObjectList {
not_null<Ui::SlideWrap<PeerListContent>*> wrap;
rpl::variable<int> count;
Fn<bool()> choose;
Fn<JumpResult(Qt::Key, int)> selectJump;
Fn<uint64(QPoint)> updateFromParentDrag;
Fn<void()> dragLeft;
Fn<bool(not_null<QTouchEvent*>)> processTouch;
rpl::event_stream<not_null<PeerData*>> chosen;
};
2024-12-17 21:16:38 +04:00
struct MediaList {
Info::WrapWidget *wrap = nullptr;
rpl::variable<int> count;
};
[[nodiscard]] static std::vector<Key> TabKeysFor(
not_null<Window::SessionController*> controller);
2024-04-09 19:04:18 +04:00
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void setupTabs();
void setupChats();
void setupChannels();
2024-07-25 18:08:22 +02:00
void setupApps();
void reinstallSwipe(not_null<Ui::ElasticScroll*>);
[[nodiscard]] auto generateIncompleteSwipeArgs()
-> Ui::Controls::SwipeHandlerArgs;
void selectJumpChats(Qt::Key direction, int pageSize);
void selectJumpChannels(Qt::Key direction, int pageSize);
2024-07-25 18:08:22 +02:00
void selectJumpApps(Qt::Key direction, int pageSize);
[[nodiscard]] Data::Thread *updateFromChatsDrag(QPoint globalPosition);
[[nodiscard]] Data::Thread *updateFromChannelsDrag(
QPoint globalPosition);
2024-07-25 18:08:22 +02:00
[[nodiscard]] Data::Thread *updateFromAppsDrag(QPoint globalPosition);
[[nodiscard]] Data::Thread *fromListId(uint64 peerListRowId);
2024-07-25 16:09:46 +02:00
[[nodiscard]] std::unique_ptr<ObjectList> setupRecentPeers(
2024-04-12 12:25:37 +04:00
RecentPeersList recentPeers);
2024-07-25 16:09:46 +02:00
[[nodiscard]] auto setupEmptyRecent()
-> object_ptr<Ui::SlideWrap<Ui::RpWidget>>;
2024-07-25 16:09:46 +02:00
[[nodiscard]] std::unique_ptr<ObjectList> setupMyChannels();
[[nodiscard]] std::unique_ptr<ObjectList> setupRecommendations();
[[nodiscard]] auto setupEmptyChannels()
-> object_ptr<Ui::SlideWrap<Ui::RpWidget>>;
2024-07-25 16:09:46 +02:00
2024-07-25 18:08:22 +02:00
[[nodiscard]] std::unique_ptr<ObjectList> setupRecentApps();
[[nodiscard]] std::unique_ptr<ObjectList> setupPopularApps();
2024-07-25 16:09:46 +02:00
[[nodiscard]] std::unique_ptr<ObjectList> setupObjectList(
not_null<Ui::ElasticScroll*> scroll,
not_null<Ui::VerticalLayout*> parent,
not_null<ObjectListController*> controller,
Fn<int()> addToScroll = nullptr);
[[nodiscard]] object_ptr<Ui::SlideWrap<Ui::RpWidget>> setupEmpty(
not_null<QWidget*> parent,
SearchEmptyIcon icon,
rpl::producer<QString> text);
2024-12-17 21:16:38 +04:00
void switchTab(Key key);
void startShownAnimation(bool shown, Fn<void()> finish);
2024-12-17 21:16:38 +04:00
void startSlideAnimation(Key was, Key now);
void ensureContent(Key key);
void finishShow();
void handlePressForChatPreview(PeerId id, Fn<void(bool)> callback);
2024-12-17 21:16:38 +04:00
void updateControlsGeometry();
void applySearchQuery();
2024-05-31 15:01:43 +04:00
void setupPostsSearch();
void setPostsSearchQuery(const QString &query);
void setupPostsResults();
void setupPostsIntro(const PostsSearchIntroState &intro);
const not_null<Window::SessionController*> _controller;
2024-04-09 19:04:18 +04:00
const std::unique_ptr<Ui::ScrollArea> _tabsScroll;
const not_null<Ui::SettingsSlider*> _tabs;
Ui::Animations::Simple _tabsScrollAnimation;
2024-12-17 21:16:38 +04:00
const std::vector<Key> _tabKeys;
rpl::variable<Key> _key;
const std::unique_ptr<Ui::ElasticScroll> _chatsScroll;
const not_null<Ui::VerticalLayout*> _chatsContent;
2024-07-25 16:09:46 +02:00
2024-04-09 19:04:18 +04:00
const not_null<Ui::SlideWrap<TopPeersStrip>*> _topPeersWrap;
const not_null<TopPeersStrip*> _topPeers;
2024-07-25 16:09:46 +02:00
rpl::event_stream<not_null<PeerData*>> _topPeerChosen;
rpl::event_stream<not_null<PeerData*>> _openBotMainAppRequests;
2024-07-25 16:09:46 +02:00
const std::unique_ptr<ObjectList> _recent;
2024-04-09 19:04:18 +04:00
2024-04-12 12:25:37 +04:00
const not_null<Ui::SlideWrap<Ui::RpWidget>*> _emptyRecent;
const std::unique_ptr<Ui::ElasticScroll> _channelsScroll;
const not_null<Ui::VerticalLayout*> _channelsContent;
2024-07-25 16:09:46 +02:00
const std::unique_ptr<ObjectList> _myChannels;
const std::unique_ptr<ObjectList> _recommendations;
const not_null<Ui::SlideWrap<Ui::RpWidget>*> _emptyChannels;
2024-07-25 18:08:22 +02:00
const std::unique_ptr<Ui::ElasticScroll> _appsScroll;
const not_null<Ui::VerticalLayout*> _appsContent;
std::unique_ptr<PostsSearch> _postsSearch;
const std::unique_ptr<Ui::ElasticScroll> _postsScroll;
const not_null<Ui::RpWidget*> _postsWrap;
PostsSearchIntro *_postsSearchIntro = nullptr;
InnerWidget *_postsContent = nullptr;
rpl::producer<> _recentAppsRefreshed;
Fn<bool(not_null<PeerData*>)> _recentAppsShows;
2024-07-25 18:08:22 +02:00
const std::unique_ptr<ObjectList> _recentApps;
const std::unique_ptr<ObjectList> _popularApps;
2024-12-17 21:16:38 +04:00
base::flat_map<Key, MediaList> _mediaLists;
rpl::event_stream<> _clearSearchQueryRequests;
QString _searchQuery;
base::Timer _searchQueryTimer;
2024-12-17 21:16:38 +04:00
2024-04-12 19:18:07 +04:00
Ui::Animations::Simple _shownAnimation;
Fn<void()> _showFinished;
bool _hidden = false;
2024-04-19 16:10:42 +04:00
bool _persist = false;
2024-04-12 19:18:07 +04:00
QPixmap _cache;
Ui::Animations::Simple _slideAnimation;
QPixmap _slideLeft;
QPixmap _slideRight;
Ui::Controls::SwipeBackResult _swipeBackData;
rpl::lifetime _swipeLifetime;
2024-07-25 18:08:22 +02:00
int _slideLeftTop = 0;
int _slideRightTop = 0;
2024-04-09 19:04:18 +04:00
};
2024-04-11 12:41:32 +04:00
[[nodiscard]] rpl::producer<TopPeersList> TopPeersContent(
2024-04-09 19:04:18 +04:00
not_null<Main::Session*> session);
2024-04-12 12:25:37 +04:00
[[nodiscard]] RecentPeersList RecentPeersContent(
not_null<Main::Session*> session);
[[nodiscard]] object_ptr<Ui::BoxContent> StarsExamplesBox(
not_null<Window::SessionController*> window);
2024-10-17 11:29:34 +04:00
[[nodiscard]] object_ptr<Ui::BoxContent> PopularAppsAboutBox(
not_null<Window::SessionController*> window);
2024-04-09 19:04:18 +04:00
} // namespace Dialogs