2018-01-10 13:13:33 +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
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/view/history_view_element.h"
|
2020-04-30 10:11:05 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2020-04-29 12:36:51 +00:00
|
|
|
#include "base/weak_ptr.h"
|
2018-01-10 13:13:33 +00:00
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
class HistoryMessage;
|
2018-01-14 16:02:25 +00:00
|
|
|
struct HistoryMessageEdited;
|
2021-09-27 00:52:00 +00:00
|
|
|
struct HistoryMessageSponsored;
|
2020-04-29 12:36:51 +00:00
|
|
|
struct HistoryMessageForwarded;
|
2018-01-10 13:13:33 +00:00
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
namespace HistoryView {
|
2018-01-10 13:13:33 +00:00
|
|
|
|
2021-10-05 22:18:53 +00:00
|
|
|
class ViewButton;
|
2019-08-02 13:21:09 +00:00
|
|
|
class WebPage;
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
// Special type of Component for the channel actions log.
|
|
|
|
struct LogEntryOriginal
|
|
|
|
: public RuntimeComponent<LogEntryOriginal, Element> {
|
|
|
|
LogEntryOriginal();
|
|
|
|
LogEntryOriginal(LogEntryOriginal &&other);
|
|
|
|
LogEntryOriginal &operator=(LogEntryOriginal &&other);
|
|
|
|
~LogEntryOriginal();
|
|
|
|
|
2019-08-02 13:21:09 +00:00
|
|
|
std::unique_ptr<WebPage> page;
|
2018-01-14 16:02:25 +00:00
|
|
|
};
|
|
|
|
|
2020-04-30 10:11:05 +00:00
|
|
|
struct PsaTooltipState : public RuntimeComponent<PsaTooltipState, Element> {
|
|
|
|
QString type;
|
|
|
|
mutable ClickHandlerPtr link;
|
|
|
|
mutable Ui::Animations::Simple buttonVisibleAnimation;
|
|
|
|
mutable bool buttonVisible = true;
|
|
|
|
};
|
|
|
|
|
2020-04-29 12:36:51 +00:00
|
|
|
class Message : public Element, public base::has_weak_ptr {
|
2018-01-10 13:13:33 +00:00
|
|
|
public:
|
2018-01-19 17:10:58 +00:00
|
|
|
Message(
|
|
|
|
not_null<ElementDelegate*> delegate,
|
2020-06-16 16:53:44 +00:00
|
|
|
not_null<HistoryMessage*> data,
|
|
|
|
Element *replacing);
|
2020-09-03 07:19:02 +00:00
|
|
|
~Message();
|
|
|
|
|
|
|
|
void clickHandlerPressedChanged(
|
|
|
|
const ClickHandlerPtr &handler,
|
|
|
|
bool pressed) override;
|
2018-01-11 13:07:29 +00:00
|
|
|
|
2018-02-16 17:59:35 +00:00
|
|
|
int marginTop() const override;
|
|
|
|
int marginBottom() const override;
|
2021-08-19 14:22:12 +00:00
|
|
|
void draw(Painter &p, const PaintContext &context) const override;
|
2018-01-27 13:59:24 +00:00
|
|
|
PointState pointState(QPoint point) const override;
|
|
|
|
TextState textState(
|
2018-01-13 12:45:11 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const override;
|
2018-01-13 12:45:11 +00:00
|
|
|
void updatePressed(QPoint point) override;
|
2018-01-14 16:02:25 +00:00
|
|
|
void drawInfo(
|
|
|
|
Painter &p,
|
2021-09-02 22:08:57 +00:00
|
|
|
const PaintContext &context,
|
2018-01-14 16:02:25 +00:00
|
|
|
int right,
|
|
|
|
int bottom,
|
|
|
|
int width,
|
|
|
|
InfoDisplayType type) const override;
|
|
|
|
bool pointInTime(
|
|
|
|
int right,
|
|
|
|
int bottom,
|
|
|
|
QPoint point,
|
|
|
|
InfoDisplayType type) const override;
|
2019-04-08 15:10:06 +00:00
|
|
|
TextForMimeData selectedText(TextSelection selection) const override;
|
2018-01-14 16:02:25 +00:00
|
|
|
TextSelection adjustSelection(
|
|
|
|
TextSelection selection,
|
|
|
|
TextSelectType type) const override;
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2020-09-03 07:19:02 +00:00
|
|
|
bool hasHeavyPart() const override;
|
|
|
|
void unloadHeavyPart() override;
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
// hasFromPhoto() returns true even if we don't display the photo
|
|
|
|
// but we need to skip a place at the left side for this photo
|
|
|
|
bool hasFromPhoto() const override;
|
2018-01-14 16:02:25 +00:00
|
|
|
bool displayFromPhoto() const override;
|
2018-01-13 12:45:11 +00:00
|
|
|
bool hasFromName() const override;
|
|
|
|
bool displayFromName() const override;
|
2018-01-14 16:02:25 +00:00
|
|
|
bool displayForwardedFrom() const override;
|
|
|
|
bool hasOutLayout() const override;
|
|
|
|
bool drawBubble() const override;
|
|
|
|
bool hasBubble() const override;
|
2020-10-01 11:05:26 +00:00
|
|
|
int minWidthForMedia() const override;
|
2018-01-14 16:02:25 +00:00
|
|
|
bool hasFastReply() const override;
|
|
|
|
bool displayFastReply() const override;
|
2020-09-17 16:25:06 +00:00
|
|
|
bool displayRightActionComments() const;
|
|
|
|
std::optional<QSize> rightActionSize() const override;
|
2018-01-14 16:02:25 +00:00
|
|
|
void drawRightAction(
|
|
|
|
Painter &p,
|
2021-09-02 22:08:57 +00:00
|
|
|
const PaintContext &context,
|
2018-01-14 16:02:25 +00:00
|
|
|
int left,
|
|
|
|
int top,
|
|
|
|
int outerWidth) const override;
|
|
|
|
ClickHandlerPtr rightActionLink() const override;
|
|
|
|
bool displayEditedBadge() const override;
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId displayedEditDate() const override;
|
2020-08-28 12:48:54 +00:00
|
|
|
HistoryMessageReply *displayedReply() const override;
|
2021-02-16 13:50:41 +00:00
|
|
|
bool toggleSelectionByHandlerClick(
|
|
|
|
const ClickHandlerPtr &handler) const override;
|
2018-01-14 16:02:25 +00:00
|
|
|
int infoWidth() const override;
|
2020-01-24 09:50:20 +00:00
|
|
|
|
|
|
|
VerticalRepaintRange verticalRepaintRange() const override;
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2020-09-15 12:30:30 +00:00
|
|
|
void applyGroupAdminChanges(
|
|
|
|
const base::flat_set<UserId> &changes) override;
|
|
|
|
|
2018-06-28 15:20:05 +00:00
|
|
|
protected:
|
|
|
|
void refreshDataIdHook() override;
|
|
|
|
|
2018-01-10 13:13:33 +00:00
|
|
|
private:
|
2020-09-03 07:19:02 +00:00
|
|
|
struct CommentsButton;
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
not_null<HistoryMessage*> message() const;
|
2018-01-11 13:07:29 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
void initLogEntryOriginal();
|
2020-04-30 10:11:05 +00:00
|
|
|
void initPsa();
|
2018-01-14 16:02:25 +00:00
|
|
|
void refreshEditedBadge();
|
2018-01-13 12:45:11 +00:00
|
|
|
void fromNameUpdated(int width) const;
|
|
|
|
|
2021-01-20 14:09:45 +00:00
|
|
|
[[nodiscard]] bool showForwardsFromSender(
|
|
|
|
not_null<HistoryMessageForwarded*> forwarded) const;
|
2018-01-14 16:02:25 +00:00
|
|
|
[[nodiscard]] TextSelection skipTextSelection(
|
|
|
|
TextSelection selection) const;
|
|
|
|
[[nodiscard]] TextSelection unskipTextSelection(
|
|
|
|
TextSelection selection) const;
|
|
|
|
|
2020-09-03 07:19:02 +00:00
|
|
|
void toggleCommentsButtonRipple(bool pressed);
|
|
|
|
|
2021-09-02 22:08:57 +00:00
|
|
|
void paintCommentsButton(
|
|
|
|
Painter &p,
|
|
|
|
QRect &g,
|
|
|
|
const PaintContext &context) const;
|
|
|
|
void paintFromName(
|
|
|
|
Painter &p,
|
|
|
|
QRect &trect,
|
|
|
|
const PaintContext &context) const;
|
|
|
|
void paintForwardedInfo(
|
|
|
|
Painter &p,
|
|
|
|
QRect &trect,
|
|
|
|
const PaintContext &context) const;
|
|
|
|
void paintReplyInfo(
|
|
|
|
Painter &p,
|
|
|
|
QRect &trect,
|
|
|
|
const PaintContext &context) const;
|
|
|
|
// This method draws "via @bot" if it is not painted
|
|
|
|
// in forwarded info or in from name.
|
|
|
|
void paintViaBotIdInfo(
|
|
|
|
Painter &p,
|
|
|
|
QRect &trect,
|
|
|
|
const PaintContext &context) const;
|
|
|
|
void paintText(
|
|
|
|
Painter &p,
|
|
|
|
QRect &trect,
|
|
|
|
const PaintContext &context) const;
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2020-09-03 07:19:02 +00:00
|
|
|
bool getStateCommentsButton(
|
|
|
|
QPoint point,
|
|
|
|
QRect &g,
|
|
|
|
not_null<TextState*> outResult) const;
|
2018-01-13 12:45:11 +00:00
|
|
|
bool getStateFromName(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
2018-01-27 13:59:24 +00:00
|
|
|
not_null<TextState*> outResult) const;
|
2018-01-13 12:45:11 +00:00
|
|
|
bool getStateForwardedInfo(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
2018-01-27 13:59:24 +00:00
|
|
|
not_null<TextState*> outResult,
|
|
|
|
StateRequest request) const;
|
2018-01-13 12:45:11 +00:00
|
|
|
bool getStateReplyInfo(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
2018-01-27 13:59:24 +00:00
|
|
|
not_null<TextState*> outResult) const;
|
2018-01-13 12:45:11 +00:00
|
|
|
bool getStateViaBotIdInfo(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
2018-01-27 13:59:24 +00:00
|
|
|
not_null<TextState*> outResult) const;
|
2018-01-13 12:45:11 +00:00
|
|
|
bool getStateText(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
2018-01-27 13:59:24 +00:00
|
|
|
not_null<TextState*> outResult,
|
|
|
|
StateRequest request) const;
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
void updateMediaInBubbleState();
|
|
|
|
QRect countGeometry() const;
|
|
|
|
|
|
|
|
int resizeContentGetHeight(int newWidth);
|
|
|
|
QSize performCountOptimalSize() override;
|
|
|
|
QSize performCountCurrentSize(int newWidth) override;
|
2018-01-18 13:59:22 +00:00
|
|
|
bool hasVisibleText() const override;
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2020-10-30 12:13:48 +00:00
|
|
|
[[nodiscard]] bool isPinnedContext() const;
|
|
|
|
|
2020-10-22 09:13:00 +00:00
|
|
|
[[nodiscard]] bool displayFastShare() const;
|
|
|
|
[[nodiscard]] bool displayGoToOriginal() const;
|
|
|
|
[[nodiscard]] ClickHandlerPtr fastReplyLink() const;
|
|
|
|
[[nodiscard]] const HistoryMessageEdited *displayedEditBadge() const;
|
|
|
|
[[nodiscard]] HistoryMessageEdited *displayedEditBadge();
|
2021-09-27 00:52:00 +00:00
|
|
|
[[nodiscard]] auto displayedSponsorBadge() const
|
|
|
|
-> const HistoryMessageSponsored*;
|
2020-10-22 09:13:00 +00:00
|
|
|
[[nodiscard]] bool displayPinIcon() const;
|
|
|
|
|
2021-09-27 00:52:00 +00:00
|
|
|
void initTime() const;
|
2020-05-12 07:06:44 +00:00
|
|
|
[[nodiscard]] int timeLeft() const;
|
|
|
|
[[nodiscard]] int plainMaxWidth() const;
|
|
|
|
[[nodiscard]] int monospaceMaxWidth() const;
|
2018-01-14 16:02:25 +00:00
|
|
|
|
2021-10-10 16:11:08 +00:00
|
|
|
[[nodiscard]] bool ensureViewButton() const;
|
|
|
|
[[nodiscard]] int viewButtonHeight() const;
|
|
|
|
|
2019-08-02 13:21:09 +00:00
|
|
|
WebPage *logEntryOriginal() const;
|
2018-01-14 16:02:25 +00:00
|
|
|
|
2020-09-17 16:25:06 +00:00
|
|
|
[[nodiscard]] ClickHandlerPtr createGoToCommentsLink() const;
|
2020-04-30 10:11:05 +00:00
|
|
|
[[nodiscard]] ClickHandlerPtr psaTooltipLink() const;
|
|
|
|
void psaTooltipToggled(bool shown) const;
|
2020-04-29 12:36:51 +00:00
|
|
|
|
2020-09-15 12:30:30 +00:00
|
|
|
void refreshRightBadge();
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
mutable ClickHandlerPtr _rightActionLink;
|
|
|
|
mutable ClickHandlerPtr _fastReplyLink;
|
2020-09-03 07:19:02 +00:00
|
|
|
mutable std::unique_ptr<CommentsButton> _comments;
|
2021-10-10 16:11:08 +00:00
|
|
|
mutable std::unique_ptr<ViewButton> _viewButton;
|
2020-09-15 12:30:30 +00:00
|
|
|
|
|
|
|
Ui::Text::String _rightBadge;
|
2020-05-12 07:06:44 +00:00
|
|
|
int _bubbleWidthLimit = 0;
|
2018-01-14 16:02:25 +00:00
|
|
|
|
2018-01-10 13:13:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace HistoryView
|