2017-06-18 11:08:14 +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-06-18 11:08:14 +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-06-18 11:08:14 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "history/view/history_view_element.h"
|
2018-01-09 17:08:31 +00:00
|
|
|
#include "history/admin_log/history_admin_log_item.h"
|
|
|
|
#include "history/admin_log/history_admin_log_section.h"
|
2017-10-05 15:35:52 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2019-04-02 09:13:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
|
|
|
#include "ui/widgets/tooltip.h"
|
2017-06-18 11:08:14 +00:00
|
|
|
#include "mtproto/sender.h"
|
2017-06-21 21:38:31 +00:00
|
|
|
#include "base/timer.h"
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
2019-07-24 11:13:51 +00:00
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
namespace HistoryView {
|
|
|
|
class Element;
|
|
|
|
struct TextState;
|
|
|
|
struct StateRequest;
|
|
|
|
enum class CursorState : char;
|
|
|
|
enum class PointState : char;
|
|
|
|
} // namespace HistoryView
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
namespace Ui {
|
|
|
|
class PopupMenu;
|
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
namespace Window {
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2017-06-21 21:38:31 +00:00
|
|
|
} // namespace Window
|
2017-06-18 11:08:14 +00:00
|
|
|
|
|
|
|
namespace AdminLog {
|
|
|
|
|
|
|
|
class SectionMemento;
|
2017-06-18 13:08:49 +00:00
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
class InnerWidget final
|
|
|
|
: public Ui::RpWidget
|
|
|
|
, public Ui::AbstractTooltipShower
|
2018-01-17 16:21:01 +00:00
|
|
|
, public HistoryView::ElementDelegate
|
2017-10-05 15:35:52 +00:00
|
|
|
, private base::Subscriber {
|
2017-06-18 11:08:14 +00:00
|
|
|
public:
|
2017-10-05 15:35:52 +00:00
|
|
|
InnerWidget(
|
|
|
|
QWidget *parent,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2017-10-05 15:35:52 +00:00
|
|
|
not_null<ChannelData*> channel);
|
2017-07-05 13:11:08 +00:00
|
|
|
|
2019-09-02 09:23:06 +00:00
|
|
|
[[nodiscard]] Main::Session &session() const;
|
2019-07-24 11:13:51 +00:00
|
|
|
|
2019-09-02 09:23:06 +00:00
|
|
|
[[nodiscard]] rpl::producer<> showSearchSignal() const;
|
|
|
|
[[nodiscard]] rpl::producer<int> scrollToSignal() const;
|
|
|
|
[[nodiscard]] rpl::producer<> cancelSignal() const;
|
2017-06-18 11:08:14 +00:00
|
|
|
|
2019-09-02 09:23:06 +00:00
|
|
|
[[nodiscard]] not_null<ChannelData*> channel() const {
|
2017-06-18 11:08:14 +00:00
|
|
|
return _channel;
|
|
|
|
}
|
|
|
|
|
2017-06-23 19:28:42 +00:00
|
|
|
// Set the correct scroll position after being resized.
|
|
|
|
void restoreScrollPosition();
|
|
|
|
|
2017-06-18 11:08:14 +00:00
|
|
|
void resizeToWidth(int newWidth, int minHeight) {
|
|
|
|
_minHeight = minHeight;
|
|
|
|
return TWidget::resizeToWidth(newWidth);
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void saveState(not_null<SectionMemento*> memento);
|
|
|
|
void restoreState(not_null<SectionMemento*> memento);
|
2017-06-18 11:08:14 +00:00
|
|
|
|
2017-07-04 13:31:18 +00:00
|
|
|
// Empty "flags" means all events.
|
|
|
|
void applyFilter(FilterValue &&value);
|
2017-07-05 13:11:08 +00:00
|
|
|
void applySearch(const QString &query);
|
2018-06-04 15:35:11 +00:00
|
|
|
void showFilter(Fn<void(FilterValue &&filter)> callback);
|
2017-06-18 11:08:14 +00:00
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
// Ui::AbstractTooltipShower interface.
|
2017-06-21 21:38:31 +00:00
|
|
|
QString tooltipText() const override;
|
|
|
|
QPoint tooltipPos() const override;
|
2019-09-16 11:14:06 +00:00
|
|
|
bool tooltipWindowActive() const override;
|
2017-06-21 21:38:31 +00:00
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
// HistoryView::ElementDelegate interface.
|
2018-01-19 17:10:58 +00:00
|
|
|
HistoryView::Context elementContext() override;
|
2018-01-17 16:21:01 +00:00
|
|
|
std::unique_ptr<HistoryView::Element> elementCreate(
|
|
|
|
not_null<HistoryMessage*> message) override;
|
|
|
|
std::unique_ptr<HistoryView::Element> elementCreate(
|
|
|
|
not_null<HistoryService*> message) override;
|
2018-01-26 15:40:11 +00:00
|
|
|
bool elementUnderCursor(
|
|
|
|
not_null<const HistoryView::Element*> view) override;
|
2018-01-21 14:49:42 +00:00
|
|
|
void elementAnimationAutoplayAsync(
|
2018-01-26 15:40:11 +00:00
|
|
|
not_null<const HistoryView::Element*> view) override;
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time elementHighlightTime(
|
2018-02-16 17:59:35 +00:00
|
|
|
not_null<const HistoryView::Element*> element) override;
|
2018-03-08 21:21:27 +00:00
|
|
|
bool elementInSelectionMode() override;
|
2019-05-14 09:50:44 +00:00
|
|
|
bool elementIntersectsRange(
|
|
|
|
not_null<const HistoryView::Element*> view,
|
|
|
|
int from,
|
|
|
|
int till) override;
|
2019-08-01 12:55:14 +00:00
|
|
|
void elementStartStickerLoop(
|
2019-08-01 11:42:24 +00:00
|
|
|
not_null<const HistoryView::Element*> view) override;
|
2020-01-14 11:55:18 +00:00
|
|
|
void elementShowPollResults(
|
|
|
|
not_null<PollData*> poll,
|
|
|
|
FullMsgId context) override;
|
2018-01-17 16:21:01 +00:00
|
|
|
|
2017-06-18 11:08:14 +00:00
|
|
|
~InnerWidget();
|
|
|
|
|
|
|
|
protected:
|
2017-09-13 16:57:44 +00:00
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
|
|
|
|
2017-06-18 11:08:14 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
2017-06-24 10:11:29 +00:00
|
|
|
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
2017-06-21 21:38:31 +00:00
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
2017-06-24 10:11:29 +00:00
|
|
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
2017-06-18 11:08:14 +00:00
|
|
|
|
|
|
|
// Resizes content and counts natural widget height for the desired width.
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
|
|
|
private:
|
2018-01-11 19:33:26 +00:00
|
|
|
using Element = HistoryView::Element;
|
2017-06-18 13:08:49 +00:00
|
|
|
enum class Direction {
|
|
|
|
Up,
|
|
|
|
Down,
|
|
|
|
};
|
2017-06-21 21:38:31 +00:00
|
|
|
enum class MouseAction {
|
|
|
|
None,
|
|
|
|
PrepareDrag,
|
|
|
|
Dragging,
|
|
|
|
Selecting,
|
|
|
|
};
|
2017-06-22 01:31:02 +00:00
|
|
|
enum class EnumItemsDirection {
|
|
|
|
TopToBottom,
|
|
|
|
BottomToTop,
|
|
|
|
};
|
2018-01-27 13:59:24 +00:00
|
|
|
using TextState = HistoryView::TextState;
|
|
|
|
using CursorState = HistoryView::CursorState;
|
|
|
|
using PointState = HistoryView::PointState;
|
|
|
|
using StateRequest = HistoryView::StateRequest;
|
2017-06-21 21:38:31 +00:00
|
|
|
|
|
|
|
void mouseActionStart(const QPoint &screenPos, Qt::MouseButton button);
|
|
|
|
void mouseActionUpdate(const QPoint &screenPos);
|
|
|
|
void mouseActionFinish(const QPoint &screenPos, Qt::MouseButton button);
|
|
|
|
void mouseActionCancel();
|
|
|
|
void updateSelected();
|
|
|
|
void performDrag();
|
2018-01-11 19:33:26 +00:00
|
|
|
int itemTop(not_null<const Element*> view) const;
|
|
|
|
void repaintItem(const Element *view);
|
2018-01-19 17:10:58 +00:00
|
|
|
void refreshItem(not_null<const Element*> view);
|
2018-01-21 19:21:08 +00:00
|
|
|
void resizeItem(not_null<Element*> view);
|
2018-01-11 19:33:26 +00:00
|
|
|
QPoint mapPointToItem(QPoint point, const Element *view) const;
|
2017-06-21 21:38:31 +00:00
|
|
|
|
2017-06-24 10:11:29 +00:00
|
|
|
void showContextMenu(QContextMenuEvent *e, bool showFromTouch = false);
|
|
|
|
void savePhotoToFile(PhotoData *photo);
|
|
|
|
void saveDocumentToFile(DocumentData *document);
|
|
|
|
void copyContextImage(PhotoData *photo);
|
2018-01-11 13:07:29 +00:00
|
|
|
void showStickerPackInfo(not_null<DocumentData*> document);
|
|
|
|
void cancelContextDownload(not_null<DocumentData*> document);
|
|
|
|
void showContextInFolder(not_null<DocumentData*> document);
|
|
|
|
void openContextGif(FullMsgId itemId);
|
|
|
|
void copyContextText(FullMsgId itemId);
|
2017-06-24 10:11:29 +00:00
|
|
|
void copySelectedText();
|
2019-04-08 15:10:06 +00:00
|
|
|
TextForMimeData getSelectedText() const;
|
2017-08-17 08:31:24 +00:00
|
|
|
void suggestRestrictUser(not_null<UserData*> user);
|
2019-01-03 14:39:19 +00:00
|
|
|
void restrictUser(not_null<UserData*> user, const MTPChatBannedRights &oldRights, const MTPChatBannedRights &newRights);
|
|
|
|
void restrictUserDone(not_null<UserData*> user, const MTPChatBannedRights &rights);
|
2017-06-24 10:11:29 +00:00
|
|
|
|
2017-07-05 18:11:31 +00:00
|
|
|
void requestAdmins();
|
2017-06-18 11:08:14 +00:00
|
|
|
void checkPreloadMore();
|
2017-06-18 13:08:49 +00:00
|
|
|
void updateVisibleTopItem();
|
|
|
|
void preloadMore(Direction direction);
|
2017-07-05 18:11:31 +00:00
|
|
|
void itemsAdded(Direction direction, int addedCount);
|
2017-06-18 11:08:14 +00:00
|
|
|
void updateSize();
|
2017-06-24 17:05:32 +00:00
|
|
|
void updateMinMaxIds();
|
2017-06-24 18:12:15 +00:00
|
|
|
void updateEmptyText();
|
2017-06-18 13:08:49 +00:00
|
|
|
void paintEmpty(Painter &p);
|
2017-07-04 13:31:18 +00:00
|
|
|
void clearAfterFilterChange();
|
2017-07-05 13:11:08 +00:00
|
|
|
void clearAndRequestLog();
|
2017-07-05 18:11:31 +00:00
|
|
|
void addEvents(Direction direction, const QVector<MTPChannelAdminLogEvent> &events);
|
2018-01-11 19:33:26 +00:00
|
|
|
Element *viewForItem(const HistoryItem *item);
|
2017-06-18 11:08:14 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
void toggleScrollDateShown();
|
|
|
|
void repaintScrollDateCallback();
|
|
|
|
bool displayScrollDate() const;
|
|
|
|
void scrollDateHide();
|
|
|
|
void scrollDateCheck();
|
|
|
|
void scrollDateHideByTimer();
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// This function finds all history items that are displayed and calls template method
|
|
|
|
// for each found message (in given direction) in the passed history with passed top offset.
|
|
|
|
//
|
2018-01-11 19:33:26 +00:00
|
|
|
// Method has "bool (*Method)(not_null<Element*> view, int itemtop, int itembottom)" signature
|
2017-06-22 01:31:02 +00:00
|
|
|
// if it returns false the enumeration stops immidiately.
|
|
|
|
template <EnumItemsDirection direction, typename Method>
|
|
|
|
void enumerateItems(Method method);
|
|
|
|
|
|
|
|
// This function finds all userpics on the left that are displayed and calls template method
|
|
|
|
// for each found userpic (from the top to the bottom) using enumerateItems() method.
|
|
|
|
//
|
2018-01-11 19:33:26 +00:00
|
|
|
// Method has "bool (*Method)(not_null<Element*> view, int userpicTop)" signature
|
2019-01-13 11:47:00 +00:00
|
|
|
// if it returns false the enumeration stops immediately.
|
2017-06-22 01:31:02 +00:00
|
|
|
template <typename Method>
|
|
|
|
void enumerateUserpics(Method method);
|
|
|
|
|
|
|
|
// This function finds all date elements that are displayed and calls template method
|
|
|
|
// for each found date element (from the bottom to the top) using enumerateItems() method.
|
|
|
|
//
|
2017-08-17 08:31:24 +00:00
|
|
|
// Method has "bool (*Method)(not_null<HistoryItem*> item, int itemtop, int dateTop)" signature
|
2019-01-13 11:47:00 +00:00
|
|
|
// if it returns false the enumeration stops immediately.
|
2017-06-22 01:31:02 +00:00
|
|
|
template <typename Method>
|
|
|
|
void enumerateDates(Method method);
|
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
const not_null<Window::SessionController*> _controller;
|
|
|
|
const not_null<ChannelData*> _channel;
|
|
|
|
const not_null<History*> _history;
|
|
|
|
MTP::Sender _api;
|
|
|
|
|
2018-01-10 13:13:33 +00:00
|
|
|
std::vector<OwnedItem> _items;
|
2019-01-13 11:47:00 +00:00
|
|
|
std::set<uint64> _eventIds;
|
|
|
|
std::map<not_null<const HistoryItem*>, not_null<Element*>> _itemsByData;
|
2019-08-01 11:42:24 +00:00
|
|
|
base::flat_set<FullMsgId> _animatedStickersPlayed;
|
2017-06-21 21:38:31 +00:00
|
|
|
int _itemsTop = 0;
|
2018-01-19 17:10:58 +00:00
|
|
|
int _itemsWidth = 0;
|
2017-06-21 21:38:31 +00:00
|
|
|
int _itemsHeight = 0;
|
2017-06-18 11:08:14 +00:00
|
|
|
|
|
|
|
int _minHeight = 0;
|
|
|
|
int _visibleTop = 0;
|
|
|
|
int _visibleBottom = 0;
|
2018-01-11 19:33:26 +00:00
|
|
|
Element *_visibleTopItem = nullptr;
|
2017-06-18 13:08:49 +00:00
|
|
|
int _visibleTopFromItem = 0;
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
bool _scrollDateShown = false;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _scrollDateOpacity;
|
2017-06-21 21:38:31 +00:00
|
|
|
SingleQueuedInvokation _scrollDateCheck;
|
|
|
|
base::Timer _scrollDateHideTimer;
|
2018-01-11 19:33:26 +00:00
|
|
|
Element *_scrollDateLastItem = nullptr;
|
2017-06-21 21:38:31 +00:00
|
|
|
int _scrollDateLastItemTop = 0;
|
|
|
|
|
2017-06-18 13:08:49 +00:00
|
|
|
// Up - max, Down - min.
|
|
|
|
uint64 _maxId = 0;
|
|
|
|
uint64 _minId = 0;
|
|
|
|
mtpRequestId _preloadUpRequestId = 0;
|
|
|
|
mtpRequestId _preloadDownRequestId = 0;
|
2017-06-24 17:05:32 +00:00
|
|
|
|
|
|
|
// Don't load anything until the memento was read.
|
|
|
|
bool _upLoaded = true;
|
2017-06-18 13:08:49 +00:00
|
|
|
bool _downLoaded = true;
|
2017-07-04 13:31:18 +00:00
|
|
|
bool _filterChanged = false;
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::String _emptyText;
|
2017-06-18 11:08:14 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
MouseAction _mouseAction = MouseAction::None;
|
|
|
|
TextSelectType _mouseSelectType = TextSelectType::Letters;
|
|
|
|
QPoint _dragStartPosition;
|
|
|
|
QPoint _mousePosition;
|
2018-01-11 19:33:26 +00:00
|
|
|
Element *_mouseActionItem = nullptr;
|
2018-01-27 13:59:24 +00:00
|
|
|
CursorState _mouseCursorState = CursorState();
|
2017-06-21 21:38:31 +00:00
|
|
|
uint16 _mouseTextSymbol = 0;
|
|
|
|
bool _pressWasInactive = false;
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
Element *_selectedItem = nullptr;
|
2017-06-21 21:38:31 +00:00
|
|
|
TextSelection _selectedText;
|
|
|
|
bool _wasSelectedText = false; // was some text selected in current drag action
|
|
|
|
Qt::CursorShape _cursor = style::cur_default;
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
2017-06-21 21:38:31 +00:00
|
|
|
|
|
|
|
QPoint _trippleClickPoint;
|
|
|
|
base::Timer _trippleClickTimer;
|
|
|
|
|
2017-07-04 13:31:18 +00:00
|
|
|
FilterValue _filter;
|
2017-07-05 13:11:08 +00:00
|
|
|
QString _searchQuery;
|
2017-08-17 08:31:24 +00:00
|
|
|
std::vector<not_null<UserData*>> _admins;
|
|
|
|
std::vector<not_null<UserData*>> _adminsCanEdit;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(FilterValue &&filter)> _showFilterCallback;
|
2017-06-18 11:08:14 +00:00
|
|
|
|
2019-09-02 09:23:06 +00:00
|
|
|
rpl::event_stream<> _showSearchSignal;
|
|
|
|
rpl::event_stream<int> _scrollToSignal;
|
|
|
|
rpl::event_stream<> _cancelSignal;
|
|
|
|
|
2017-06-18 11:08:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace AdminLog
|