tdesktop/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h

511 lines
14 KiB
C
Raw Normal View History

/*
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 "dialogs/dialogs_key.h"
#include "data/data_messages.h"
#include "ui/dragging_scroll_manager.h"
#include "ui/effects/animations.h"
#include "ui/rp_widget.h"
#include "ui/userpic_view.h"
2017-08-31 16:28:58 +00:00
#include "base/flags.h"
2019-09-13 12:22:54 +00:00
#include "base/object_ptr.h"
namespace style {
struct DialogRow;
} // namespace style
2021-03-12 12:48:00 +00:00
namespace MTP {
class Error;
} // namespace MTP
2019-07-24 11:45:24 +00:00
namespace Main {
class Session;
} // namespace Main
namespace Ui {
class IconButton;
class PopupMenu;
2020-03-31 08:36:33 +00:00
class FlatLabel;
struct ScrollToRequest;
} // namespace Ui
namespace Window {
class SessionController;
} // namespace Window
2020-05-28 14:32:10 +00:00
namespace Data {
2022-11-01 04:46:31 +00:00
class Thread;
class Folder;
class Forum;
2020-05-28 14:32:10 +00:00
} // namespace Data
namespace Dialogs::Ui {
using namespace ::Ui;
class VideoUserpic;
struct PaintContext;
struct TopicJumpCache;
} // namespace Dialogs::Ui
2019-04-24 10:15:10 +00:00
namespace Dialogs {
class Row;
class FakeRow;
class IndexedList;
struct ChosenRow {
Key key;
Data::MessagePosition message;
2023-07-04 16:13:56 +00:00
bool userpicClick : 1 = false;
bool filteredRow : 1 = false;
bool newWindow : 1 = false;
2019-04-24 10:15:10 +00:00
};
enum class SearchRequestType {
FromStart,
FromOffset,
PeerFromStart,
PeerFromOffset,
MigratedFromStart,
MigratedFromOffset,
};
enum class WidgetState {
Default,
Filtered,
};
class InnerWidget final : public Ui::RpWidget {
public:
struct ChildListShown {
PeerId peerId = 0;
float64 shown = 0.;
};
InnerWidget(
QWidget *parent,
not_null<Window::SessionController*> controller,
rpl::producer<ChildListShown> childListShown);
void searchReceived(
std::vector<not_null<HistoryItem*>> result,
HistoryItem *inject,
2019-04-24 10:15:10 +00:00
SearchRequestType type,
int fullCount);
void peerSearchReceived(
const QString &query,
const QVector<MTPPeer> &my,
const QVector<MTPPeer> &result);
2020-02-07 16:07:21 +00:00
[[nodiscard]] FilterId filterId() const;
2019-04-24 14:12:35 +00:00
void clearSelection();
2019-04-24 10:15:10 +00:00
void changeOpenedFolder(Data::Folder *folder);
void changeOpenedForum(Data::Forum *forum);
void selectSkip(int32 direction);
void selectSkipPage(int32 pixels, int32 direction);
void dragLeft();
void setNarrowRatio(float64 narrowRatio);
void clearFilter();
void refresh(bool toTop = false);
2020-03-31 08:36:33 +00:00
void refreshEmptyLabel();
void resizeEmptyLabel();
2022-11-14 07:24:31 +00:00
bool chooseRow(
Qt::KeyboardModifiers modifiers = {},
MsgId pressedTopicRootId = {});
2019-04-24 10:15:10 +00:00
void scrollToEntry(const RowDescriptor &entry);
[[nodiscard]] Data::Folder *shownFolder() const;
[[nodiscard]] Data::Forum *shownForum() const;
[[nodiscard]] WidgetState state() const;
[[nodiscard]] not_null<const style::DialogRow*> st() const {
return _st;
}
[[nodiscard]] bool waitingForSearch() const {
2018-01-07 12:04:34 +00:00
return _waitingForSearch;
}
[[nodiscard]] bool hasFilteredResults() const;
2020-10-06 12:58:16 +00:00
void searchInChat(Key key, PeerData *from);
void applyFilterUpdate(QString newFilter, bool force = false);
void onHashtagFilterUpdate(QStringView newFilter);
void appendToFiltered(Key key);
2022-11-01 04:46:31 +00:00
Data::Thread *updateFromParentDrag(QPoint globalPosition);
2018-12-29 13:09:45 +00:00
void setLoadMoreCallback(Fn<void()> callback);
void setLoadMoreFilteredCallback(Fn<void()> callback);
2018-12-29 13:09:45 +00:00
[[nodiscard]] rpl::producer<> listBottomReached() const;
[[nodiscard]] rpl::producer<> cancelSearchFromUserRequests() const;
[[nodiscard]] rpl::producer<ChosenRow> chosenRow() const;
[[nodiscard]] rpl::producer<> updated() const;
2019-04-24 10:15:10 +00:00
[[nodiscard]] rpl::producer<int> scrollByDeltaRequests() const;
[[nodiscard]] rpl::producer<Ui::ScrollToRequest> mustScrollTo() const;
[[nodiscard]] rpl::producer<Ui::ScrollToRequest> dialogMoved() const;
[[nodiscard]] rpl::producer<> searchMessages() const;
[[nodiscard]] rpl::producer<> cancelSearchInChatRequests() const;
[[nodiscard]] rpl::producer<QString> completeHashtagRequests() const;
[[nodiscard]] rpl::producer<> refreshHashtagsRequests() const;
2022-02-05 15:15:24 +00:00
[[nodiscard]] RowDescriptor resolveChatNext(RowDescriptor from = {}) const;
[[nodiscard]] RowDescriptor resolveChatPrevious(RowDescriptor from = {}) const;
2019-04-24 10:15:10 +00:00
~InnerWidget();
void parentGeometryChanged();
protected:
2017-09-13 16:57:44 +00:00
void visibleTopBottomUpdated(
int visibleTop,
int visibleBottom) override;
void paintEvent(QPaintEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void enterEventHook(QEnterEvent *e) override;
void leaveEventHook(QEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override;
private:
struct CollapsedRow;
struct HashtagResult;
struct PeerSearchResult;
2018-12-29 13:09:45 +00:00
enum class JumpSkip {
PreviousOrBegin,
NextOrEnd,
PreviousOrOriginal,
NextOrOriginal,
};
2020-03-31 08:36:33 +00:00
enum class EmptyState : uchar {
None,
Loading,
NoContacts,
EmptyFolder,
EmptyForum,
2020-03-31 08:36:33 +00:00
};
struct PinnedRow {
anim::value yadd;
crl::time animStartTime = 0;
};
struct FilterResult {
2022-11-11 18:58:51 +00:00
FilterResult(not_null<Row*> row) : row(row) {
}
not_null<Row*> row;
int top = 0;
[[nodiscard]] Key key() const;
[[nodiscard]] int bottom() const;
};
2019-07-24 11:45:24 +00:00
Main::Session &session() const;
2019-04-24 10:15:10 +00:00
void dialogRowReplaced(Row *oldRow, Row *newRow);
void setState(WidgetState state);
void editOpenedFilter();
void repaintCollapsedFolderRow(not_null<Data::Folder*> folder);
void refreshWithCollapsedRows(bool toTop = false);
bool needCollapsedRowsRefresh() const;
bool chooseCollapsedRow();
2020-02-07 11:34:05 +00:00
void switchToFilter(FilterId filterId);
2018-01-07 12:04:34 +00:00
bool chooseHashtag();
ChosenRow computeChosenRow() const;
2018-11-21 06:43:49 +00:00
bool isSearchResultActive(
2019-04-24 10:15:10 +00:00
not_null<FakeRow*> result,
const RowDescriptor &entry) const;
2018-01-07 12:04:34 +00:00
2020-06-12 14:09:04 +00:00
void repaintDialogRow(FilterId filterId, not_null<Row*> row);
void repaintDialogRow(RowDescriptor row);
void refreshDialogRow(RowDescriptor row);
bool updateEntryHeight(not_null<Entry*> entry);
2020-06-12 14:09:04 +00:00
void clearMouseSelection(bool clearSelection = false);
void mousePressReleased(
QPoint globalPosition,
Qt::MouseButton button,
Qt::KeyboardModifiers modifiers);
void clearIrrelevantState();
void selectByMouse(QPoint globalPosition);
void preloadRowsData();
void scrollToItem(int top, int height);
void scrollToDefaultSelected();
void setCollapsedPressed(int pressed);
2022-11-14 07:24:31 +00:00
void setPressed(Row *pressed, bool pressedTopicJump);
void clearPressed();
void setHashtagPressed(int pressed);
void setFilteredPressed(int pressed, bool pressedTopicJump);
void setPeerSearchPressed(int pressed);
void setSearchedPressed(int pressed);
bool isPressed() const {
return (_collapsedPressed >= 0)
2018-01-03 18:00:11 +00:00
|| _pressed
|| (_hashtagPressed >= 0)
|| (_filteredPressed >= 0)
|| (_peerSearchPressed >= 0)
|| (_searchedPressed >= 0);
}
bool isSelected() const {
return (_collapsedSelected >= 0)
2018-01-03 18:00:11 +00:00
|| _selected
|| (_hashtagSelected >= 0)
|| (_filteredSelected >= 0)
|| (_peerSearchSelected >= 0)
|| (_searchedSelected >= 0);
}
bool uniqueSearchResults() const;
bool hasHistoryInResults(not_null<History*> history) const;
2018-01-03 18:00:11 +00:00
2019-06-17 14:37:29 +00:00
int defaultRowTop(not_null<Row*> row) const;
void setupOnlineStatusCheck();
2023-05-23 16:13:02 +00:00
void jumpToTop();
void updateRowCornerStatusShown(not_null<History*> history);
void repaintDialogRowCornerStatus(not_null<History*> history);
2019-06-17 14:37:29 +00:00
2018-11-16 13:36:42 +00:00
void setupShortcuts();
2019-04-24 10:15:10 +00:00
RowDescriptor computeJump(
const RowDescriptor &to,
2022-02-05 15:15:24 +00:00
JumpSkip skip) const;
2019-04-24 10:15:10 +00:00
bool jumpToDialogRow(RowDescriptor to);
2018-11-16 13:36:42 +00:00
2019-04-24 10:15:10 +00:00
RowDescriptor chatListEntryBefore(const RowDescriptor &which) const;
RowDescriptor chatListEntryAfter(const RowDescriptor &which) const;
RowDescriptor chatListEntryFirst() const;
RowDescriptor chatListEntryLast() const;
2018-11-16 13:36:42 +00:00
void itemRemoved(not_null<const HistoryItem*> item);
enum class UpdateRowSection {
Default = (1 << 0),
Filtered = (1 << 1),
PeerSearch = (1 << 2),
MessageSearch = (1 << 3),
All = Default | Filtered | PeerSearch | MessageSearch,
};
2017-08-31 16:28:58 +00:00
using UpdateRowSections = base::flags<UpdateRowSection>;
friend inline constexpr auto is_flag_type(UpdateRowSection) { return true; };
void updateSearchResult(not_null<PeerData*> peer);
2018-01-03 18:00:11 +00:00
void updateDialogRow(
2019-04-24 10:15:10 +00:00
RowDescriptor row,
QRect updateRect = QRect(),
2018-01-03 18:00:11 +00:00
UpdateRowSections sections = UpdateRowSection::All);
void fillSupportSearchMenu(not_null<Ui::PopupMenu*> menu);
void fillArchiveSearchMenu(not_null<Ui::PopupMenu*> menu);
void refreshShownList();
[[nodiscard]] int skipTopHeight() const;
[[nodiscard]] int collapsedRowsOffset() const;
[[nodiscard]] int dialogsOffset() const;
[[nodiscard]] int shownHeight(int till = -1) const;
[[nodiscard]] int fixedOnTopCount() const;
[[nodiscard]] int pinnedOffset() const;
[[nodiscard]] int filteredOffset() const;
[[nodiscard]] int filteredIndex(int y) const;
[[nodiscard]] int filteredHeight(int till = -1) const;
[[nodiscard]] int peerSearchOffset() const;
[[nodiscard]] int searchedOffset() const;
[[nodiscard]] int searchInChatSkip() const;
void paintCollapsedRows(
Painter &p,
QRect clip) const;
void paintCollapsedRow(
Painter &p,
not_null<const CollapsedRow*> row,
bool selected) const;
void paintPeerSearchResult(
Painter &p,
not_null<const PeerSearchResult*> result,
const Ui::PaintContext &context);
void paintSearchInChat(
Painter &p,
const Ui::PaintContext &context) const;
void paintSearchInPeer(
Painter &p,
not_null<PeerData*> peer,
Ui::PeerUserpicView &userpic,
int top,
2019-06-12 13:26:04 +00:00
const Ui::Text::String &text) const;
void paintSearchInSaved(
Painter &p,
int top,
2019-06-12 13:26:04 +00:00
const Ui::Text::String &text) const;
2020-09-11 15:33:26 +00:00
void paintSearchInReplies(
Painter &p,
int top,
const Ui::Text::String &text) const;
void paintSearchInTopic(
Painter &p,
const Ui::PaintContext &context,
not_null<Data::ForumTopic*> topic,
Ui::PeerUserpicView &userpic,
int top,
const Ui::Text::String &text) const;
template <typename PaintUserpic>
void paintSearchInFilter(
Painter &p,
PaintUserpic paintUserpic,
int top,
const style::icon *icon,
2019-06-12 13:26:04 +00:00
const Ui::Text::String &text) const;
void refreshSearchInChatLabel();
void repaintSearchResult(int index);
Ui::VideoUserpic *validateVideoUserpic(not_null<Row*> row);
Ui::VideoUserpic *validateVideoUserpic(not_null<History*> history);
Row *shownRowByKey(Key key);
void clearSearchResults(bool clearPeerSearchResults = true);
2019-04-24 10:15:10 +00:00
void updateSelectedRow(Key key = Key());
void trackSearchResultsHistory(not_null<History*> history);
void trackSearchResultsForum(Data::Forum *forum);
[[nodiscard]] QBrush currentBg() const;
2022-11-08 13:57:54 +00:00
[[nodiscard]] const std::vector<Key> &pinnedChatsOrder() const;
void checkReorderPinnedStart(QPoint localPosition);
int updateReorderIndexGetCount();
bool updateReorderPinned(QPoint localPosition);
void finishReorderPinned();
void stopReorderPinned();
2019-04-24 10:15:10 +00:00
int countPinnedIndex(Row *ofRow);
void savePinnedOrder();
bool pinnedShiftAnimationCallback(crl::time now);
2020-06-12 14:09:04 +00:00
void handleChatListEntryRefreshes();
void moveCancelSearchButtons();
void saveChatsFilterScrollState(FilterId filterId);
void restoreChatsFilterScrollState(FilterId filterId);
2022-09-20 18:12:30 +00:00
const not_null<Window::SessionController*> _controller;
not_null<IndexedList*> _shownList;
2020-02-07 09:43:12 +00:00
FilterId _filterId = 0;
bool _mouseSelection = false;
std::optional<QPoint> _lastMousePosition;
2023-07-04 16:13:56 +00:00
int _lastRowLocalMouseX = -1;
Qt::MouseButton _pressButton = Qt::LeftButton;
Data::Folder *_openedFolder = nullptr;
Data::Forum *_openedForum = nullptr;
2022-09-20 18:12:30 +00:00
rpl::lifetime _openedForumLifetime;
std::vector<std::unique_ptr<CollapsedRow>> _collapsedRows;
not_null<const style::DialogRow*> _st;
mutable std::unique_ptr<Ui::TopicJumpCache> _topicJumpCache;
int _collapsedSelected = -1;
int _collapsedPressed = -1;
bool _skipTopDialog = false;
2019-04-24 10:15:10 +00:00
Row *_selected = nullptr;
Row *_pressed = nullptr;
2022-11-14 07:24:31 +00:00
MsgId _pressedTopicJumpRootId;
bool _selectedTopicJump = false;
bool _pressedTopicJump = false;
2019-04-24 10:15:10 +00:00
Row *_dragging = nullptr;
int _draggingIndex = -1;
int _aboveIndex = -1;
QPoint _dragStart;
std::vector<PinnedRow> _pinnedRows;
Ui::Animations::Basic _pinnedShiftAnimation;
2019-04-24 10:15:10 +00:00
base::flat_set<Key> _pinnedOnDragStart;
// Remember the last currently dragged row top shift for updating area.
int _aboveTopShift = -1;
int _narrowWidth = 0;
int _visibleTop = 0;
int _visibleBottom = 0;
QString _filter, _hashtagFilter;
std::vector<std::unique_ptr<HashtagResult>> _hashtagResults;
int _hashtagSelected = -1;
int _hashtagPressed = -1;
bool _hashtagDeleteSelected = false;
bool _hashtagDeletePressed = false;
std::vector<FilterResult> _filterResults;
base::flat_map<Key, std::unique_ptr<Row>> _filterResultsGlobal;
int _filteredSelected = -1;
int _filteredPressed = -1;
2018-01-07 12:04:34 +00:00
bool _waitingForSearch = false;
2020-03-31 08:36:33 +00:00
EmptyState _emptyState = EmptyState::None;
2018-01-07 12:04:34 +00:00
QString _peerSearchQuery;
std::vector<std::unique_ptr<PeerSearchResult>> _peerSearchResults;
int _peerSearchSelected = -1;
int _peerSearchPressed = -1;
2019-04-24 10:15:10 +00:00
std::vector<std::unique_ptr<FakeRow>> _searchResults;
base::flat_set<not_null<History*>> _searchResultsHistories;
rpl::lifetime _searchResultsLifetime;
int _searchedCount = 0;
int _searchedMigratedCount = 0;
int _searchedSelected = -1;
int _searchedPressed = -1;
2014-10-22 18:39:03 +00:00
2019-04-24 10:15:10 +00:00
WidgetState _state = WidgetState::Default;
2020-03-31 08:36:33 +00:00
object_ptr<Ui::FlatLabel> _empty = { nullptr };
object_ptr<Ui::IconButton> _cancelSearchInChat;
object_ptr<Ui::IconButton> _cancelSearchFromUser;
Ui::DraggingScrollManager _draggingScroll;
2019-04-24 10:15:10 +00:00
Key _searchInChat;
History *_searchInMigrated = nullptr;
2020-10-06 12:58:16 +00:00
PeerData *_searchFromPeer = nullptr;
mutable Ui::PeerUserpicView _searchInChatUserpic;
mutable Ui::PeerUserpicView _searchFromUserUserpic;
2019-06-12 13:26:04 +00:00
Ui::Text::String _searchInChatText;
Ui::Text::String _searchFromUserText;
2019-04-24 10:15:10 +00:00
RowDescriptor _menuRow;
base::flat_map<
not_null<PeerData*>,
std::unique_ptr<Ui::VideoUserpic>> _videoUserpics;
base::flat_map<FilterId, int> _chatsFilterScrollStates;
Fn<void()> _loadMoreCallback;
Fn<void()> _loadMoreFilteredCallback;
2018-12-29 13:09:45 +00:00
rpl::event_stream<> _listBottomReached;
2019-04-24 10:15:10 +00:00
rpl::event_stream<ChosenRow> _chosenRow;
rpl::event_stream<> _updated;
rpl::event_stream<Ui::ScrollToRequest> _mustScrollTo;
rpl::event_stream<Ui::ScrollToRequest> _dialogMoved;
rpl::event_stream<> _searchMessages;
rpl::event_stream<QString> _completeHashtagRequests;
rpl::event_stream<> _refreshHashtagsRequests;
rpl::variable<ChildListShown> _childListShown;
float64 _narrowRatio = 0.;
bool _geometryInited = false;
base::unique_qptr<Ui::PopupMenu> _menu;
};
2019-04-24 10:15:10 +00:00
} // namespace Dialogs