tdesktop/Telegram/SourceFiles/history/view/history_view_replies_section.h

335 lines
8.8 KiB
C
Raw Normal View History

2020-08-28 10:01:55 +00: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 "window/section_widget.h"
#include "window/section_memento.h"
#include "history/view/history_view_list_widget.h"
#include "data/data_messages.h"
2020-09-08 11:19:44 +00:00
#include "base/timer.h"
2020-08-28 10:01:55 +00:00
class History;
enum class CompressConfirm;
enum class SendMediaType;
struct SendingAlbum;
namespace SendMenu {
enum class Type;
} // namespace SendMenu
namespace Api {
struct SendOptions;
} // namespace Api
namespace Storage {
struct PreparedList;
} // namespace Storage
namespace Ui {
class ScrollArea;
class PlainShadow;
class FlatButton;
class HistoryDownButton;
template <typename Widget>
class SlideWrap;
2020-08-28 10:01:55 +00:00
} // namespace Ui
namespace Profile {
class BackButton;
} // namespace Profile
namespace InlineBots {
class Result;
} // namespace InlineBots
namespace Data {
class RepliesList;
} // namespace Data
namespace HistoryView {
class Element;
class TopBarWidget;
class RepliesMemento;
class ComposeControls;
class SendActionPainter;
2020-08-28 10:01:55 +00:00
class RepliesWidget final
: public Window::SectionWidget
, private ListDelegate {
public:
RepliesWidget(
QWidget *parent,
not_null<Window::SessionController*> controller,
not_null<History*> history,
MsgId rootId);
~RepliesWidget();
[[nodiscard]] not_null<History*> history() const;
Dialogs::RowDescriptor activeChat() const override;
bool hasTopBarShadow() const override {
return true;
}
QPixmap grabForShowAnimation(
const Window::SectionSlideParams &params) override;
bool showInternal(
not_null<Window::SectionMemento*> memento,
const Window::SectionShow &params) override;
std::unique_ptr<Window::SectionMemento> createMemento() override;
bool showMessage(
PeerId peerId,
const Window::SectionShow &params,
MsgId messageId) override;
2020-08-28 10:01:55 +00:00
void setInternalState(
const QRect &geometry,
not_null<RepliesMemento*> memento);
// Tabbed selector management.
bool pushTabbedSelectorToThirdSection(
not_null<PeerData*> peer,
const Window::SectionShow &params) override;
bool returnTabbedSelector() override;
// Float player interface.
bool floatPlayerHandleWheelEvent(QEvent *e) override;
QRect floatPlayerAvailableRect() override;
// ListDelegate interface.
Context listContext() override;
void listScrollTo(int top) override;
void listCancelRequest() override;
void listDeleteRequest() override;
rpl::producer<Data::MessagesSlice> listSource(
Data::MessagePosition aroundId,
int limitBefore,
int limitAfter) override;
bool listAllowsMultiSelect() override;
bool listIsItemGoodForSelection(not_null<HistoryItem*> item) override;
bool listIsLessInOrder(
not_null<HistoryItem*> first,
not_null<HistoryItem*> second) override;
void listSelectionChanged(SelectedItems &&items) override;
void listVisibleItemsChanged(HistoryItemsList &&items) override;
2020-09-15 15:30:34 +00:00
MessagesBarData listMessagesBar(
2020-08-28 10:01:55 +00:00
const std::vector<not_null<Element*>> &elements) override;
void listContentRefreshed() override;
ClickHandlerPtr listDateLink(not_null<Element*> view) override;
bool listElementHideReply(not_null<const Element*> view) override;
bool listElementShownUnread(not_null<const Element*> view) override;
bool listIsGoodForAroundPosition(not_null<const Element*> view) override;
2020-08-28 10:01:55 +00:00
protected:
void resizeEvent(QResizeEvent *e) override;
void paintEvent(QPaintEvent *e) override;
void showAnimatedHook(
const Window::SectionSlideParams &params) override;
void showFinishedHook() override;
void doSetInnerFocus() override;
private:
void onScroll();
void updateInnerVisibleArea();
void updateControlsGeometry();
void updateAdaptiveLayout();
void saveState(not_null<RepliesMemento*> memento);
void restoreState(not_null<RepliesMemento*> memento);
void showAtStart();
void showAtEnd();
2020-08-31 13:41:24 +00:00
void showAtPosition(
Data::MessagePosition position,
HistoryItem *originItem = nullptr);
bool showAtPositionNow(
Data::MessagePosition position,
HistoryItem *originItem);
void finishSending();
2020-08-28 10:01:55 +00:00
void setupComposeControls();
2020-09-03 07:19:02 +00:00
void setupRoot();
void setupRootView();
2020-09-03 07:19:02 +00:00
void refreshRootView();
2020-08-28 10:01:55 +00:00
void setupDragArea();
2020-09-08 11:19:44 +00:00
void sendReadTillRequest();
2020-09-15 15:30:34 +00:00
void readTill(not_null<HistoryItem*> item);
2020-08-28 10:01:55 +00:00
void setupScrollDownButton();
void scrollDownClicked();
void scrollDownAnimationFinish();
void updateScrollDownVisibility();
void updateScrollDownPosition();
void updatePinnedVisibility();
2020-08-28 10:01:55 +00:00
void confirmSendNowSelected();
void confirmDeleteSelected();
void confirmForwardSelected();
2020-08-28 10:01:55 +00:00
void clearSelected();
void setPinnedVisibility(bool shown);
2020-08-28 10:01:55 +00:00
void send();
void send(Api::SendOptions options);
void sendVoice(QByteArray bytes, VoiceWaveform waveform, int duration);
2020-08-28 10:01:55 +00:00
void edit(
not_null<HistoryItem*> item,
Api::SendOptions options,
mtpRequestId *const saveEditMsgRequestId);
void chooseAttach();
[[nodiscard]] SendMenu::Type sendMenuType() const;
2020-09-01 06:07:37 +00:00
[[nodiscard]] MsgId replyToId() const;
2020-09-03 07:19:02 +00:00
[[nodiscard]] HistoryItem *lookupRoot() const;
[[nodiscard]] bool computeAreComments() const;
2020-08-28 10:01:55 +00:00
2020-08-31 13:41:24 +00:00
void pushReplyReturn(not_null<HistoryItem*> item);
void computeCurrentReplyReturn();
void calculateNextReplyReturn();
void restoreReplyReturns(const std::vector<MsgId> &list);
void checkReplyReturns();
2020-09-22 16:16:36 +00:00
void recountChatWidth();
2020-08-31 13:41:24 +00:00
2020-08-28 10:01:55 +00:00
void uploadFile(const QByteArray &fileContent, SendMediaType type);
bool confirmSendingFiles(
QImage &&image,
QByteArray &&content,
CompressConfirm compressed,
const QString &insertTextOnCancel = QString());
bool confirmSendingFiles(
Storage::PreparedList &&list,
CompressConfirm compressed,
const QString &insertTextOnCancel = QString());
bool confirmSendingFiles(
not_null<const QMimeData*> data,
CompressConfirm compressed,
const QString &insertTextOnCancel = QString());
bool showSendingFilesError(const Storage::PreparedList &list) const;
void uploadFilesAfterConfirmation(
Storage::PreparedList &&list,
SendMediaType type,
TextWithTags &&caption,
MsgId replyTo,
Api::SendOptions options,
std::shared_ptr<SendingAlbum> album);
void sendExistingDocument(not_null<DocumentData*> document);
bool sendExistingDocument(
not_null<DocumentData*> document,
Api::SendOptions options);
void sendExistingPhoto(not_null<PhotoData*> photo);
bool sendExistingPhoto(
not_null<PhotoData*> photo,
Api::SendOptions options);
void sendInlineResult(
not_null<InlineBots::Result*> result,
not_null<UserData*> bot);
void sendInlineResult(
not_null<InlineBots::Result*> result,
not_null<UserData*> bot,
Api::SendOptions options);
const not_null<History*> _history;
const MsgId _rootId = 0;
2020-09-03 07:19:02 +00:00
HistoryItem *_root = nullptr;
2020-08-28 10:01:55 +00:00
std::shared_ptr<Data::RepliesList> _replies;
2020-09-03 07:19:02 +00:00
rpl::variable<bool> _areComments = false;
std::shared_ptr<SendActionPainter> _sendAction;
2020-08-28 10:01:55 +00:00
QPointer<ListWidget> _inner;
object_ptr<TopBarWidget> _topBar;
object_ptr<Ui::PlainShadow> _topBarShadow;
std::unique_ptr<ComposeControls> _composeControls;
bool _skipScrollEvent = false;
Ui::Text::String _rootTitle;
Ui::Text::String _rootMessage;
object_ptr<Ui::SlideWrap<Ui::RpWidget>> _rootView;
int _rootViewHeight = 0;
object_ptr<Ui::PlainShadow> _rootShadow;
std::unique_ptr<Ui::ScrollArea> _scroll;
2020-08-31 13:41:24 +00:00
std::vector<MsgId> _replyReturns;
HistoryItem *_replyReturn = nullptr;
2020-08-28 10:01:55 +00:00
Ui::Animations::Simple _scrollDownShown;
bool _scrollDownIsShown = false;
object_ptr<Ui::HistoryDownButton> _scrollDown;
Data::MessagesSlice _lastSlice;
bool _choosingAttach = false;
2020-09-08 11:19:44 +00:00
base::Timer _readRequestTimer;
bool _readRequestPending = false;
2020-09-08 11:19:44 +00:00
mtpRequestId _readRequestId = 0;
bool _loaded = false;
2020-08-28 10:01:55 +00:00
};
2020-09-08 11:19:44 +00:00
2020-08-28 10:01:55 +00:00
class RepliesMemento : public Window::SectionMemento {
public:
RepliesMemento(
not_null<History*> history,
MsgId rootId,
MsgId highlightId = 0)
2020-08-28 10:01:55 +00:00
: _history(history)
, _rootId(rootId)
, _highlightId(highlightId) {
2020-08-28 10:01:55 +00:00
}
explicit RepliesMemento(
not_null<HistoryItem*> commentsItem,
MsgId commentId = 0);
2020-08-28 10:01:55 +00:00
object_ptr<Window::SectionWidget> createWidget(
QWidget *parent,
not_null<Window::SessionController*> controller,
Window::Column column,
const QRect &geometry) override;
[[nodiscard]] not_null<History*> getHistory() const {
return _history;
}
[[nodiscard]] MsgId getRootId() const {
return _rootId;
}
void setReplies(std::shared_ptr<Data::RepliesList> replies) {
_replies = std::move(replies);
}
[[nodiscard]] std::shared_ptr<Data::RepliesList> getReplies() const {
return _replies;
}
2020-08-31 13:41:24 +00:00
void setReplyReturns(const std::vector<MsgId> &list) {
_replyReturns = list;
}
const std::vector<MsgId> &replyReturns() const {
return _replyReturns;
}
2020-08-28 10:01:55 +00:00
[[nodiscard]] not_null<ListMemento*> list() {
return &_list;
}
[[nodiscard]] MsgId getHighlightId() const {
return _highlightId;
}
2020-08-28 10:01:55 +00:00
private:
const not_null<History*> _history;
const MsgId _rootId = 0;
const MsgId _highlightId = 0;
2020-08-28 10:01:55 +00:00
ListMemento _list;
std::shared_ptr<Data::RepliesList> _replies;
2020-08-31 13:41:24 +00:00
std::vector<MsgId> _replyReturns;
2020-08-28 10:01:55 +00:00
};
} // namespace HistoryView