2017-08-01 12:01:42 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-08-01 12:01:42 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
#include "base/timer.h"
|
2019-08-06 14:43:26 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2017-08-01 12:01:42 +00:00
|
|
|
#include "window/section_widget.h"
|
2019-04-02 09:13:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2017-08-01 12:01:42 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2019-04-05 08:28:07 +00:00
|
|
|
#include "ui/special_buttons.h"
|
2020-07-02 07:13:50 +00:00
|
|
|
#include "mtproto/sender.h"
|
2019-08-06 14:43:26 +00:00
|
|
|
#include "api/api_single_message_search.h"
|
2020-06-11 16:09:46 +00:00
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
namespace MTP {
|
|
|
|
class Error;
|
|
|
|
} // namespace MTP
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2022-11-30 06:31:33 +00:00
|
|
|
namespace Data {
|
|
|
|
class Forum;
|
|
|
|
} // namespace Data
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2019-04-24 14:12:35 +00:00
|
|
|
namespace HistoryView {
|
|
|
|
class TopBarWidget;
|
2022-10-21 14:10:56 +00:00
|
|
|
class ContactStatus;
|
2019-04-24 14:12:35 +00:00
|
|
|
} // namespace HistoryView
|
|
|
|
|
2017-08-01 12:01:42 +00:00
|
|
|
namespace Ui {
|
|
|
|
class IconButton;
|
|
|
|
class PopupMenu;
|
|
|
|
class DropdownMenu;
|
|
|
|
class FlatButton;
|
2022-10-20 13:42:50 +00:00
|
|
|
class InputField;
|
2017-08-01 12:01:42 +00:00
|
|
|
class CrossButton;
|
2022-10-21 14:10:56 +00:00
|
|
|
class PlainShadow;
|
2022-02-22 13:58:55 +00:00
|
|
|
class DownloadBar;
|
2022-10-21 14:10:56 +00:00
|
|
|
class GroupCallBar;
|
|
|
|
class RequestsBar;
|
2017-08-01 12:01:42 +00:00
|
|
|
template <typename Widget>
|
2017-09-30 18:26:45 +00:00
|
|
|
class FadeWrapScaled;
|
2017-08-01 12:01:42 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
namespace Window {
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2019-02-10 16:29:55 +00:00
|
|
|
class ConnectionState;
|
2022-11-30 06:31:33 +00:00
|
|
|
struct SectionShow;
|
2017-08-01 12:01:42 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
namespace Dialogs {
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
struct RowDescriptor;
|
|
|
|
class Row;
|
|
|
|
class FakeRow;
|
|
|
|
class Key;
|
|
|
|
struct ChosenRow;
|
|
|
|
class InnerWidget;
|
|
|
|
enum class SearchRequestType;
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
class Widget final : public Window::AbstractSectionWidget {
|
2017-08-01 12:01:42 +00:00
|
|
|
public:
|
2022-11-30 06:31:33 +00:00
|
|
|
enum class Layout {
|
|
|
|
Main,
|
|
|
|
Child,
|
|
|
|
};
|
|
|
|
Widget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
Layout layout);
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2020-06-11 09:41:03 +00:00
|
|
|
// When resizing the widget with top edge moved up or down and we
|
|
|
|
// want to add this top movement to the scroll position, so inner
|
|
|
|
// content will not move.
|
|
|
|
void setGeometryWithTopMoved(const QRect &newGeometry, int topDelta);
|
|
|
|
|
2017-08-01 12:01:42 +00:00
|
|
|
void updateDragInScroll(bool inScroll);
|
|
|
|
|
2022-11-30 06:31:33 +00:00
|
|
|
void showForum(
|
|
|
|
not_null<Data::Forum*> forum,
|
|
|
|
const Window::SectionShow ¶ms);
|
2019-04-24 10:15:10 +00:00
|
|
|
void searchInChat(Key chat);
|
2019-04-24 14:12:35 +00:00
|
|
|
void setInnerFocus();
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2022-10-06 15:11:00 +00:00
|
|
|
void jumpToTop(bool belowPinned = false);
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
void startWidthAnimation();
|
|
|
|
void stopWidthAnimation();
|
|
|
|
|
|
|
|
bool hasTopBarShadow() const {
|
|
|
|
return true;
|
|
|
|
}
|
2022-11-30 06:31:33 +00:00
|
|
|
void showAnimated(
|
|
|
|
Window::SlideDirection direction,
|
|
|
|
const Window::SectionSlideParams ¶ms);
|
2017-08-01 12:01:42 +00:00
|
|
|
void showFast();
|
2022-12-01 13:48:33 +00:00
|
|
|
[[nodiscard]] rpl::producer<float64> shownProgressValue() const;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void scrollToEntry(const RowDescriptor &entry);
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void searchMessages(const QString &query, Key inChat = {});
|
2022-10-26 14:18:00 +00:00
|
|
|
void searchTopics();
|
2022-03-14 15:48:39 +00:00
|
|
|
void searchMore();
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2022-02-05 15:15:24 +00:00
|
|
|
[[nodiscard]] RowDescriptor resolveChatNext(RowDescriptor from = {}) const;
|
|
|
|
[[nodiscard]] RowDescriptor resolveChatPrevious(RowDescriptor from = {}) const;
|
|
|
|
|
2017-08-01 12:01:42 +00:00
|
|
|
// Float player interface.
|
2020-06-25 14:17:37 +00:00
|
|
|
bool floatPlayerHandleWheelEvent(QEvent *e) override;
|
|
|
|
QRect floatPlayerAvailableRect() override;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
bool cancelSearch();
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
~Widget();
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void dragEnterEvent(QDragEnterEvent *e) override;
|
|
|
|
void dragMoveEvent(QDragMoveEvent *e) override;
|
|
|
|
void dragLeaveEvent(QDragLeaveEvent *e) override;
|
|
|
|
void dropEvent(QDropEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2022-09-26 13:37:32 +00:00
|
|
|
void chosenRow(const ChosenRow &row);
|
2022-03-14 15:48:39 +00:00
|
|
|
void listScrollUpdated();
|
|
|
|
void cancelSearchInChat();
|
2022-10-20 13:42:50 +00:00
|
|
|
void filterCursorMoved();
|
2022-03-14 15:48:39 +00:00
|
|
|
void completeHashtag(QString tag);
|
|
|
|
|
2022-10-26 09:30:10 +00:00
|
|
|
[[nodiscard]] QString currentSearchQuery() const;
|
|
|
|
void clearSearchField();
|
2022-03-14 15:48:39 +00:00
|
|
|
bool searchMessages(bool searchCache = false);
|
|
|
|
void needSearchMessages();
|
|
|
|
|
2022-12-01 10:14:35 +00:00
|
|
|
void slideFinished();
|
2018-01-22 10:58:11 +00:00
|
|
|
void searchReceived(
|
2019-04-24 10:15:10 +00:00
|
|
|
SearchRequestType type,
|
2018-01-22 10:58:11 +00:00
|
|
|
const MTPmessages_Messages &result,
|
|
|
|
mtpRequestId requestId);
|
|
|
|
void peerSearchReceived(
|
|
|
|
const MTPcontacts_Found &result,
|
|
|
|
mtpRequestId requestId);
|
2019-05-01 12:09:16 +00:00
|
|
|
void escape();
|
2022-10-26 09:30:10 +00:00
|
|
|
void submit();
|
2020-02-21 12:57:06 +00:00
|
|
|
void cancelSearchRequest();
|
2022-10-26 09:30:10 +00:00
|
|
|
[[nodiscard]] PeerData *searchInPeer() const;
|
|
|
|
[[nodiscard]] Data::ForumTopic *searchInTopic() const;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2018-12-30 08:40:25 +00:00
|
|
|
void setupSupportMode();
|
2018-05-07 17:44:33 +00:00
|
|
|
void setupConnectingWidget();
|
2020-07-24 05:41:51 +00:00
|
|
|
void setupMainMenuToggle();
|
2022-02-22 13:58:55 +00:00
|
|
|
void setupDownloadBar();
|
2022-10-26 09:30:10 +00:00
|
|
|
void setupShortcuts();
|
2022-10-26 14:18:00 +00:00
|
|
|
[[nodiscard]] bool searchForPeersRequired(const QString &query) const;
|
|
|
|
[[nodiscard]] bool searchForTopicsRequired(const QString &query) const;
|
2022-11-30 06:31:33 +00:00
|
|
|
bool setSearchInChat(Key chat, PeerData *from = nullptr);
|
2021-11-16 07:26:35 +00:00
|
|
|
void showCalendar();
|
2017-08-01 12:01:42 +00:00
|
|
|
void showSearchFrom();
|
|
|
|
void showMainMenu();
|
2017-08-01 15:55:51 +00:00
|
|
|
void clearSearchCache();
|
2019-04-24 10:15:10 +00:00
|
|
|
void updateControlsVisibility(bool fast = false);
|
2017-08-01 12:01:42 +00:00
|
|
|
void updateLockUnlockVisibility();
|
2019-04-24 10:15:10 +00:00
|
|
|
void updateLoadMoreChatsVisibility();
|
2017-08-01 12:01:42 +00:00
|
|
|
void updateJumpToDateVisibility(bool fast = false);
|
2017-08-01 15:55:51 +00:00
|
|
|
void updateSearchFromVisibility(bool fast = false);
|
2017-08-01 12:01:42 +00:00
|
|
|
void updateControlsGeometry();
|
2022-10-21 14:10:56 +00:00
|
|
|
void refreshTopBars();
|
2022-10-27 09:22:31 +00:00
|
|
|
void showSearchInTopBar(anim::type animated);
|
2018-04-26 16:14:21 +00:00
|
|
|
void checkUpdateStatus();
|
2022-09-20 09:35:47 +00:00
|
|
|
void changeOpenedSubsection(
|
|
|
|
FnMut<void()> change,
|
|
|
|
bool fromRight,
|
|
|
|
anim::type animated);
|
2019-04-24 10:15:10 +00:00
|
|
|
void changeOpenedFolder(Data::Folder *folder, anim::type animated);
|
2022-11-30 06:31:33 +00:00
|
|
|
void changeOpenedForum(Data::Forum *forum, anim::type animated);
|
|
|
|
void hideChildList();
|
|
|
|
[[nodiscard]] QPixmap grabForFolderSlideAnimation();
|
2022-12-01 10:14:35 +00:00
|
|
|
void startSlideAnimation(
|
|
|
|
QPixmap oldContentCache,
|
|
|
|
QPixmap newContentCache,
|
|
|
|
Window::SlideDirection direction);
|
2018-04-26 16:14:21 +00:00
|
|
|
|
2022-12-01 13:48:33 +00:00
|
|
|
void openChildList(
|
|
|
|
not_null<Data::Forum*> forum,
|
|
|
|
const Window::SectionShow ¶ms);
|
|
|
|
void closeChildList(anim::type animated);
|
|
|
|
|
2019-06-17 13:29:07 +00:00
|
|
|
void fullSearchRefreshOn(rpl::producer<> events);
|
2018-12-29 08:11:54 +00:00
|
|
|
void applyFilterUpdate(bool force = false);
|
2019-04-16 16:28:41 +00:00
|
|
|
void refreshLoadMoreButton(bool mayBlock, bool isBlocked);
|
|
|
|
void loadMoreBlockedByDate();
|
2018-11-09 13:54:34 +00:00
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
void searchFailed(
|
|
|
|
SearchRequestType type,
|
2021-03-12 12:48:00 +00:00
|
|
|
const MTP::Error &error,
|
2020-06-11 16:09:46 +00:00
|
|
|
mtpRequestId requestId);
|
2021-03-12 12:48:00 +00:00
|
|
|
void peopleFailed(const MTP::Error &error, mtpRequestId requestId);
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void scrollToTop();
|
|
|
|
void setupScrollUpButton();
|
|
|
|
void updateScrollUpVisibility();
|
|
|
|
void startScrollUpButtonAnimation(bool shown);
|
|
|
|
void updateScrollUpPosition();
|
|
|
|
|
2020-07-02 07:13:50 +00:00
|
|
|
MTP::Sender _api;
|
|
|
|
|
2017-08-01 12:01:42 +00:00
|
|
|
bool _dragInScroll = false;
|
|
|
|
bool _dragForward = false;
|
2022-03-14 15:48:39 +00:00
|
|
|
base::Timer _chooseByDragTimer;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2022-11-30 06:31:33 +00:00
|
|
|
Layout _layout = Layout::Main;
|
|
|
|
int _narrowWidth = 0;
|
2019-04-24 10:15:10 +00:00
|
|
|
object_ptr<Ui::RpWidget> _searchControls;
|
2022-10-26 09:30:10 +00:00
|
|
|
object_ptr<HistoryView::TopBarWidget> _subsectionTopBar = { nullptr } ;
|
2017-08-01 12:01:42 +00:00
|
|
|
object_ptr<Ui::IconButton> _mainMenuToggle;
|
2020-03-18 12:14:45 +00:00
|
|
|
object_ptr<Ui::IconButton> _searchForNarrowFilters;
|
2022-10-20 13:42:50 +00:00
|
|
|
object_ptr<Ui::InputField> _filter;
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _chooseFromUser;
|
|
|
|
object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _jumpToDate;
|
2017-08-01 12:01:42 +00:00
|
|
|
object_ptr<Ui::CrossButton> _cancelSearch;
|
|
|
|
object_ptr<Ui::IconButton> _lockUnlock;
|
2022-10-21 14:10:56 +00:00
|
|
|
|
|
|
|
std::unique_ptr<Ui::PlainShadow> _forumTopShadow;
|
|
|
|
std::unique_ptr<Ui::GroupCallBar> _forumGroupCallBar;
|
|
|
|
std::unique_ptr<Ui::RequestsBar> _forumRequestsBar;
|
|
|
|
std::unique_ptr<HistoryView::ContactStatus> _forumReportBar;
|
|
|
|
|
2017-08-01 12:01:42 +00:00
|
|
|
object_ptr<Ui::ScrollArea> _scroll;
|
2019-04-24 10:15:10 +00:00
|
|
|
QPointer<InnerWidget> _inner;
|
2018-11-09 13:54:34 +00:00
|
|
|
class BottomButton;
|
|
|
|
object_ptr<BottomButton> _updateTelegram = { nullptr };
|
|
|
|
object_ptr<BottomButton> _loadMoreChats = { nullptr };
|
2022-02-22 13:58:55 +00:00
|
|
|
std::unique_ptr<Ui::DownloadBar> _downloadBar;
|
2019-02-10 16:29:55 +00:00
|
|
|
std::unique_ptr<Window::ConnectionState> _connecting;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _scrollToAnimation;
|
2022-12-01 10:14:35 +00:00
|
|
|
std::unique_ptr<Window::SlideAnimation> _showAnimation;
|
2022-12-01 13:48:33 +00:00
|
|
|
rpl::variable<float64> _shownProgressValue;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2019-04-05 08:28:07 +00:00
|
|
|
Ui::Animations::Simple _scrollToTopShown;
|
|
|
|
object_ptr<Ui::HistoryDownButton> _scrollToTop;
|
2022-10-26 09:30:10 +00:00
|
|
|
bool _scrollToTopIsShown = false;
|
|
|
|
bool _forumSearchRequested = false;
|
2019-04-05 08:28:07 +00:00
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
Data::Folder *_openedFolder = nullptr;
|
2022-11-30 06:31:33 +00:00
|
|
|
Data::Forum *_openedForum = nullptr;
|
2020-06-12 14:09:04 +00:00
|
|
|
Dialogs::Key _searchInChat;
|
2018-02-14 19:38:01 +00:00
|
|
|
History *_searchInMigrated = nullptr;
|
2020-10-06 12:58:16 +00:00
|
|
|
PeerData *_searchFromAuthor = nullptr;
|
2017-08-06 17:32:05 +00:00
|
|
|
QString _lastFilterText;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
base::Timer _searchTimer;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
QString _peerSearchQuery;
|
|
|
|
bool _peerSearchFull = false;
|
|
|
|
mtpRequestId _peerSearchRequest = 0;
|
|
|
|
|
2022-10-26 14:18:00 +00:00
|
|
|
QString _topicSearchQuery;
|
|
|
|
TimeId _topicSearchOffsetDate = 0;
|
|
|
|
MsgId _topicSearchOffsetId = 0;
|
|
|
|
MsgId _topicSearchOffsetTopicId = 0;
|
|
|
|
bool _topicSearchFull = false;
|
|
|
|
mtpRequestId _topicSearchRequest = 0;
|
|
|
|
|
2017-08-01 12:01:42 +00:00
|
|
|
QString _searchQuery;
|
2020-10-06 12:58:16 +00:00
|
|
|
PeerData *_searchQueryFrom = nullptr;
|
2019-05-20 19:04:24 +00:00
|
|
|
int32 _searchNextRate = 0;
|
2017-08-01 12:01:42 +00:00
|
|
|
bool _searchFull = false;
|
|
|
|
bool _searchFullMigrated = false;
|
2020-02-21 12:57:06 +00:00
|
|
|
int _searchInHistoryRequest = 0; // Not real mtpRequestId.
|
2017-08-01 12:01:42 +00:00
|
|
|
mtpRequestId _searchRequest = 0;
|
|
|
|
|
2022-10-26 12:33:58 +00:00
|
|
|
PeerData *_lastSearchPeer = nullptr;
|
|
|
|
MsgId _lastSearchId = 0;
|
|
|
|
MsgId _lastSearchMigratedId = 0;
|
|
|
|
|
2020-07-02 07:13:50 +00:00
|
|
|
base::flat_map<QString, MTPmessages_Messages> _searchCache;
|
2019-08-06 14:43:26 +00:00
|
|
|
Api::SingleMessageSearch _singleMessageSearch;
|
2020-07-02 07:13:50 +00:00
|
|
|
base::flat_map<mtpRequestId, QString> _searchQueries;
|
|
|
|
base::flat_map<QString, MTPcontacts_Found> _peerSearchCache;
|
|
|
|
base::flat_map<mtpRequestId, QString> _peerSearchQueries;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
QPixmap _widthAnimationCache;
|
|
|
|
|
2020-06-11 09:41:03 +00:00
|
|
|
int _topDelta = 0;
|
|
|
|
|
2022-11-30 06:31:33 +00:00
|
|
|
std::unique_ptr<Widget> _childList;
|
|
|
|
std::unique_ptr<Ui::RpWidget> _childListShadow;
|
2022-12-01 13:48:33 +00:00
|
|
|
rpl::variable<float64> _childListShown;
|
|
|
|
rpl::variable<PeerId> _childListPeerId;
|
|
|
|
std::unique_ptr<Ui::RpWidget> _hideChildListCanvas;
|
2022-11-30 06:31:33 +00:00
|
|
|
|
2017-08-01 12:01:42 +00:00
|
|
|
};
|
2019-04-24 10:15:10 +00:00
|
|
|
|
|
|
|
} // namespace Dialogs
|