Make HistoryItem a final class.

This commit is contained in:
John Preston 2022-12-14 16:15:46 +04:00
parent 36de2e98d4
commit 1b73b34810
62 changed files with 4662 additions and 5116 deletions

View File

@ -764,6 +764,8 @@ PRIVATE
history/history_item_components.h
history/history_item_edition.cpp
history/history_item_edition.h
history/history_item_helpers.cpp
history/history_item_helpers.h
history/history_item_reply_markup.cpp
history/history_item_reply_markup.h
history/history_item_text.cpp
@ -772,10 +774,6 @@ PRIVATE
history/history_inner_widget.h
history/history_location_manager.cpp
history/history_location_manager.h
history/history_message.cpp
history/history_message.h
history/history_service.cpp
history/history_service.h
history/history_unread_things.cpp
history/history_unread_things.h
history/history_view_highlight_manager.cpp

View File

@ -16,7 +16,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_poll.h"
#include "data/data_session.h"
#include "history/history.h"
#include "history/history_message.h" // ShouldSendSilent
#include "history/history_item.h"
#include "history/history_item_helpers.h" // ShouldSendSilent
#include "main/main_session.h"
namespace Api {

View File

@ -20,7 +20,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_changes.h"
#include "data/stickers/data_stickers.h"
#include "history/history.h"
#include "history/history_message.h" // NewMessageFlags.
#include "history/history_item.h"
#include "history/history_item_helpers.h" // NewMessageFlags.
#include "chat_helpers/message_field.h" // ConvertTextTagsToEntities.
#include "chat_helpers/stickers_dice_pack.h" // DicePacks::kDiceString.
#include "ui/text/text_entity.h" // TextWithEntities.

View File

@ -67,8 +67,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/add_contact_box.h"
#include "mtproto/mtproto_config.h"
#include "history/history.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "history/history_item_helpers.h"
#include "main/main_session.h"
#include "main/main_session_settings.h"
#include "main/main_account.h"

View File

@ -20,7 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/painter.h"
#include "ui/ui_utility.h"
#include "history/history.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/view/history_view_message.h"
#include "main/main_session.h"
#include "apiwrap.h"

View File

@ -32,7 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/painter.h"
#include "boxes/share_box.h"
#include "history/view/history_view_group_call_bar.h" // GenerateUserpics...
#include "history/history_message.h" // GetErrorTextForSending.
#include "history/history_item_helpers.h" // GetErrorTextForSending.
#include "history/history.h"
#include "ui/boxes/confirm_box.h"
#include "boxes/peer_list_box.h"

View File

@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h"
#include "history/admin_log/history_admin_log_item.h"
#include "history/history.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/view/history_view_element.h"
#include "history/view/reactions/history_view_reactions_strip.h"
#include "lang/lang_keys.h"

View File

@ -30,7 +30,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "menu/menu_check_item.h"
#include "menu/menu_send.h"
#include "history/history.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "history/view/history_view_element.h" // HistoryView::Context.
#include "history/view/history_view_context_menu.h" // CopyPostLink.
#include "history/view/history_view_schedule_box.h"

View File

@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "calls/calls_instance.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "mainwidget.h"
#include "window/window_session_controller.h"
#include "main/main_session.h"

View File

@ -24,7 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h"
#include "boxes/share_box.h"
#include "history/view/history_view_schedule_box.h"
#include "history/history_message.h" // GetErrorTextForSending.
#include "history/history_item_helpers.h" // GetErrorTextForSending.
#include "history/history.h"
#include "data/data_histories.h"
#include "data/data_session.h"

View File

@ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_widget.h"
#include "history/history.h" // History::session
#include "history/history_item.h" // HistoryItem::originalText
#include "history/history_message.h" // DropCustomEmoji
#include "history/history_item_helpers.h" // DropCustomEmoji
#include "base/qthelp_regex.h"
#include "base/qthelp_url.h"
#include "base/event_filter.h"

View File

@ -23,7 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/storage_account.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_message.h"
#include "history/history_item_helpers.h"
#include "core/application.h"
#include "core/mime_type.h"
#include "ui/controls/download_bar.h"

View File

@ -8,8 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_media_types.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_message.h" // CreateMedia.
#include "history/history_item.h" // CreateMedia.
#include "history/history_location_manager.h"
#include "history/view/history_view_element.h"
#include "history/view/history_view_item_preview.h"
@ -235,7 +234,7 @@ template <typename MediaType>
bool UpdateExtendedMedia(
Invoice &invoice,
not_null<HistoryMessage*> item,
not_null<HistoryItem*> item,
const MTPMessageExtendedMedia &media) {
return media.match([&](const MTPDmessageExtendedMediaPreview &data) {
if (invoice.extendedMedia) {
@ -269,7 +268,7 @@ bool UpdateExtendedMedia(
}
return changed;
}, [&](const MTPDmessageExtendedMedia &data) {
invoice.extendedMedia = HistoryMessage::CreateMedia(
invoice.extendedMedia = HistoryItem::CreateMedia(
item,
data.vmedia());
return true;
@ -291,7 +290,7 @@ TextForMimeData WithCaptionClipboardText(
}
Invoice ComputeInvoiceData(
not_null<HistoryMessage*> item,
not_null<HistoryItem*> item,
const MTPDmessageMediaInvoice &data) {
auto description = qs(data.vdescription());
auto result = Invoice{
@ -1639,7 +1638,7 @@ bool MediaInvoice::updateSentMedia(const MTPMessageMedia &media) {
}
bool MediaInvoice::updateExtendedMedia(
not_null<HistoryMessage*> item,
not_null<HistoryItem*> item,
const MTPMessageExtendedMedia &media) {
Expects(item == parent());

View File

@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class Image;
class History;
class HistoryItem;
class HistoryMessage;
namespace base {
template <typename Enum>
@ -140,7 +139,7 @@ public:
virtual bool updateInlineResultMedia(const MTPMessageMedia &media) = 0;
virtual bool updateSentMedia(const MTPMessageMedia &media) = 0;
virtual bool updateExtendedMedia(
not_null<HistoryMessage*> item,
not_null<HistoryItem*> item,
const MTPMessageExtendedMedia &media) {
return false;
}
@ -428,7 +427,7 @@ public:
bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override;
bool updateExtendedMedia(
not_null<HistoryMessage*> item,
not_null<HistoryItem*> item,
const MTPMessageExtendedMedia &media) override;
std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message,
@ -541,7 +540,7 @@ private:
TextForMimeData &&caption);
[[nodiscard]] Invoice ComputeInvoiceData(
not_null<HistoryMessage*> item,
not_null<HistoryItem*> item,
const MTPDmessageMediaInvoice &data);
[[nodiscard]] Call ComputeCallData(const MTPDmessageActionPhoneCall &call);

View File

@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_service.h"
#include "history/history_item_helpers.h"
#include "main/main_session.h"
#include "data/data_histories.h"
#include "data/data_session.h"
@ -30,15 +30,15 @@ constexpr auto kMessagesPerPage = 50;
constexpr auto kReadRequestTimeout = 3 * crl::time(1000);
constexpr auto kMaxMessagesToDeleteMyTopic = 10;
[[nodiscard]] HistoryService *GenerateDivider(
[[nodiscard]] HistoryItem *GenerateDivider(
not_null<History*> history,
TimeId date,
const QString &text) {
return history->makeServiceMessage(
return history->makeMessage(
history->nextNonHistoryEntryId(),
MessageFlag::FakeHistoryItem,
date,
HistoryService::PreparedText{ { .text = text } });
PreparedServiceText{ { .text = text } });
}
[[nodiscard]] bool IsCreating(not_null<History*> history, MsgId rootId) {
@ -345,7 +345,7 @@ void RepliesList::injectRootDivider(
text());
} else if (_dividerWithComments != withComments) {
_dividerWithComments = withComments;
_divider->setServiceText(HistoryService::PreparedText{ { text() } });
_divider->updateServiceText(PreparedServiceText{ { text() } });
}
slice->ids.push_back(_divider->fullId());
}

View File

@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/timer.h"
class History;
class HistoryService;
namespace Data {
@ -123,7 +122,7 @@ private:
rpl::variable<std::optional<int>> _unreadCount;
MsgId _inboxReadTillId = 0;
MsgId _outboxReadTillId = 0;
HistoryService *_divider = nullptr;
HistoryItem *_divider = nullptr;
bool _dividerWithComments = false;
int _beforeId = 0;
int _afterId = 0;

View File

@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h"
#include "history/history.h"
#include "history/history_item_components.h"
#include "history/history_message.h"
#include "history/history_item_helpers.h"
#include "apiwrap.h"
namespace Data {

View File

@ -19,8 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class Image;
class HistoryItem;
class HistoryMessage;
class HistoryService;
struct WebPageCollage;
enum class WebPageType;
enum class NewMessageType;

View File

@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h"
#include "data/data_user.h"
#include "history/history.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/view/history_view_element.h"
#include "main/main_session.h"
#include "ui/image/image_location_factory.h"

View File

@ -29,8 +29,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_send_action.h"
#include "history/view/history_view_item_preview.h"
#include "history/history_unread_things.h"
#include "history/history_item_components.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "history/history_item_helpers.h"
#include "history/history.h"
#include "base/unixtime.h"
#include "data/data_channel.h"

View File

@ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h"
#include "history/view/media/history_view_media.h"
#include "history/view/media/history_view_web_page.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "history/history_item_text.h"
#include "history/admin_log/history_admin_log_section.h"
@ -582,18 +582,6 @@ HistoryView::Context InnerWidget::elementContext() {
return HistoryView::Context::AdminLog;
}
std::unique_ptr<HistoryView::Element> InnerWidget::elementCreate(
not_null<HistoryMessage*> message,
Element *replacing) {
return std::make_unique<HistoryView::Message>(this, message, replacing);
}
std::unique_ptr<HistoryView::Element> InnerWidget::elementCreate(
not_null<HistoryService*> message,
Element *replacing) {
return std::make_unique<HistoryView::Service>(this, message, replacing);
}
bool InnerWidget::elementUnderCursor(
not_null<const HistoryView::Element*> view) {
return (Element::Hovered() == view);
@ -1294,7 +1282,6 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
_antiSpamValidator.addAction(_menu, itemId);
auto msg = dynamic_cast<HistoryMessage*>(item);
if (isUponSelected > 0) {
_menu->addAction(
tr::lng_context_copy_selected(tr::now),
@ -1311,7 +1298,7 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
}), &st::menuIconDownload);
}
}
if (msg
if (!item->isService()
&& !link
&& (view->hasVisibleText()
|| mediaHasTextForCopy

View File

@ -91,12 +91,6 @@ public:
// HistoryView::ElementDelegate interface.
HistoryView::Context elementContext() override;
std::unique_ptr<HistoryView::Element> elementCreate(
not_null<HistoryMessage*> message,
HistoryView::Element *replacing = nullptr) override;
std::unique_ptr<HistoryView::Element> elementCreate(
not_null<HistoryService*> message,
HistoryView::Element *replacing = nullptr) override;
bool elementUnderCursor(
not_null<const HistoryView::Element*> view) override;
[[nodiscard]] float64 elementHighlightOpacity(

View File

@ -9,10 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/admin_log/history_admin_log_inner.h"
#include "history/view/history_view_element.h"
#include "history/history_location_manager.h"
#include "history/history_service.h"
#include "history/history_message.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "history/history_location_manager.h"
#include "api/api_chat_participants.h"
#include "api/api_text_entities.h"
#include "data/data_channel.h"
@ -773,10 +773,10 @@ void GenerateItems(
const TextWithEntities &text,
MsgId realId = MsgId(),
PhotoData *photo = nullptr) {
auto message = HistoryService::PreparedText{ text };
auto message = PreparedServiceText{ text };
message.links.push_back(fromLink);
addPart(
history->makeServiceMessage(
history->makeMessage(
history->nextNonHistoryEntryId(),
MessageFlag::AdminLogEntry,
date,
@ -1117,10 +1117,10 @@ void GenerateItems(
Ui::LayerOption::CloseOther);
}
});
auto message = HistoryService::PreparedText { text };
auto message = PreparedServiceText{ text };
message.links.push_back(fromLink);
message.links.push_back(setLink);
addPart(history->makeServiceMessage(
addPart(history->makeMessage(
history->nextNonHistoryEntryId(),
MessageFlag::AdminLogEntry,
date,
@ -1198,10 +1198,10 @@ void GenerateItems(
window->showPeerHistory(now);
}
});
auto message = HistoryService::PreparedText{ text };
auto message = PreparedServiceText{ text };
message.links.push_back(fromLink);
message.links.push_back(chatLink);
addPart(history->makeServiceMessage(
addPart(history->makeMessage(
history->nextNonHistoryEntryId(),
MessageFlag::AdminLogEntry,
date,
@ -1294,10 +1294,10 @@ void GenerateItems(
const auto addServiceMessageWithLink = [&](
const TextWithEntities &text,
const ClickHandlerPtr &link) {
auto message = HistoryService::PreparedText{ text };
auto message = PreparedServiceText{ text };
message.links.push_back(fromLink);
message.links.push_back(link);
addPart(history->makeServiceMessage(
addPart(history->makeMessage(
history->nextNonHistoryEntryId(),
MessageFlag::AdminLogEntry,
date,
@ -1363,7 +1363,7 @@ void GenerateItems(
const TextWithEntities &text,
const MTPExportedChatInvite &data,
ClickHandlerPtr additional = nullptr) {
auto message = HistoryService::PreparedText{ text };
auto message = PreparedServiceText{ text };
message.links.push_back(fromLink);
if (!ExtractInviteLink(data).endsWith(Ui::kQEllipsis)) {
message.links.push_back(std::make_shared<UrlClickHandler>(
@ -1372,7 +1372,7 @@ void GenerateItems(
if (additional) {
message.links.push_back(std::move(additional));
}
addPart(history->makeServiceMessage(
addPart(history->makeMessage(
history->nextNonHistoryEntryId(),
MessageFlag::AdminLogEntry,
date,

View File

@ -9,9 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_element.h"
#include "history/view/history_view_item_preview.h"
#include "history/history_message.h"
#include "history/history_service.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "history/history_item_helpers.h"
#include "history/history_inner_widget.h"
#include "history/history_unread_things.h"
#include "dialogs/dialogs_indexed_list.h"
@ -419,7 +419,9 @@ not_null<HistoryItem*> History::createItem(
}
return result;
}
return HistoryItem::Create(this, id, message, localFlags);
return message.match([&](const auto &data) {
return makeMessage(id, data, localFlags);
});
}
std::vector<not_null<HistoryItem*>> History::createItems(
@ -3080,7 +3082,7 @@ MsgRange History::rangeForDifferenceRequest() const {
return MsgRange();
}
HistoryService *History::insertJoinedMessage() {
HistoryItem *History::insertJoinedMessage() {
const auto channel = peer->asChannel();
if (!channel
|| _joinedMessage

View File

@ -19,8 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class History;
class HistoryBlock;
class HistoryItem;
class HistoryMessage;
class HistoryService;
struct HistoryMessageMarkupData;
class HistoryMainElementDelegateMixin;
@ -126,22 +124,14 @@ public:
void applyGroupAdminChanges(const base::flat_set<UserId> &changes);
template <typename ...Args>
not_null<HistoryMessage*> makeMessage(Args &&...args) {
return static_cast<HistoryMessage*>(
not_null<HistoryItem*> makeMessage(Args &&...args) {
return static_cast<HistoryItem*>(
insertItem(
std::make_unique<HistoryMessage>(
std::make_unique<HistoryItem>(
this,
std::forward<Args>(args)...)).get());
}
template <typename ...Args>
not_null<HistoryService*> makeServiceMessage(Args &&...args) {
return static_cast<HistoryService*>(
insertItem(
std::make_unique<HistoryService>(
this,
std::forward<Args>(args)...)).get());
}
void destroyMessage(not_null<HistoryItem*> item);
void destroyMessagesByDates(TimeId minDate, TimeId maxDate);
void destroyMessagesByTopic(MsgId topicRootId);
@ -577,7 +567,7 @@ private:
void createLocalDraftFromCloud(MsgId topicRootId);
HistoryService *insertJoinedMessage();
HistoryItem *insertJoinedMessage();
void insertMessageToBlocks(not_null<HistoryItem*> item);
[[nodiscard]] Dialogs::BadgesState computeBadgesState() const;
@ -598,7 +588,7 @@ private:
int _height = 0;
Element *_unreadBarView = nullptr;
Element *_firstUnreadView = nullptr;
HistoryService *_joinedMessage = nullptr;
HistoryItem *_joinedMessage = nullptr;
bool _loadedAtTop = false;
bool _loadedAtBottom = true;

View File

@ -11,7 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/crash_reports.h"
#include "core/click_handler_types.h"
#include "history/history.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "history/view/media/history_view_media.h"
#include "history/view/media/history_view_sticker.h"
#include "history/view/media/history_view_web_page.h"
@ -145,22 +146,6 @@ public:
HistoryView::Context elementContext() override {
return HistoryView::Context::History;
}
std::unique_ptr<Element> elementCreate(
not_null<HistoryMessage*> message,
Element *replacing = nullptr) override {
return std::make_unique<HistoryView::Message>(
this,
message,
replacing);
}
std::unique_ptr<HistoryView::Element> elementCreate(
not_null<HistoryService*> message,
Element *replacing = nullptr) override {
return std::make_unique<HistoryView::Service>(
this,
message,
replacing);
}
bool elementUnderCursor(
not_null<const Element*> view) override {
return (Element::Moused() == view);

File diff suppressed because it is too large Load Diff

View File

@ -15,9 +15,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <any>
class HiddenSenderInfo;
class History;
struct HistoryMessageReply;
struct HistoryMessageViews;
struct HistoryMessageMarkupData;
struct HistoryMessageReplyMarkup;
struct HistoryServiceDependentData;
enum class HistorySelfDestructType;
struct PreparedServiceText;
class ReplyKeyboard;
class HistoryMessage;
namespace base {
template <typename Enum>
@ -47,6 +54,7 @@ struct MessageReaction;
class MessageReactions;
class ForumTopic;
class Thread;
struct SponsoredFrom;
} // namespace Data
namespace Main {
@ -68,46 +76,120 @@ enum class CursorState : char;
enum class PointState : char;
enum class Context : char;
class ElementDelegate;
class Element;
class Message;
class Service;
class ServiceMessagePainter;
} // namespace HistoryView
class HiddenSenderInfo;
class History;
[[nodiscard]] MessageFlags FlagsFromMTP(
MsgId id,
MTPDmessage::Flags flags,
MessageFlags localFlags);
[[nodiscard]] MessageFlags FlagsFromMTP(
MsgId id,
MTPDmessageService::Flags flags,
MessageFlags localFlags);
class HistoryItem : public RuntimeComposer<HistoryItem> {
class HistoryItem final : public RuntimeComposer<HistoryItem> {
public:
static not_null<HistoryItem*> Create(
[[nodiscard]] static std::unique_ptr<Data::Media> CreateMedia(
not_null<HistoryItem*> item,
const MTPMessageMedia &media);
HistoryItem(
not_null<History*> history,
MsgId id,
const MTPMessage &message,
const MTPDmessage &data,
MessageFlags localFlags);
HistoryItem(
not_null<History*> history,
MsgId id,
const MTPDmessageService &data,
MessageFlags localFlags);
HistoryItem(
not_null<History*> history,
MsgId id,
const MTPDmessageEmpty &data,
MessageFlags localFlags);
HistoryItem( // Sponsored message.
not_null<History*> history,
MsgId id,
Data::SponsoredFrom from,
const TextWithEntities &textWithEntities,
HistoryItem *injectedAfter);
HistoryItem( // Local message.
not_null<History*> history,
MsgId id,
MessageFlags flags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
const QString &postAuthor,
const TextWithEntities &textWithEntities,
const MTPMessageMedia &media,
HistoryMessageMarkupData &&markup,
uint64 groupedId);
HistoryItem( // Local service message.
not_null<History*> history,
MsgId id,
MessageFlags flags,
TimeId date,
PreparedServiceText &&message,
PeerId from = 0,
PhotoData *photo = nullptr);
HistoryItem( // Local forwarded.
not_null<History*> history,
MsgId id,
MessageFlags flags,
TimeId date,
PeerId from,
const QString &postAuthor,
not_null<HistoryItem*> original,
MsgId topicRootId);
HistoryItem( // Local photo.
not_null<History*> history,
MsgId id,
MessageFlags flags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
const QString &postAuthor,
not_null<PhotoData*> photo,
const TextWithEntities &caption,
HistoryMessageMarkupData &&markup);
HistoryItem( // Local document.
not_null<History*> history,
MsgId id,
MessageFlags flags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
const QString &postAuthor,
not_null<DocumentData*> document,
const TextWithEntities &caption,
HistoryMessageMarkupData &&markup);
HistoryItem( // Local game.
not_null<History*> history,
MsgId id,
MessageFlags flags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
const QString &postAuthor,
not_null<GameData*> game,
HistoryMessageMarkupData &&markup);
~HistoryItem();
struct Destroyer {
void operator()(HistoryItem *value);
};
virtual void dependencyItemRemoved(HistoryItem *dependency) {
}
virtual bool updateDependencyItem() {
return true;
}
virtual MsgId dependencyMsgId() const {
return 0;
}
virtual void checkBuyButton() {
}
[[nodiscard]] virtual bool notificationReady() const {
return true;
}
void dependencyItemRemoved(not_null<HistoryItem*> dependency);
void updateDependencyItem();
[[nodiscard]] MsgId dependencyMsgId() const;
[[nodiscard]] bool notificationReady() const;
[[nodiscard]] PeerData *specialNotificationPeer() const;
void checkBuyButton();
void updateServiceText(PreparedServiceText &&text);
[[nodiscard]] UserData *viaBot() const;
[[nodiscard]] UserData *getMessageBot() const;
@ -165,15 +247,13 @@ public:
void setIsPinned(bool isPinned);
// For edit media in history_message.
virtual void returnSavedMedia();
void returnSavedMedia();
void savePreviousMedia();
[[nodiscard]] bool isEditingMedia() const;
void clearSavedMedia();
// Zero result means this message is not self-destructing right now.
virtual crl::time getSelfDestructIn(crl::time now) {
return 0;
}
[[nodiscard]] crl::time getSelfDestructIn(crl::time now);
[[nodiscard]] bool definesReplyKeyboard() const;
[[nodiscard]] ReplyMarkupFlags replyKeyboardFlags() const;
@ -224,118 +304,75 @@ public:
[[nodiscard]] bool isRegular() const;
[[nodiscard]] bool isUploading() const;
void sendFailed();
[[nodiscard]] virtual int viewsCount() const {
return hasViews() ? 1 : -1;
}
[[nodiscard]] virtual int repliesCount() const {
return 0;
}
[[nodiscard]] virtual bool repliesAreComments() const {
return false;
}
[[nodiscard]] virtual bool externalReply() const {
return false;
}
[[nodiscard]] int viewsCount() const;
[[nodiscard]] int repliesCount() const;
[[nodiscard]] bool repliesAreComments() const;
[[nodiscard]] bool externalReply() const;
[[nodiscard]] bool hasExtendedMediaPreview() const;
virtual void setCommentsInboxReadTill(MsgId readTillId) {
}
virtual void setCommentsMaxId(MsgId maxId) {
}
virtual void setCommentsPossibleMaxId(MsgId possibleMaxId) {
}
[[nodiscard]] virtual bool areCommentsUnread() const {
return false;
}
void setCommentsInboxReadTill(MsgId readTillId);
void setCommentsMaxId(MsgId maxId);
void setCommentsPossibleMaxId(MsgId possibleMaxId);
[[nodiscard]] bool areCommentsUnread() const;
[[nodiscard]] virtual FullMsgId commentsItemId() const {
return FullMsgId();
}
virtual void setCommentsItemId(FullMsgId id) {
}
[[nodiscard]] FullMsgId commentsItemId() const;
void setCommentsItemId(FullMsgId id);
[[nodiscard]] virtual bool needCheck() const;
[[nodiscard]] bool needCheck() const;
[[nodiscard]] virtual bool isService() const {
return false;
}
virtual void applyEdition(HistoryMessageEdition &&edition) {
}
virtual void applyEdition(const MTPDmessageService &message) {
}
virtual void applyEdition(const MTPMessageExtendedMedia &media) {
}
void applyEditionToHistoryCleared();
virtual void updateSentContent(
[[nodiscard]] bool isService() const;
void applyEdition(HistoryMessageEdition &&edition);
void applyEdition(const MTPDmessageService &message);
void applyEdition(const MTPMessageExtendedMedia &media);
void updateForwardedInfo(const MTPMessageFwdHeader *fwd);
void updateSentContent(
const TextWithEntities &textWithEntities,
const MTPMessageMedia *media) {
}
virtual void updateReplyMarkup(HistoryMessageMarkupData &&markup) {
}
virtual void updateForwardedInfo(const MTPMessageFwdHeader *fwd) {
}
virtual void contributeToSlowmode(TimeId realDate = 0) {
}
virtual void addToUnreadThings(HistoryUnreadThings::AddType type);
virtual void destroyHistoryEntry() {
}
[[nodiscard]] virtual Storage::SharedMediaTypesMask sharedMediaTypes() const = 0;
virtual void applySentMessage(const MTPDmessage &data);
virtual void applySentMessage(
const MTPMessageMedia *media);
void applySentMessage(const MTPDmessage &data);
void applySentMessage(
const QString &text,
const MTPDupdateShortSentMessage &data,
bool wasAlready);
void updateReactions(const MTPMessageReactions *reactions);
void applyEditionToHistoryCleared();
void updateReplyMarkup(HistoryMessageMarkupData &&markup);
void contributeToSlowmode(TimeId realDate = 0);
void addToUnreadThings(HistoryUnreadThings::AddType type);
void destroyHistoryEntry();
[[nodiscard]] Storage::SharedMediaTypesMask sharedMediaTypes() const;
void indexAsNewItem();
[[nodiscard]] virtual QString notificationHeader() const {
return QString();
}
[[nodiscard]] virtual TextWithEntities notificationText() const;
[[nodiscard]] QString notificationHeader() const;
[[nodiscard]] TextWithEntities notificationText() const;
using ToPreviewOptions = HistoryView::ToPreviewOptions;
using ItemPreview = HistoryView::ItemPreview;
// Returns text with link-start and link-end commands for service-color highlighting.
// Example: "[link1-start]You:[link1-end] [link1-start]Photo,[link1-end] caption text"
[[nodiscard]] virtual ItemPreview toPreview(
ToPreviewOptions options) const;
[[nodiscard]] virtual TextWithEntities inReplyText() const;
[[nodiscard]] virtual TextWithEntities originalText() const {
return TextWithEntities();
}
[[nodiscard]] virtual auto originalTextWithLocalEntities() const
-> TextWithEntities {
return TextWithEntities();
}
[[nodiscard]] virtual auto customTextLinks() const
-> const std::vector<ClickHandlerPtr> &;
[[nodiscard]] virtual TextForMimeData clipboardText() const {
return TextForMimeData();
}
[[nodiscard]] ItemPreview toPreview(ToPreviewOptions options) const;
[[nodiscard]] TextWithEntities inReplyText() const;
[[nodiscard]] TextWithEntities originalText() const;
[[nodiscard]] TextWithEntities originalTextWithLocalEntities() const;
[[nodiscard]] const std::vector<ClickHandlerPtr> &customTextLinks() const;
[[nodiscard]] TextForMimeData clipboardText() const;
virtual bool changeViewsCount(int count) {
return false;
}
virtual void setForwardsCount(int count) {
}
virtual void setReplies(HistoryMessageRepliesData &&data) {
}
virtual void clearReplies() {
}
virtual void changeRepliesCount(int delta, PeerId replier) {
}
virtual void setReplyFields(
bool changeViewsCount(int count);
void setForwardsCount(int count);
void setReplies(HistoryMessageRepliesData &&data);
void clearReplies();
void changeRepliesCount(int delta, PeerId replier);
void setReplyFields(
MsgId replyTo,
MsgId replyToTop,
bool isForumPost) = 0;
virtual void setPostAuthor(const QString &author) {
}
virtual void setRealId(MsgId newId);
virtual void incrementReplyToTopCounter() {
}
bool isForumPost);
void setPostAuthor(const QString &author);
void setRealId(MsgId newId);
void incrementReplyToTopCounter();
[[nodiscard]] bool emptyText() const {
return _text.empty();
@ -346,9 +383,9 @@ public:
[[nodiscard]] bool canStopPoll() const;
[[nodiscard]] bool forbidsForward() const;
[[nodiscard]] bool forbidsSaving() const;
[[nodiscard]] virtual bool allowsSendNow() const;
[[nodiscard]] virtual bool allowsForward() const;
[[nodiscard]] virtual bool allowsEdit(TimeId now) const;
[[nodiscard]] bool allowsSendNow() const;
[[nodiscard]] bool allowsForward() const;
[[nodiscard]] bool allowsEdit(TimeId now) const;
[[nodiscard]] bool canDelete() const;
[[nodiscard]] bool canDeleteForEveryone(TimeId now) const;
[[nodiscard]] bool suggestReport() const;
@ -364,7 +401,6 @@ public:
void toggleReaction(
const Data::ReactionId &reaction,
ReactionSource source);
void updateReactions(const MTPMessageReactions *reactions);
void updateReactionsUnknown();
[[nodiscard]] auto reactions() const
-> const std::vector<Data::MessageReaction> &;
@ -391,12 +427,11 @@ public:
return _media.get();
}
[[nodiscard]] bool computeDropForwardedInfo() const;
virtual void setText(const TextWithEntities &textWithEntities) {
}
void setText(const TextWithEntities &textWithEntities);
[[nodiscard]] virtual MsgId replyToId() const = 0;
[[nodiscard]] virtual MsgId replyToTop() const = 0;
[[nodiscard]] virtual MsgId topicRootId() const = 0;
[[nodiscard]] MsgId replyToId() const;
[[nodiscard]] MsgId replyToTop() const;
[[nodiscard]] MsgId topicRootId() const;
[[nodiscard]] bool inThread(MsgId rootId) const;
[[nodiscard]] not_null<PeerData*> author() const;
@ -426,9 +461,9 @@ public:
[[nodiscard]] HistoryItem *lookupDiscussionPostOriginal() const;
[[nodiscard]] PeerData *displayFrom() const;
[[nodiscard]] virtual std::unique_ptr<HistoryView::Element> createView(
[[nodiscard]] std::unique_ptr<HistoryView::Element> createView(
not_null<HistoryView::ElementDelegate*> delegate,
HistoryView::Element *replacing = nullptr) = 0;
HistoryView::Element *replacing = nullptr);
void updateDate(TimeId newDate);
[[nodiscard]] bool canUpdateDate() const;
@ -438,11 +473,16 @@ public:
return _ttlDestroyAt;
}
virtual ~HistoryItem();
MsgId id;
protected:
private:
struct CreateConfig;
struct SavedMediaData {
TextWithEntities text;
std::unique_ptr<Data::Media> media;
};
HistoryItem(
not_null<History*> history,
MsgId id,
@ -450,63 +490,113 @@ protected:
TimeId date,
PeerId from);
virtual void markMediaAsReadHook() {
void createComponentsHelper(
MessageFlags flags,
MsgId replyTo,
UserId viaBotId,
const QString &postAuthor,
HistoryMessageMarkupData &&markup);
void createComponents(CreateConfig &&config);
void setupForwardedComponent(const CreateConfig &config);
[[nodiscard]] bool generateLocalEntitiesByReply() const;
[[nodiscard]] TextWithEntities withLocalEntities(
const TextWithEntities &textWithEntities) const;
void setTextValue(TextWithEntities text);
[[nodiscard]] bool isTooOldForEdit(TimeId now) const;
[[nodiscard]] bool isLegacyMessage() const {
return _flags & MessageFlag::Legacy;
}
void applyServiceDateEdition(const MTPDmessageService &data);
[[nodiscard]] bool checkCommentsLinkedChat(ChannelId id) const;
void setReplyMarkup(HistoryMessageMarkupData &&markup);
void changeReplyToTopCounter(
not_null<HistoryMessageReply*> reply,
int delta);
void refreshRepliesText(
not_null<HistoryMessageViews*> views,
bool forceResize = false);
[[nodiscard]] bool checkRepliesPts(
const HistoryMessageRepliesData &data) const;
[[nodiscard]] HistoryServiceDependentData *GetServiceDependentData();
[[nodiscard]] auto GetServiceDependentData() const
-> const HistoryServiceDependentData *;
void updateDependentServiceText();
bool updateServiceDependent(bool force = false);
void setServiceText(PreparedServiceText &&prepared);
void finishEdition(int oldKeyboardTop);
void finishEditionToEmpty();
void clearDependencyMessage();
void setupChatThemeChange();
void setupTTLChange();
void setSelfDestruct(HistorySelfDestructType type, int ttlSeconds);
TextWithEntities fromLinkText() const;
ClickHandlerPtr fromLink() const;
void setGroupId(MessageGroupId groupId);
static void FillForwardedInfo(
CreateConfig &config,
const MTPDmessageFwdHeader &data);
void createComponents(const MTPDmessage &data);
void setMedia(const MTPMessageMedia &media);
void applyServiceDateEdition(const MTPDmessageService &data);
void setReactions(const MTPMessageReactions *reactions);
[[nodiscard]] bool changeReactions(const MTPMessageReactions *reactions);
void setServiceMessageByAction(const MTPmessageAction &action);
void applyAction(const MTPMessageAction &action);
void refreshMedia(const MTPMessageMedia *media);
void refreshSentMedia(const MTPMessageMedia *media);
void createServiceFromMtp(const MTPDmessage &message);
void createServiceFromMtp(const MTPDmessageService &message);
void applyTTL(const MTPDmessage &data);
void applyTTL(const MTPDmessageService &data);
void applyTTL(TimeId destroyAt);
// For an invoice button we replace the button text with a "Receipt" key.
// It should show the receipt for the payed invoice. Still let mobile apps do that.
void replaceBuyWithReceiptInMarkup();
void setSponsoredFrom(const Data::SponsoredFrom &from);
[[nodiscard]] PreparedServiceText preparePinnedText();
[[nodiscard]] PreparedServiceText prepareGameScoreText();
[[nodiscard]] PreparedServiceText preparePaymentSentText();
[[nodiscard]] PreparedServiceText prepareInvitedToCallText(
const std::vector<not_null<UserData*>> &users,
CallId linkCallId);
[[nodiscard]] PreparedServiceText prepareCallScheduledText(
TimeId scheduleDate);
const not_null<History*> _history;
const not_null<PeerData*> _from;
MessageFlags _flags = 0;
void setGroupId(MessageGroupId groupId);
void applyTTL(const MTPDmessage &data);
void applyTTL(const MTPDmessageService &data);
void applyTTL(TimeId destroyAt);
TextWithEntities _text;
struct SavedMediaData {
TextWithEntities text;
std::unique_ptr<Data::Media> media;
};
std::unique_ptr<SavedMediaData> _savedLocalEditMediaData;
std::unique_ptr<Data::Media> _media;
std::unique_ptr<Data::MessageReactions> _reactions;
crl::time _reactionsLastRefreshed = 0;
private:
TimeId _date = 0;
TimeId _ttlDestroyAt = 0;
HistoryView::Element *_mainView = nullptr;
friend class HistoryView::Element;
MessageGroupId _groupId = MessageGroupId();
friend class HistoryView::Element;
friend class HistoryView::Message;
friend class HistoryView::Service;
friend class HistoryView::ServiceMessagePainter;
};
[[nodiscard]] Main::Session *SessionByUniqueId(uint64 sessionUniqueId);
[[nodiscard]] HistoryItem *MessageByGlobalId(GlobalMsgId globalId);
[[nodiscard]] QDateTime ItemDateTime(not_null<const HistoryItem*> item);
[[nodiscard]] QString ItemDateText(
not_null<const HistoryItem*> item,
bool isUntilOnline);
[[nodiscard]] bool IsItemScheduledUntilOnline(
not_null<const HistoryItem*> item);
ClickHandlerPtr goToMessageClickHandler(
not_null<PeerData*> peer,
MsgId msgId,
FullMsgId returnToId = FullMsgId());
ClickHandlerPtr goToMessageClickHandler(
not_null<HistoryItem*> item,
FullMsgId returnToId = FullMsgId());

View File

@ -18,7 +18,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/chat_theme.h"
#include "ui/painter.h"
#include "history/history.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "history/view/history_view_message.h" // FromNameFg.
#include "history/view/history_view_service_message.h"
#include "history/view/media/history_view_document.h"
@ -244,7 +245,7 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
text.setMarkedText(st::fwdTextStyle, phrase);
text.setLink(1, fromChannel
? goToMessageClickHandler(originalSender, originalId)
? JumpToMessageClickHandler(originalSender, originalId)
: originalSender
? originalSender->openLink()
: HiddenSenderInfo::ForwardClickHandler());
@ -254,7 +255,7 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
}
bool HistoryMessageReply::updateData(
not_null<HistoryMessage*> holder,
not_null<HistoryItem*> holder,
bool force) {
const auto guard = gsl::finally([&] { refreshReplyToMedia(); });
if (!force) {
@ -322,13 +323,13 @@ bool HistoryMessageReply::updateData(
}
void HistoryMessageReply::setReplyToLinkFrom(
not_null<HistoryMessage*> holder) {
not_null<HistoryItem*> holder) {
replyToLnk = replyToMsg
? goToMessageClickHandler(replyToMsg.get(), holder->fullId())
? JumpToMessageClickHandler(replyToMsg.get(), holder->fullId())
: nullptr;
}
void HistoryMessageReply::clearData(not_null<HistoryMessage*> holder) {
void HistoryMessageReply::clearData(not_null<HistoryItem*> holder) {
replyToVia = nullptr;
if (replyToMsg) {
holder->history()->owner().unregisterDependentMessage(
@ -341,7 +342,7 @@ void HistoryMessageReply::clearData(not_null<HistoryMessage*> holder) {
}
PeerData *HistoryMessageReply::replyToFrom(
not_null<HistoryMessage*> holder) const {
not_null<HistoryItem*> holder) const {
if (!replyToMsg) {
return nullptr;
} else if (holder->Has<HistoryMessageForwarded>()) {
@ -356,7 +357,7 @@ PeerData *HistoryMessageReply::replyToFrom(
}
QString HistoryMessageReply::replyToFromName(
not_null<HistoryMessage*> holder) const {
not_null<HistoryItem*> holder) const {
if (!replyToMsg) {
return QString();
} else if (holder->Has<HistoryMessageForwarded>()) {
@ -381,7 +382,7 @@ QString HistoryMessageReply::replyToFromName(
}
bool HistoryMessageReply::isNameUpdated(
not_null<HistoryMessage*> holder) const {
not_null<HistoryItem*> holder) const {
if (const auto from = replyToFrom(holder)) {
if (replyToVersion < from->nameVersion()) {
updateName(holder);
@ -392,7 +393,7 @@ bool HistoryMessageReply::isNameUpdated(
}
void HistoryMessageReply::updateName(
not_null<HistoryMessage*> holder) const {
not_null<HistoryItem*> holder) const {
if (const auto name = replyToFromName(holder); !name.isEmpty()) {
replyToName.setText(st::fwdTextStyle, name, Ui::NameTextOptions());
if (const auto from = replyToFrom(holder)) {
@ -423,7 +424,7 @@ void HistoryMessageReply::resize(int width) const {
}
void HistoryMessageReply::itemRemoved(
HistoryMessage *holder,
HistoryItem *holder,
HistoryItem *removed) {
if (replyToMsg.get() == removed) {
clearData(holder);

View File

@ -195,20 +195,19 @@ struct HistoryMessageReply
Expects(replyToVia == nullptr);
}
bool updateData(not_null<HistoryMessage*> holder, bool force = false);
bool updateData(not_null<HistoryItem*> holder, bool force = false);
// Must be called before destructor.
void clearData(not_null<HistoryMessage*> holder);
void clearData(not_null<HistoryItem*> holder);
[[nodiscard]] PeerData *replyToFrom(
not_null<HistoryMessage*> holder) const;
[[nodiscard]] PeerData *replyToFrom(not_null<HistoryItem*> holder) const;
[[nodiscard]] QString replyToFromName(
not_null<HistoryMessage*> holder) const;
not_null<HistoryItem*> holder) const;
[[nodiscard]] QString replyToFromName(not_null<PeerData*> peer) const;
[[nodiscard]] bool isNameUpdated(not_null<HistoryMessage*> holder) const;
void updateName(not_null<HistoryMessage*> holder) const;
[[nodiscard]] bool isNameUpdated(not_null<HistoryItem*> holder) const;
void updateName(not_null<HistoryItem*> holder) const;
void resize(int width) const;
void itemRemoved(HistoryMessage *holder, HistoryItem *removed);
void itemRemoved(HistoryItem *holder, HistoryItem *removed);
void paint(
Painter &p,
@ -234,8 +233,7 @@ struct HistoryMessageReply
[[nodiscard]] ClickHandlerPtr replyToLink() const {
return replyToLnk;
}
void setReplyToLinkFrom(
not_null<HistoryMessage*> holder);
void setReplyToLinkFrom(not_null<HistoryItem*> holder);
void refreshReplyToMedia();
@ -452,7 +450,7 @@ private:
// Special type of Component for the channel actions log.
struct HistoryMessageLogEntryOriginal
: public RuntimeComponent<HistoryMessageLogEntryOriginal, HistoryItem> {
: public RuntimeComponent<HistoryMessageLogEntryOriginal, HistoryItem> {
HistoryMessageLogEntryOriginal();
HistoryMessageLogEntryOriginal(HistoryMessageLogEntryOriginal &&other);
HistoryMessageLogEntryOriginal &operator=(HistoryMessageLogEntryOriginal &&other);
@ -462,6 +460,94 @@ struct HistoryMessageLogEntryOriginal
};
struct HistoryServiceData
: public RuntimeComponent<HistoryServiceData, HistoryItem> {
std::vector<ClickHandlerPtr> textLinks;
};
struct HistoryServiceDependentData {
PeerId peerId = 0;
HistoryItem *msg = nullptr;
ClickHandlerPtr lnk;
MsgId msgId = 0;
MsgId topId = 0;
bool topicPost = false;
};
struct HistoryServicePinned
: public RuntimeComponent<HistoryServicePinned, HistoryItem>
, public HistoryServiceDependentData {
};
struct HistoryServiceTopicInfo
: public RuntimeComponent<HistoryServiceTopicInfo, HistoryItem>
, public HistoryServiceDependentData {
QString title;
DocumentId iconId = 0;
bool closed = false;
bool reopened = false;
bool reiconed = false;
bool renamed = false;
bool hidden = false;
bool unhidden = false;
[[nodiscard]] bool created() const {
return !closed
&& !reopened
&& !reiconed
&& !renamed
&& !hidden
&& !unhidden;
}
};
struct HistoryServiceGameScore
: public RuntimeComponent<HistoryServiceGameScore, HistoryItem>
, public HistoryServiceDependentData {
int score = 0;
};
struct HistoryServicePayment
: public RuntimeComponent<HistoryServicePayment, HistoryItem>
, public HistoryServiceDependentData {
QString slug;
QString amount;
ClickHandlerPtr invoiceLink;
bool recurringInit = false;
bool recurringUsed = false;
};
enum class HistorySelfDestructType {
Photo,
Video,
};
struct HistoryServiceSelfDestruct
: public RuntimeComponent<HistoryServiceSelfDestruct, HistoryItem> {
using Type = HistorySelfDestructType;
Type type = Type::Photo;
crl::time timeToLive = 0;
crl::time destructAt = 0;
};
struct HistoryServiceOngoingCall
: public RuntimeComponent<HistoryServiceOngoingCall, HistoryItem> {
CallId id = 0;
ClickHandlerPtr link;
rpl::lifetime lifetime;
};
struct HistoryServiceChatThemeChange
: public RuntimeComponent<HistoryServiceChatThemeChange, HistoryItem> {
ClickHandlerPtr link;
};
struct HistoryServiceTTLChange
: public RuntimeComponent<HistoryServiceTTLChange, HistoryItem> {
ClickHandlerPtr link;
};
class FileClickHandler;
struct HistoryDocumentThumbed : public RuntimeComponent<HistoryDocumentThumbed, HistoryView::Document> {
std::shared_ptr<FileClickHandler> linksavel;

View File

@ -0,0 +1,656 @@
/*
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
*/
#include "history/history_item_helpers.h"
#include "calls/calls_instance.h"
#include "data/notify/data_notify_settings.h"
#include "data/data_chat_participant_status.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_changes.h"
#include "data/data_group_call.h"
#include "data/data_forum.h"
#include "data/data_forum_topic.h"
#include "data/data_media_types.h"
#include "data/data_message_reactions.h"
#include "data/data_scheduled_messages.h"
#include "data/data_session.h"
#include "data/data_user.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "main/main_account.h"
#include "main/main_domain.h"
#include "main/main_session.h"
#include "main/main_session_settings.h"
#include "window/window_controller.h"
#include "window/window_session_controller.h"
#include "apiwrap.h"
#include "base/unixtime.h"
#include "core/application.h"
#include "ui/text/format_values.h"
#include "ui/text/text_utilities.h"
#include "ui/text/text_entity.h"
#include "ui/item_text_options.h"
#include "lang/lang_keys.h"
namespace {
[[nodiscard]] bool HasInlineItems(const HistoryItemsList &items) {
for (const auto &item : items) {
if (item->viaBot()) {
return true;
}
}
return false;
}
bool PeerCallKnown(not_null<PeerData*> peer) {
if (peer->groupCall() != nullptr) {
return true;
} else if (const auto chat = peer->asChat()) {
return !(chat->flags() & ChatDataFlag::CallActive);
} else if (const auto channel = peer->asChannel()) {
return !(channel->flags() & ChannelDataFlag::CallActive);
}
return true;
}
} // namespace
QString GetErrorTextForSending(
not_null<PeerData*> peer,
SendingErrorRequest request) {
const auto forum = request.topicRootId ? peer->forum() : nullptr;
const auto topic = forum
? forum->topicFor(request.topicRootId)
: nullptr;
if (!(topic ? topic->canWrite() : peer->canWrite())) {
return tr::lng_forward_cant(tr::now);
}
if (request.forward) {
for (const auto &item : *request.forward) {
if (const auto media = item->media()) {
const auto error = media->errorTextForForward(peer);
if (!error.isEmpty() && error != u"skip"_q) {
return error;
}
}
}
}
const auto error = Data::RestrictionError(
peer,
ChatRestriction::SendInline);
if (error && request.forward && HasInlineItems(*request.forward)) {
return *error;
}
if (peer->slowmodeApplied()) {
const auto hasText = (request.text && !request.text->empty());
const auto count = (hasText ? 1 : 0)
+ (request.forward ? int(request.forward->size()) : 0);
if (const auto history = peer->owner().historyLoaded(peer)) {
if (!request.ignoreSlowmodeCountdown
&& (history->latestSendingMessage() != nullptr)
&& (count > 0)) {
return tr::lng_slowmode_no_many(tr::now);
}
}
if (request.text && request.text->text.size() > MaxMessageSize) {
return tr::lng_slowmode_too_long(tr::now);
} else if (hasText && count > 1) {
return tr::lng_slowmode_no_many(tr::now);
} else if (count > 1) {
const auto albumForward = [&] {
const auto first = request.forward->front();
if (const auto groupId = first->groupId()) {
for (const auto &item : *request.forward) {
if (item->groupId() != groupId) {
return false;
}
}
return true;
}
return false;
}();
if (!albumForward) {
return tr::lng_slowmode_no_many(tr::now);
}
}
}
if (const auto left = peer->slowmodeSecondsLeft()) {
if (!request.ignoreSlowmodeCountdown) {
return tr::lng_slowmode_enabled(
tr::now,
lt_left,
Ui::FormatDurationWordsSlowmode(left));
}
}
return QString();
}
QString GetErrorTextForSending(
not_null<Data::Thread*> thread,
SendingErrorRequest request) {
request.topicRootId = thread->topicRootId();
return GetErrorTextForSending(thread->peer(), std::move(request));
}
void RequestDependentMessageData(
not_null<HistoryItem*> item,
PeerId peerId,
MsgId msgId) {
if (!IsServerMsgId(msgId)) {
return;
}
const auto fullId = item->fullId();
const auto history = item->history();
const auto session = &history->session();
const auto done = [=] {
if (const auto item = session->data().message(fullId)) {
item->updateDependencyItem();
}
};
history->session().api().requestMessageData(
(peerId ? history->owner().peer(peerId) : history->peer),
msgId,
done);
}
MessageFlags NewMessageFlags(not_null<PeerData*> peer) {
return MessageFlag::BeingSent
| (peer->isSelf() ? MessageFlag() : MessageFlag::Outgoing);
}
bool ShouldSendSilent(
not_null<PeerData*> peer,
const Api::SendOptions &options) {
return options.silent
|| (peer->isBroadcast()
&& peer->owner().notifySettings().silentPosts(peer))
|| (peer->session().supportMode()
&& peer->session().settings().supportAllSilent());
}
HistoryItem *LookupReplyTo(not_null<History*> history, MsgId replyToId) {
const auto &owner = history->owner();
return owner.message(history->peer, replyToId);
}
MsgId LookupReplyToTop(HistoryItem *replyTo) {
return replyTo ? replyTo->replyToTop() : 0;
}
bool LookupReplyIsTopicPost(HistoryItem *replyTo) {
return replyTo
&& (replyTo->topicRootId() != Data::ForumTopic::kGeneralId);
}
TextWithEntities DropCustomEmoji(TextWithEntities text) {
text.entities.erase(
ranges::remove(
text.entities,
EntityType::CustomEmoji,
&EntityInText::type),
text.entities.end());
return text;
}
Main::Session *SessionByUniqueId(uint64 sessionUniqueId) {
if (!sessionUniqueId) {
return nullptr;
}
for (const auto &[index, account] : Core::App().domain().accounts()) {
if (const auto session = account->maybeSession()) {
if (session->uniqueId() == sessionUniqueId) {
return session;
}
}
}
return nullptr;
}
HistoryItem *MessageByGlobalId(GlobalMsgId globalId) {
const auto sessionId = globalId.itemId ? globalId.sessionUniqueId : 0;
if (const auto session = SessionByUniqueId(sessionId)) {
return session->data().message(globalId.itemId);
}
return nullptr;
}
QDateTime ItemDateTime(not_null<const HistoryItem*> item) {
return base::unixtime::parse(item->date());
}
QString ItemDateText(not_null<const HistoryItem*> item, bool isUntilOnline) {
const auto dateText = langDayOfMonthFull(ItemDateTime(item).date());
return !item->isScheduled()
? dateText
: isUntilOnline
? tr::lng_scheduled_date_until_online(tr::now)
: tr::lng_scheduled_date(tr::now, lt_date, dateText);
}
bool IsItemScheduledUntilOnline(not_null<const HistoryItem*> item) {
return item->isScheduled()
&& (item->date() ==
Data::ScheduledMessages::kScheduledUntilOnlineTimestamp);
}
ClickHandlerPtr JumpToMessageClickHandler(
not_null<HistoryItem*> item,
FullMsgId returnToId) {
return JumpToMessageClickHandler(
item->history()->peer,
item->id,
returnToId);
}
ClickHandlerPtr JumpToMessageClickHandler(
not_null<PeerData*> peer,
MsgId msgId,
FullMsgId returnToId) {
return std::make_shared<LambdaClickHandler>([=] {
const auto separate = Core::App().separateWindowForPeer(peer);
const auto controller = separate
? separate->sessionController()
: peer->session().tryResolveWindow();
if (controller) {
auto params = Window::SectionShow{
Window::SectionShow::Way::Forward
};
params.origin = Window::SectionShow::OriginMessage{
returnToId
};
if (const auto item = peer->owner().message(peer, msgId)) {
controller->showMessage(item, params);
} else {
controller->showPeerHistory(peer, params, msgId);
}
}
});
}
MessageFlags FlagsFromMTP(
MsgId id,
MTPDmessage::Flags flags,
MessageFlags localFlags) {
using Flag = MessageFlag;
using MTP = MTPDmessage::Flag;
return localFlags
| (IsServerMsgId(id) ? Flag::HistoryEntry : Flag())
| ((flags & MTP::f_out) ? Flag::Outgoing : Flag())
| ((flags & MTP::f_mentioned) ? Flag::MentionsMe : Flag())
| ((flags & MTP::f_media_unread) ? Flag::MediaIsUnread : Flag())
| ((flags & MTP::f_silent) ? Flag::Silent : Flag())
| ((flags & MTP::f_post) ? Flag::Post : Flag())
| ((flags & MTP::f_legacy) ? Flag::Legacy : Flag())
| ((flags & MTP::f_edit_hide) ? Flag::HideEdited : Flag())
| ((flags & MTP::f_pinned) ? Flag::Pinned : Flag())
| ((flags & MTP::f_from_id) ? Flag::HasFromId : Flag())
| ((flags & MTP::f_reply_to) ? Flag::HasReplyInfo : Flag())
| ((flags & MTP::f_reply_markup) ? Flag::HasReplyMarkup : Flag())
| ((flags & MTP::f_from_scheduled) ? Flag::IsOrWasScheduled : Flag())
| ((flags & MTP::f_views) ? Flag::HasViews : Flag())
| ((flags & MTP::f_noforwards) ? Flag::NoForwards : Flag());
}
MessageFlags FlagsFromMTP(
MsgId id,
MTPDmessageService::Flags flags,
MessageFlags localFlags) {
using Flag = MessageFlag;
using MTP = MTPDmessageService::Flag;
return localFlags
| (IsServerMsgId(id) ? Flag::HistoryEntry : Flag())
| ((flags & MTP::f_out) ? Flag::Outgoing : Flag())
| ((flags & MTP::f_mentioned) ? Flag::MentionsMe : Flag())
| ((flags & MTP::f_media_unread) ? Flag::MediaIsUnread : Flag())
| ((flags & MTP::f_silent) ? Flag::Silent : Flag())
| ((flags & MTP::f_post) ? Flag::Post : Flag())
| ((flags & MTP::f_legacy) ? Flag::Legacy : Flag())
| ((flags & MTP::f_from_id) ? Flag::HasFromId : Flag())
| ((flags & MTP::f_reply_to) ? Flag::HasReplyInfo : Flag());
}
MTPMessageReplyHeader NewMessageReplyHeader(const Api::SendAction &action) {
if (const auto id = action.replyTo) {
const auto to = LookupReplyTo(action.history, id);
if (const auto replyToTop = LookupReplyToTop(to)) {
using Flag = MTPDmessageReplyHeader::Flag;
return MTP_messageReplyHeader(
MTP_flags(Flag::f_reply_to_top_id
| (LookupReplyIsTopicPost(to)
? Flag::f_forum_topic
: Flag(0))),
MTP_int(id),
MTPPeer(),
MTP_int(replyToTop));
}
return MTP_messageReplyHeader(
MTP_flags(0),
MTP_int(id),
MTPPeer(),
MTPint());
}
return MTPMessageReplyHeader();
}
MediaCheckResult CheckMessageMedia(const MTPMessageMedia &media) {
using Result = MediaCheckResult;
return media.match([](const MTPDmessageMediaEmpty &) {
return Result::Good;
}, [](const MTPDmessageMediaContact &) {
return Result::Good;
}, [](const MTPDmessageMediaGeo &data) {
return data.vgeo().match([](const MTPDgeoPoint &) {
return Result::Good;
}, [](const MTPDgeoPointEmpty &) {
return Result::Empty;
});
}, [](const MTPDmessageMediaVenue &data) {
return data.vgeo().match([](const MTPDgeoPoint &) {
return Result::Good;
}, [](const MTPDgeoPointEmpty &) {
return Result::Empty;
});
}, [](const MTPDmessageMediaGeoLive &data) {
return data.vgeo().match([](const MTPDgeoPoint &) {
return Result::Good;
}, [](const MTPDgeoPointEmpty &) {
return Result::Empty;
});
}, [](const MTPDmessageMediaPhoto &data) {
const auto photo = data.vphoto();
if (data.vttl_seconds()) {
return Result::HasTimeToLive;
} else if (!photo) {
return Result::Empty;
}
return photo->match([](const MTPDphoto &) {
return Result::Good;
}, [](const MTPDphotoEmpty &) {
return Result::Empty;
});
}, [](const MTPDmessageMediaDocument &data) {
const auto document = data.vdocument();
if (data.vttl_seconds()) {
return Result::HasTimeToLive;
} else if (!document) {
return Result::Empty;
}
return document->match([](const MTPDdocument &) {
return Result::Good;
}, [](const MTPDdocumentEmpty &) {
return Result::Empty;
});
}, [](const MTPDmessageMediaWebPage &data) {
return data.vwebpage().match([](const MTPDwebPage &) {
return Result::Good;
}, [](const MTPDwebPageEmpty &) {
return Result::Good;
}, [](const MTPDwebPagePending &) {
return Result::Good;
}, [](const MTPDwebPageNotModified &) {
return Result::Unsupported;
});
}, [](const MTPDmessageMediaGame &data) {
return data.vgame().match([](const MTPDgame &) {
return Result::Good;
});
}, [](const MTPDmessageMediaInvoice &) {
return Result::Good;
}, [](const MTPDmessageMediaPoll &) {
return Result::Good;
}, [](const MTPDmessageMediaDice &) {
return Result::Good;
}, [](const MTPDmessageMediaUnsupported &) {
return Result::Unsupported;
});
}
[[nodiscard]] CallId CallIdFromInput(const MTPInputGroupCall &data) {
return data.match([&](const MTPDinputGroupCall &data) {
return data.vid().v;
});
}
std::vector<not_null<UserData*>> ParseInvitedToCallUsers(
not_null<HistoryItem*> item,
const QVector<MTPlong> &users) {
auto &owner = item->history()->owner();
return ranges::views::all(
users
) | ranges::views::transform([&](const MTPlong &id) {
return owner.user(id.v);
}) | ranges::to_vector;
}
PreparedServiceText GenerateJoinedText(
not_null<History*> history,
not_null<UserData*> inviter,
bool viaRequest) {
if (inviter->id != history->session().userPeerId()) {
auto result = PreparedServiceText();
result.links.push_back(inviter->createOpenLink());
result.text = (history->peer->isMegagroup()
? tr::lng_action_add_you_group
: tr::lng_action_add_you)(
tr::now,
lt_from,
Ui::Text::Link(inviter->name(), QString()),
Ui::Text::WithEntities);
return result;
} else if (history->peer->isMegagroup()) {
if (viaRequest) {
return { tr::lng_action_you_joined_by_request(
tr::now,
Ui::Text::WithEntities) };
}
auto self = history->session().user();
auto result = PreparedServiceText();
result.links.push_back(self->createOpenLink());
result.text = tr::lng_action_user_joined(
tr::now,
lt_from,
Ui::Text::Link(self->name(), QString()),
Ui::Text::WithEntities);
return result;
}
return { viaRequest
? tr::lng_action_you_joined_by_request_channel(
tr::now,
Ui::Text::WithEntities)
: tr::lng_action_you_joined(tr::now, Ui::Text::WithEntities) };
}
not_null<HistoryItem*> GenerateJoinedMessage(
not_null<History*> history,
TimeId inviteDate,
not_null<UserData*> inviter,
bool viaRequest) {
return history->makeMessage(
history->owner().nextLocalMessageId(),
MessageFlag::Local,
inviteDate,
GenerateJoinedText(history, inviter, viaRequest));
}
std::optional<bool> PeerHasThisCall(
not_null<PeerData*> peer,
CallId id) {
const auto call = peer->groupCall();
return call
? std::make_optional(call->id() == id)
: PeerCallKnown(peer)
? std::make_optional(false)
: std::nullopt;
}
[[nodiscard]] rpl::producer<bool> PeerHasThisCallValue(
not_null<PeerData*> peer,
CallId id) {
return peer->session().changes().peerFlagsValue(
peer,
Data::PeerUpdate::Flag::GroupCall
) | rpl::filter([=] {
return PeerCallKnown(peer);
}) | rpl::map([=] {
const auto call = peer->groupCall();
return (call && call->id() == id);
}) | rpl::distinct_until_changed(
) | rpl::take_while([=](bool hasThisCall) {
return hasThisCall;
}) | rpl::then(
rpl::single(false)
);
}
[[nodiscard]] ClickHandlerPtr GroupCallClickHandler(
not_null<PeerData*> peer,
CallId callId) {
return std::make_shared<LambdaClickHandler>([=] {
const auto call = peer->groupCall();
if (call && call->id() == callId) {
const auto &windows = peer->session().windows();
if (windows.empty()) {
Core::App().domain().activate(&peer->session().account());
if (windows.empty()) {
return;
}
}
windows.front()->startOrJoinGroupCall(peer, {});
}
});
}
[[nodiscard]] MessageFlags FinalizeMessageFlags(MessageFlags flags) {
if (!(flags & MessageFlag::FakeHistoryItem)
&& !(flags & MessageFlag::IsOrWasScheduled)
&& !(flags & MessageFlag::AdminLogEntry)) {
flags |= MessageFlag::HistoryEntry;
}
return flags;
}
using OnStackUsers = std::array<UserData*, kMaxUnreadReactions>;
[[nodiscard]] OnStackUsers LookupRecentUnreadReactedUsers(
not_null<HistoryItem*> item) {
auto result = OnStackUsers();
auto index = 0;
for (const auto &[emoji, reactions] : item->recentReactions()) {
for (const auto &reaction : reactions) {
if (!reaction.unread) {
continue;
}
if (const auto user = reaction.peer->asUser()) {
result[index++] = user;
if (index == result.size()) {
return result;
}
}
}
}
return result;
}
void CheckReactionNotificationSchedule(
not_null<HistoryItem*> item,
const OnStackUsers &wasUsers) {
// Call to addToUnreadThings may have read the reaction already.
if (!item->hasUnreadReaction()) {
return;
}
for (const auto &[emoji, reactions] : item->recentReactions()) {
for (const auto &reaction : reactions) {
if (!reaction.unread) {
continue;
}
const auto user = reaction.peer->asUser();
if (!user
|| !user->isContact()
|| ranges::contains(wasUsers, user)) {
continue;
}
using Status = PeerData::BlockStatus;
if (user->blockStatus() == Status::Unknown) {
user->updateFull();
}
const auto notification = Data::ItemNotification{
.item = item,
.reactionSender = user,
.type = Data::ItemNotificationType::Reaction,
};
item->notificationThread()->pushNotification(notification);
Core::App().notifications().schedule(notification);
return;
}
}
}
[[nodiscard]] MessageFlags NewForwardedFlags(
not_null<PeerData*> peer,
PeerId from,
not_null<HistoryItem*> fwd) {
auto result = NewMessageFlags(peer);
if (from) {
result |= MessageFlag::HasFromId;
}
if (const auto media = fwd->media()) {
if ((!peer->isChannel() || peer->isMegagroup())
&& media->forwardedBecomesUnread()) {
result |= MessageFlag::MediaIsUnread;
}
}
if (fwd->hasViews()) {
result |= MessageFlag::HasViews;
}
return result;
}
[[nodiscard]] bool CopyMarkupToForward(not_null<const HistoryItem*> item) {
auto mediaOriginal = item->media();
if (mediaOriginal && mediaOriginal->game()) {
// Copy inline keyboard when forwarding messages with a game.
return true;
}
const auto markup = item->inlineReplyMarkup();
if (!markup) {
return false;
}
using Type = HistoryMessageMarkupButton::Type;
for (const auto &row : markup->data.rows) {
for (const auto &button : row) {
const auto switchInline = (button.type == Type::SwitchInline)
|| (button.type == Type::SwitchInlineSame);
const auto url = (button.type == Type::Url)
|| (button.type == Type::Auth);
if ((!switchInline || !item->viaBot()) && !url) {
return false;
}
}
}
return true;
}
[[nodiscard]] TextWithEntities EnsureNonEmpty(
const TextWithEntities &text) {
return !text.text.isEmpty() ? text : TextWithEntities{ u":-("_q };
}
[[nodiscard]] TextWithEntities UnsupportedMessageText() {
const auto siteLink = u"https://desktop.telegram.org"_q;
auto result = TextWithEntities{
tr::lng_message_unsupported(tr::now, lt_link, siteLink)
};
TextUtilities::ParseEntities(result, Ui::ItemTextNoMonoOptions().flags);
result.entities.push_front(
EntityInText(EntityType::Italic, 0, result.text.size()));
return result;
}

View File

@ -0,0 +1,133 @@
/*
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
class History;
namespace Api {
struct SendOptions;
struct SendAction;
} // namespace Api
namespace Data {
class Thread;
} // namespace Data
namespace Main {
class Session;
} // namespace Main
struct PreparedServiceText {
TextWithEntities text;
std::vector<ClickHandlerPtr> links;
};
[[nodiscard]] MessageFlags FlagsFromMTP(
MsgId id,
MTPDmessage::Flags flags,
MessageFlags localFlags);
[[nodiscard]] MessageFlags FlagsFromMTP(
MsgId id,
MTPDmessageService::Flags flags,
MessageFlags localFlags);
[[nodiscard]] MTPMessageReplyHeader NewMessageReplyHeader(
const Api::SendAction &action);
enum class MediaCheckResult {
Good,
Unsupported,
Empty,
HasTimeToLive,
};
[[nodiscard]] MediaCheckResult CheckMessageMedia(
const MTPMessageMedia &media);
[[nodiscard]] CallId CallIdFromInput(const MTPInputGroupCall &data);
[[nodiscard]] std::vector<not_null<UserData*>> ParseInvitedToCallUsers(
not_null<HistoryItem*> item,
const QVector<MTPlong> &users);
inline constexpr auto kMaxUnreadReactions = 5; // Now 3, but just in case.
using OnStackUsers = std::array<UserData*, kMaxUnreadReactions>;
[[nodiscard]] OnStackUsers LookupRecentUnreadReactedUsers(
not_null<HistoryItem*> item);
void CheckReactionNotificationSchedule(
not_null<HistoryItem*> item,
const OnStackUsers &wasUsers);
[[nodiscard]] MessageFlags NewForwardedFlags(
not_null<PeerData*> peer,
PeerId from,
not_null<HistoryItem*> fwd);
[[nodiscard]] MessageFlags FinalizeMessageFlags(MessageFlags flags);
[[nodiscard]] bool CopyMarkupToForward(not_null<const HistoryItem*> item);
[[nodiscard]] TextWithEntities EnsureNonEmpty(
const TextWithEntities &text = TextWithEntities());
[[nodiscard]] TextWithEntities UnsupportedMessageText();
void RequestDependentMessageData(
not_null<HistoryItem*> item,
PeerId peerId,
MsgId msgId);
[[nodiscard]] MessageFlags NewMessageFlags(not_null<PeerData*> peer);
[[nodiscard]] bool ShouldSendSilent(
not_null<PeerData*> peer,
const Api::SendOptions &options);
[[nodiscard]] HistoryItem *LookupReplyTo(
not_null<History*> history,
MsgId replyToId);
[[nodiscard]] MsgId LookupReplyToTop(HistoryItem *replyTo);
[[nodiscard]] bool LookupReplyIsTopicPost(HistoryItem *replyTo);
struct SendingErrorRequest {
MsgId topicRootId = 0;
const HistoryItemsList *forward = nullptr;
const TextWithTags *text = nullptr;
bool ignoreSlowmodeCountdown = false;
};
[[nodiscard]] QString GetErrorTextForSending(
not_null<PeerData*> peer,
SendingErrorRequest request);
[[nodiscard]] QString GetErrorTextForSending(
not_null<Data::Thread*> thread,
SendingErrorRequest request);
[[nodiscard]] TextWithEntities DropCustomEmoji(TextWithEntities text);
[[nodiscard]] Main::Session *SessionByUniqueId(uint64 sessionUniqueId);
[[nodiscard]] HistoryItem *MessageByGlobalId(GlobalMsgId globalId);
[[nodiscard]] QDateTime ItemDateTime(not_null<const HistoryItem*> item);
[[nodiscard]] QString ItemDateText(
not_null<const HistoryItem*> item,
bool isUntilOnline);
[[nodiscard]] bool IsItemScheduledUntilOnline(
not_null<const HistoryItem*> item);
[[nodiscard]] ClickHandlerPtr JumpToMessageClickHandler(
not_null<PeerData*> peer,
MsgId msgId,
FullMsgId returnToId = FullMsgId());
[[nodiscard]] ClickHandlerPtr JumpToMessageClickHandler(
not_null<HistoryItem*> item,
FullMsgId returnToId = FullMsgId());
[[nodiscard]] not_null<HistoryItem*> GenerateJoinedMessage(
not_null<History*> history,
TimeId inviteDate,
not_null<UserData*> inviter,
bool viaRequest);
[[nodiscard]] std::optional<bool> PeerHasThisCall(
not_null<PeerData*> peer,
CallId id);
[[nodiscard]] rpl::producer<bool> PeerHasThisCallValue(
not_null<PeerData*> peer,
CallId id);
[[nodiscard]] ClickHandlerPtr GroupCallClickHandler(
not_null<PeerData*> peer,
CallId callId);

File diff suppressed because it is too large Load Diff

View File

@ -1,276 +0,0 @@
/*
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 "history/history_item.h"
namespace Api {
struct SendAction;
struct SendOptions;
} // namespace Api
namespace Data {
class Thread;
struct SponsoredFrom;
} // namespace Data
namespace HistoryView {
class Message;
} // namespace HistoryView
struct HistoryMessageEdited;
struct HistoryMessageReply;
struct HistoryMessageViews;
struct HistoryMessageMarkupData;
void RequestDependentMessageData(
not_null<HistoryItem*> item,
PeerId peerId,
MsgId msgId);
[[nodiscard]] MessageFlags NewMessageFlags(not_null<PeerData*> peer);
[[nodiscard]] bool ShouldSendSilent(
not_null<PeerData*> peer,
const Api::SendOptions &options);
[[nodiscard]] MsgId LookupReplyToTop(
not_null<History*> history,
MsgId replyToId);
[[nodiscard]] MTPMessageReplyHeader NewMessageReplyHeader(
const Api::SendAction &action);
struct SendingErrorRequest {
MsgId topicRootId = 0;
const HistoryItemsList *forward = nullptr;
const TextWithTags *text = nullptr;
bool ignoreSlowmodeCountdown = false;
};
[[nodiscard]] QString GetErrorTextForSending(
not_null<PeerData*> peer,
SendingErrorRequest request);
[[nodiscard]] QString GetErrorTextForSending(
not_null<Data::Thread*> thread,
SendingErrorRequest request);
[[nodiscard]] TextWithEntities DropCustomEmoji(TextWithEntities text);
class HistoryMessage final : public HistoryItem {
public:
HistoryMessage(
not_null<History*> history,
MsgId id,
const MTPDmessage &data,
MessageFlags localFlags);
HistoryMessage(
not_null<History*> history,
MsgId id,
const MTPDmessageService &data,
MessageFlags localFlags);
HistoryMessage(
not_null<History*> history,
MsgId id,
MessageFlags flags,
TimeId date,
PeerId from,
const QString &postAuthor,
not_null<HistoryItem*> original,
MsgId topicRootId); // local forwarded
HistoryMessage(
not_null<History*> history,
MsgId id,
MessageFlags flags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
const QString &postAuthor,
const TextWithEntities &textWithEntities,
const MTPMessageMedia &media,
HistoryMessageMarkupData &&markup,
uint64 groupedId); // local message
HistoryMessage(
not_null<History*> history,
MsgId id,
MessageFlags flags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
const QString &postAuthor,
not_null<DocumentData*> document,
const TextWithEntities &caption,
HistoryMessageMarkupData &&markup); // local document
HistoryMessage(
not_null<History*> history,
MsgId id,
MessageFlags flags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
const QString &postAuthor,
not_null<PhotoData*> photo,
const TextWithEntities &caption,
HistoryMessageMarkupData &&markup); // local photo
HistoryMessage(
not_null<History*> history,
MsgId id,
MessageFlags flags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
const QString &postAuthor,
not_null<GameData*> game,
HistoryMessageMarkupData &&markup); // local game
HistoryMessage(
not_null<History*> history,
MsgId id,
Data::SponsoredFrom from,
const TextWithEntities &textWithEntities,
HistoryItem *injectedAfter); // sponsored
void refreshMedia(const MTPMessageMedia *media);
void refreshSentMedia(const MTPMessageMedia *media);
void returnSavedMedia() override;
void setMedia(const MTPMessageMedia &media);
void checkBuyButton() override;
[[nodiscard]] static std::unique_ptr<Data::Media> CreateMedia(
not_null<HistoryMessage*> item,
const MTPMessageMedia &media);
[[nodiscard]] bool allowsForward() const override;
[[nodiscard]] bool allowsSendNow() const override;
[[nodiscard]] bool allowsEdit(TimeId now) const override;
bool changeViewsCount(int count) override;
void setForwardsCount(int count) override;
void setReplies(HistoryMessageRepliesData &&data) override;
void clearReplies() override;
void changeRepliesCount(int delta, PeerId replier) override;
void setReplyFields(
MsgId replyTo,
MsgId replyToTop,
bool isForumPost) override;
void setPostAuthor(const QString &author) override;
void setRealId(MsgId newId) override;
void incrementReplyToTopCounter() override;
void dependencyItemRemoved(HistoryItem *dependency) override;
[[nodiscard]] QString notificationHeader() const override;
// Looks on:
// f_edit_hide
// f_edit_date
// f_entities
// f_reply_markup
// f_media
// f_views
// f_forwards
// f_replies
// f_ttl_period
void applyEdition(HistoryMessageEdition &&edition) override;
void applyEdition(const MTPDmessageService &message) override;
void applyEdition(const MTPMessageExtendedMedia &media) override;
void updateSentContent(
const TextWithEntities &textWithEntities,
const MTPMessageMedia *media) override;
void updateReplyMarkup(HistoryMessageMarkupData &&markup) override;
void updateForwardedInfo(const MTPMessageFwdHeader *fwd) override;
void contributeToSlowmode(TimeId realDate = 0) override;
void addToUnreadThings(HistoryUnreadThings::AddType type) override;
void destroyHistoryEntry() override;
[[nodiscard]] Storage::SharedMediaTypesMask sharedMediaTypes() const override;
[[nodiscard]] MsgId replyToId() const override;
[[nodiscard]] MsgId replyToTop() const override;
[[nodiscard]] MsgId topicRootId() const override;
void setText(const TextWithEntities &textWithEntities) override;
[[nodiscard]] TextWithEntities originalText() const override;
[[nodiscard]] auto originalTextWithLocalEntities() const
-> TextWithEntities override;
[[nodiscard]] TextForMimeData clipboardText() const override;
[[nodiscard]] int viewsCount() const override;
[[nodiscard]] int repliesCount() const override;
[[nodiscard]] bool repliesAreComments() const override;
[[nodiscard]] bool externalReply() const override;
void setCommentsInboxReadTill(MsgId readTillId) override;
void setCommentsMaxId(MsgId maxId) override;
void setCommentsPossibleMaxId(MsgId possibleMaxId) override;
[[nodiscard]] bool areCommentsUnread() const override;
[[nodiscard]] FullMsgId commentsItemId() const override;
void setCommentsItemId(FullMsgId id) override;
bool updateDependencyItem() override;
[[nodiscard]] MsgId dependencyMsgId() const override {
return replyToId();
}
void applySentMessage(const MTPDmessage &data) override;
void applySentMessage(
const QString &text,
const MTPDupdateShortSentMessage &data,
bool wasAlready) override;
[[nodiscard]] std::unique_ptr<HistoryView::Element> createView(
not_null<HistoryView::ElementDelegate*> delegate,
HistoryView::Element *replacing = nullptr) override;
~HistoryMessage();
private:
void setTextValue(TextWithEntities text);
[[nodiscard]] bool isTooOldForEdit(TimeId now) const;
[[nodiscard]] bool isLegacyMessage() const {
return _flags & MessageFlag::Legacy;
}
[[nodiscard]] bool checkCommentsLinkedChat(ChannelId id) const;
// For an invoice button we replace the button text with a "Receipt" key.
// It should show the receipt for the payed invoice. Still let mobile apps do that.
void replaceBuyWithReceiptInMarkup();
void setReplyMarkup(HistoryMessageMarkupData &&markup);
struct CreateConfig;
void createComponentsHelper(
MessageFlags flags,
MsgId replyTo,
UserId viaBotId,
const QString &postAuthor,
HistoryMessageMarkupData &&markup);
void createComponents(CreateConfig &&config);
void setupForwardedComponent(const CreateConfig &config);
void changeReplyToTopCounter(
not_null<HistoryMessageReply*> reply,
int delta);
void refreshRepliesText(
not_null<HistoryMessageViews*> views,
bool forceResize = false);
void setSponsoredFrom(const Data::SponsoredFrom &from);
static void FillForwardedInfo(
CreateConfig &config,
const MTPDmessageFwdHeader &data);
[[nodiscard]] bool generateLocalEntitiesByReply() const;
[[nodiscard]] TextWithEntities withLocalEntities(
const TextWithEntities &textWithEntities) const;
[[nodiscard]] bool checkRepliesPts(
const HistoryMessageRepliesData &data) const;
friend class HistoryView::Element;
friend class HistoryView::Message;
};

File diff suppressed because it is too large Load Diff

View File

@ -1,235 +0,0 @@
/*
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 "history/history_item.h"
namespace HistoryView {
class Service;
} // namespace HistoryView
struct HistoryServiceDependentData {
PeerId peerId = 0;
HistoryItem *msg = nullptr;
ClickHandlerPtr lnk;
MsgId msgId = 0;
MsgId topId = 0;
bool topicPost = false;
};
struct HistoryServicePinned
: public RuntimeComponent<HistoryServicePinned, HistoryItem>
, public HistoryServiceDependentData {
};
struct HistoryServiceTopicInfo
: public RuntimeComponent<HistoryServiceTopicInfo, HistoryItem>
, public HistoryServiceDependentData {
QString title;
DocumentId iconId = 0;
bool closed = false;
bool reopened = false;
bool reiconed = false;
bool renamed = false;
bool hidden = false;
bool unhidden = false;
[[nodiscard]] bool created() const {
return !closed
&& !reopened
&& !reiconed
&& !renamed
&& !hidden
&& !unhidden;
}
};
struct HistoryServiceGameScore
: public RuntimeComponent<HistoryServiceGameScore, HistoryItem>
, public HistoryServiceDependentData {
int score = 0;
};
struct HistoryServicePayment
: public RuntimeComponent<HistoryServicePayment, HistoryItem>
, public HistoryServiceDependentData {
QString slug;
QString amount;
ClickHandlerPtr invoiceLink;
bool recurringInit = false;
bool recurringUsed = false;
};
struct HistoryServiceSelfDestruct
: public RuntimeComponent<HistoryServiceSelfDestruct, HistoryItem> {
enum class Type {
Photo,
Video,
};
Type type = Type::Photo;
crl::time timeToLive = 0;
crl::time destructAt = 0;
};
struct HistoryServiceOngoingCall
: public RuntimeComponent<HistoryServiceOngoingCall, HistoryItem> {
CallId id = 0;
ClickHandlerPtr link;
rpl::lifetime lifetime;
};
struct HistoryServiceChatThemeChange
: public RuntimeComponent<HistoryServiceChatThemeChange, HistoryItem> {
ClickHandlerPtr link;
};
struct HistoryServiceTTLChange
: public RuntimeComponent<HistoryServiceTTLChange, HistoryItem> {
ClickHandlerPtr link;
};
namespace HistoryView {
class ServiceMessagePainter;
} // namespace HistoryView
class HistoryService : public HistoryItem {
public:
struct PreparedText {
TextWithEntities text;
std::vector<ClickHandlerPtr> links;
};
HistoryService(
not_null<History*> history,
MsgId id,
const MTPDmessage &data,
MessageFlags localFlags);
HistoryService(
not_null<History*> history,
MsgId id,
const MTPDmessageService &data,
MessageFlags localFlags);
HistoryService(
not_null<History*> history,
MsgId id,
MessageFlags flags,
TimeId date,
PreparedText &&message,
PeerId from = 0,
PhotoData *photo = nullptr);
bool updateDependencyItem() override;
MsgId dependencyMsgId() const override {
if (auto dependent = GetDependentData()) {
return dependent->msgId;
}
return 0;
}
bool notificationReady() const override {
if (auto dependent = GetDependentData()) {
return (dependent->msg || !dependent->msgId);
}
return true;
}
const std::vector<ClickHandlerPtr> &customTextLinks() const override;
void applyEdition(const MTPDmessageService &message) override;
crl::time getSelfDestructIn(crl::time now) override;
Storage::SharedMediaTypesMask sharedMediaTypes() const override;
void dependencyItemRemoved(HistoryItem *dependency) override;
bool needCheck() const override;
bool isService() const override {
return true;
}
ItemPreview toPreview(ToPreviewOptions options) const override;
TextWithEntities inReplyText() const override;
MsgId replyToId() const override;
MsgId replyToTop() const override;
MsgId topicRootId() const override;
void setReplyFields(
MsgId replyTo,
MsgId replyToTop,
bool isForumPost) override;
std::unique_ptr<HistoryView::Element> createView(
not_null<HistoryView::ElementDelegate*> delegate,
HistoryView::Element *replacing = nullptr) override;
void setServiceText(PreparedText &&prepared);
~HistoryService();
protected:
friend class HistoryView::ServiceMessagePainter;
void markMediaAsReadHook() override;
TextWithEntities fromLinkText() const;
ClickHandlerPtr fromLink() const;
void removeMedia();
private:
HistoryServiceDependentData *GetDependentData() {
if (const auto pinned = Get<HistoryServicePinned>()) {
return pinned;
} else if (const auto gamescore = Get<HistoryServiceGameScore>()) {
return gamescore;
} else if (const auto payment = Get<HistoryServicePayment>()) {
return payment;
} else if (const auto info = Get<HistoryServiceTopicInfo>()) {
return info;
}
return nullptr;
}
const HistoryServiceDependentData *GetDependentData() const {
return const_cast<HistoryService*>(this)->GetDependentData();
}
bool updateDependent(bool force = false);
void updateDependentText();
void updateText(PreparedText &&text);
void clearDependency();
void setupChatThemeChange();
void setupTTLChange();
void createFromMtp(const MTPDmessage &message);
void createFromMtp(const MTPDmessageService &message);
void setMessageByAction(const MTPmessageAction &action);
void setSelfDestruct(
HistoryServiceSelfDestruct::Type type,
int ttlSeconds);
void applyAction(const MTPMessageAction &action);
PreparedText preparePinnedText();
PreparedText prepareGameScoreText();
PreparedText preparePaymentSentText();
PreparedText prepareInvitedToCallText(
const QVector<MTPlong> &users,
CallId linkCallId);
PreparedText prepareCallScheduledText(
TimeId scheduleDate);
friend class HistoryView::Service;
std::vector<ClickHandlerPtr> _textLinks;
};
[[nodiscard]] not_null<HistoryService*> GenerateJoinedMessage(
not_null<History*> history,
TimeId inviteDate,
not_null<UserData*> inviter,
bool viaRequest);
[[nodiscard]] std::optional<bool> PeerHasThisCall(
not_null<PeerData*> peer,
CallId id);

View File

@ -78,7 +78,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/stickers/data_custom_emoji.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_message.h"
#include "history/history_item_helpers.h" // GetErrorTextForSending.
#include "history/history_drag_area.h"
#include "history/history_inner_widget.h"
#include "history/history_item_components.h"

View File

@ -8,7 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/controls/history_view_forward_panel.h"
#include "history/history.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "history/history_item_components.h"
#include "history/view/history_view_item_preview.h"
#include "data/data_session.h"

View File

@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/painter.h"
#include "lang/lang_keys.h"
#include "history/history_item_components.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history.h"
#include "history/view/history_view_message.h"
#include "history/view/history_view_cursor_state.h"
@ -629,7 +629,7 @@ void BottomInfo::continueReactionAnimations(base::flat_map<
BottomInfo::Data BottomInfoDataFromMessage(not_null<Message*> message) {
using Flag = BottomInfo::Data::Flag;
const auto item = message->message();
const auto item = message->data();
auto result = BottomInfo::Data();
result.date = message->dateTime();

View File

@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_cursor_state.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_message.h"
#include "history/history_item_text.h"
#include "history/view/history_view_schedule_box.h"
#include "history/view/media/history_view_media.h"

View File

@ -10,8 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_chat_invite.h"
#include "history/view/history_view_service_message.h"
#include "history/view/history_view_message.h"
#include "history/history_item_components.h"
#include "history/history_item.h"
#include "history/view/media/history_view_media.h"
#include "history/view/media/history_view_media_grouped.h"
#include "history/view/media/history_view_sticker.h"
@ -22,7 +20,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_cursor_state.h"
#include "history/view/history_view_spoiler_click_handler.h"
#include "history/history.h"
#include "history/history_service.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "history/history_item_helpers.h"
#include "base/unixtime.h"
#include "core/application.h"
#include "core/core_settings.h"
@ -118,18 +118,6 @@ SimpleElementDelegate::SimpleElementDelegate(
SimpleElementDelegate::~SimpleElementDelegate() = default;
std::unique_ptr<HistoryView::Element> SimpleElementDelegate::elementCreate(
not_null<HistoryMessage*> message,
Element *replacing) {
return std::make_unique<HistoryView::Message>(this, message, replacing);
}
std::unique_ptr<HistoryView::Element> SimpleElementDelegate::elementCreate(
not_null<HistoryService*> message,
Element *replacing) {
return std::make_unique<HistoryView::Service>(this, message, replacing);
}
bool SimpleElementDelegate::elementUnderCursor(
not_null<const Element*> view) {
return false;

View File

@ -15,8 +15,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class History;
class HistoryBlock;
class HistoryItem;
class HistoryMessage;
class HistoryService;
struct HistoryMessageReply;
namespace Data {
@ -64,12 +62,6 @@ class Element;
class ElementDelegate {
public:
virtual Context elementContext() = 0;
virtual std::unique_ptr<Element> elementCreate(
not_null<HistoryMessage*> message,
Element *replacing = nullptr) = 0;
virtual std::unique_ptr<Element> elementCreate(
not_null<HistoryService*> message,
Element *replacing = nullptr) = 0;
virtual bool elementUnderCursor(not_null<const Element*> view) = 0;
[[nodiscard]] virtual float64 elementHighlightOpacity(
not_null<const HistoryItem*> item) const = 0;
@ -126,12 +118,6 @@ public:
Fn<void()> update);
~SimpleElementDelegate();
std::unique_ptr<Element> elementCreate(
not_null<HistoryMessage*> message,
Element *replacing = nullptr) override;
std::unique_ptr<Element> elementCreate(
not_null<HistoryService*> message,
Element *replacing = nullptr) override;
bool elementUnderCursor(not_null<const Element*> view) override;
[[nodiscard]] float64 elementHighlightOpacity(
not_null<const HistoryItem*> item) const override;

View File

@ -10,8 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/unixtime.h"
#include "base/qt/qt_key_modifiers.h"
#include "base/qt/qt_common_adapters.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "history/history_item_helpers.h"
#include "history/history_item_text.h"
#include "history/view/media/history_view_media.h"
#include "history/view/media/history_view_sticker.h"
@ -1614,18 +1615,6 @@ Context ListWidget::elementContext() {
return _delegate->listContext();
}
std::unique_ptr<Element> ListWidget::elementCreate(
not_null<HistoryMessage*> message,
Element *replacing) {
return std::make_unique<Message>(this, message, replacing);
}
std::unique_ptr<Element> ListWidget::elementCreate(
not_null<HistoryService*> message,
Element *replacing) {
return std::make_unique<Service>(this, message, replacing);
}
bool ListWidget::elementUnderCursor(
not_null<const HistoryView::Element*> view) {
return (_overElement == view);

View File

@ -286,12 +286,6 @@ public:
// ElementDelegate interface.
Context elementContext() override;
std::unique_ptr<Element> elementCreate(
not_null<HistoryMessage*> message,
Element *replacing = nullptr) override;
std::unique_ptr<Element> elementCreate(
not_null<HistoryService*> message,
Element *replacing = nullptr) override;
bool elementUnderCursor(not_null<const Element*> view) override;
[[nodiscard]] float64 elementHighlightOpacity(
not_null<const HistoryItem*> item) const override;

View File

@ -10,8 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/click_handler_types.h" // ClickHandlerContext
#include "core/ui_integration.h"
#include "history/view/history_view_cursor_state.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "history/history_message.h"
#include "history/history_item_helpers.h"
#include "history/view/media/history_view_media.h"
#include "history/view/media/history_view_web_page.h"
#include "history/view/reactions/history_view_reactions.h"
@ -313,7 +314,7 @@ LogEntryOriginal::~LogEntryOriginal() = default;
Message::Message(
not_null<ElementDelegate*> delegate,
not_null<HistoryMessage*> data,
not_null<HistoryItem*> data,
Element *replacing)
: Element(delegate, data, replacing, Flag(0))
, _bottomInfo(
@ -348,10 +349,6 @@ Message::~Message() {
}
}
not_null<HistoryMessage*> Message::message() const {
return static_cast<HistoryMessage*>(data().get());
}
void Message::refreshRightBadge() {
const auto text = [&] {
if (data()->isDiscussionPost()) {
@ -403,7 +400,7 @@ void Message::applyGroupAdminChanges(
}
void Message::animateReaction(Ui::ReactionFlyAnimationArgs &&args) {
const auto item = message();
const auto item = data();
const auto media = this->media();
auto g = countGeometry();
@ -510,7 +507,7 @@ auto Message::takeReactionAnimations()
}
QSize Message::performCountOptimalSize() {
const auto item = message();
const auto item = data();
const auto markup = item->inlineReplyMarkup();
refreshIsTopicRootReply();
validateText();
@ -689,7 +686,7 @@ QSize Message::performCountOptimalSize() {
}
void Message::refreshTopicButton() {
const auto item = message();
const auto item = data();
if (isAttachedToPrevious() || context() != Context::History) {
_topicButton = nullptr;
} else if (const auto topic = item->topic()) {
@ -742,7 +739,7 @@ void Message::draw(Painter &p, const PaintContext &context) const {
return;
}
const auto item = message();
const auto item = data();
const auto media = this->media();
const auto stm = context.messageStyle();
@ -1039,7 +1036,7 @@ void Message::draw(Painter &p, const PaintContext &context) const {
}
if (const auto reply = displayedReply()) {
if (reply->isNameUpdated(message())) {
if (reply->isNameUpdated(data())) {
const_cast<Message*>(this)->setPendingResize();
}
}
@ -1174,7 +1171,7 @@ void Message::paintFromName(
Painter &p,
QRect &trect,
const PaintContext &context) const {
const auto item = message();
const auto item = data();
if (!displayFromName()) {
return;
}
@ -1367,7 +1364,7 @@ void Message::paintForwardedInfo(
QRect &trect,
const PaintContext &context) const {
if (displayForwardedFrom()) {
const auto item = message();
const auto item = data();
const auto st = context.st;
const auto stm = context.messageStyle();
const auto forwarded = item->Get<HistoryMessageForwarded>();
@ -1438,7 +1435,7 @@ void Message::paintViaBotIdInfo(
Painter &p,
QRect &trect,
const PaintContext &context) const {
const auto item = message();
const auto item = data();
if (!displayFromName() && !displayForwardedFrom()) {
if (auto via = item->Get<HistoryMessageVia>()) {
const auto stm = context.messageStyle();
@ -1479,7 +1476,7 @@ PointState Message::pointState(QPoint point) const {
}
const auto media = this->media();
const auto item = message();
const auto item = data();
const auto reactionsInBubble = _reactions && embedReactionsInBubble();
if (drawBubble()) {
if (!g.contains(point)) {
@ -1744,7 +1741,7 @@ void Message::unloadHeavyPart() {
bool Message::showForwardsFromSender(
not_null<HistoryMessageForwarded*> forwarded) const {
const auto peer = message()->history()->peer;
const auto peer = data()->history()->peer;
return peer->isSelf()
|| peer->isRepliesChat()
|| forwarded->imported;
@ -1760,7 +1757,7 @@ bool Message::hasFromPhoto() const {
case Context::History:
case Context::Pinned:
case Context::Replies: {
const auto item = message();
const auto item = data();
if (item->isPost()) {
if (item->isSponsored()) {
if (item->history()->peer->isMegagroup()) {
@ -1794,7 +1791,7 @@ bool Message::hasFromPhoto() const {
TextState Message::textState(
QPoint point,
StateRequest request) const {
const auto item = message();
const auto item = data();
const auto media = this->media();
auto result = TextState(item);
@ -2067,7 +2064,7 @@ bool Message::getStateFromName(
if (replyWidth) {
availableWidth -= st::msgPadding.right() + replyWidth;
}
const auto item = message();
const auto item = data();
const auto from = item->displayFrom();
const auto nameText = [&]() -> const Ui::Text::String * {
if (from) {
@ -2138,7 +2135,7 @@ bool Message::getStateForwardedInfo(
if (!displayForwardedFrom()) {
return false;
}
const auto item = message();
const auto item = data();
const auto forwarded = item->Get<HistoryMessageForwarded>();
const auto skip1 = forwarded->psaType.isEmpty()
? 0
@ -2252,7 +2249,7 @@ bool Message::getStateViaBotIdInfo(
QPoint point,
QRect &trect,
not_null<TextState*> outResult) const {
const auto item = message();
const auto item = data();
if (const auto via = item->Get<HistoryMessageVia>()) {
if (!displayFromName() && !displayForwardedFrom()) {
if (QRect(trect.x(), trect.y(), via->width, st::msgNameFont->height).contains(point)) {
@ -2273,7 +2270,7 @@ bool Message::getStateText(
if (!hasVisibleText()) {
return false;
}
const auto item = message();
const auto item = data();
if (base::in_range(point.y(), trect.y(), trect.y() + trect.height())) {
*outResult = TextState(item, text().getState(
point - trect.topLeft(),
@ -2286,7 +2283,7 @@ bool Message::getStateText(
// Forward to media.
void Message::updatePressed(QPoint point) {
const auto item = message();
const auto item = data();
const auto media = this->media();
if (!media) return;
@ -2759,7 +2756,7 @@ void Message::updateViewButtonExistence() {
}
void Message::initLogEntryOriginal() {
if (const auto log = message()->Get<HistoryMessageLogEntryOriginal>()) {
if (const auto log = data()->Get<HistoryMessageLogEntryOriginal>()) {
AddComponents(LogEntryOriginal::Bit());
const auto entry = Get<LogEntryOriginal>();
entry->page = std::make_unique<WebPage>(this, log->page);
@ -2767,7 +2764,7 @@ void Message::initLogEntryOriginal() {
}
void Message::initPsa() {
if (const auto forwarded = message()->Get<HistoryMessageForwarded>()) {
if (const auto forwarded = data()->Get<HistoryMessageForwarded>()) {
if (!forwarded->psaType.isEmpty()) {
AddComponents(PsaTooltipState::Bit());
Get<PsaTooltipState>()->type = forwarded->psaType;
@ -2810,7 +2807,7 @@ bool Message::hasFromName() const {
case Context::History:
case Context::Pinned:
case Context::Replies: {
const auto item = message();
const auto item = data();
const auto peer = item->history()->peer;
if (hasOutLayout() && !item->from()->isChannel()) {
return false;
@ -2841,7 +2838,7 @@ bool Message::displayFromName() const {
}
bool Message::displayForwardedFrom() const {
const auto item = message();
const auto item = data();
if (const auto forwarded = item->Get<HistoryMessageForwarded>()) {
if (showForwardsFromSender(forwarded)) {
return false;
@ -2858,7 +2855,7 @@ bool Message::displayForwardedFrom() const {
}
bool Message::hasOutLayout() const {
const auto item = message();
const auto item = data();
if (item->history()->peer->isSelf()) {
return !item->Has<HistoryMessageForwarded>();
} else if (const auto forwarded = item->Get<HistoryMessageForwarded>()) {
@ -2874,7 +2871,7 @@ bool Message::hasOutLayout() const {
}
bool Message::drawBubble() const {
const auto item = message();
const auto item = data();
if (isHidden()) {
return false;
} else if (logEntryOriginal()) {
@ -2895,7 +2892,7 @@ TopicButton *Message::displayedTopicButton() const {
}
bool Message::unwrapped() const {
const auto item = message();
const auto item = data();
if (isHidden()) {
return true;
} else if (logEntryOriginal()) {
@ -2989,7 +2986,7 @@ std::optional<QSize> Message::rightActionSize() const {
}
bool Message::displayFastShare() const {
const auto item = message();
const auto item = data();
const auto peer = item->history()->peer;
if (!item->allowsForward()) {
return false;
@ -3015,7 +3012,7 @@ bool Message::displayGoToOriginal() const {
if (isPinnedContext()) {
return !hasOutLayout();
}
const auto item = message();
const auto item = data();
if (const auto forwarded = item->Get<HistoryMessageForwarded>()) {
return forwarded->savedFromPeer
&& forwarded->savedFromMsgId
@ -3116,7 +3113,7 @@ void Message::ensureRightAction() const {
ClickHandlerPtr Message::prepareRightActionLink() const {
if (isPinnedContext()) {
return goToMessageClickHandler(data());
return JumpToMessageClickHandler(data());
} else if (displayRightActionComments()) {
return createGoToCommentsLink();
}
@ -3207,7 +3204,7 @@ bool Message::isPinnedContext() const {
}
void Message::updateMediaInBubbleState() {
const auto item = message();
const auto item = data();
const auto media = this->media();
if (media) {
@ -3271,7 +3268,7 @@ void Message::updateMediaInBubbleState() {
}
void Message::fromNameUpdated(int width) const {
const auto item = message();
const auto item = data();
const auto replyWidth = hasFastReply()
? st::msgFont->width(FastReplyText())
: 0;
@ -3356,7 +3353,7 @@ QRect Message::innerGeometry() const {
}
if (!displayFromName() && !displayForwardedFrom()) {
// See paintViaBotIdInfo().
if (message()->Has<HistoryMessageVia>()) {
if (data()->Has<HistoryMessageVia>()) {
result.translate(0, st::msgServiceNameFont->height);
}
}
@ -3468,7 +3465,7 @@ int Message::resizeContentGetHeight(int newWidth) {
auto newHeight = minHeight();
const auto item = message();
const auto item = data();
const auto media = this->media();
const auto mediaDisplayed = media ? media->isDisplayed() : false;
const auto bubble = drawBubble();
@ -3635,7 +3632,7 @@ bool Message::needInfoDisplay() const {
}
bool Message::hasVisibleText() const {
if (message()->emptyText()) {
if (data()->emptyText()) {
return false;
}
const auto media = this->media();
@ -3660,7 +3657,7 @@ QSize Message::performCountCurrentSize(int newWidth) {
}
void Message::refreshInfoSkipBlock() {
const auto item = message();
const auto item = data();
const auto media = this->media();
const auto hasTextSkipBlock = [&] {
if (item->_text.empty()) {
@ -3687,7 +3684,7 @@ void Message::refreshInfoSkipBlock() {
}
TimeId Message::displayedEditDate() const {
const auto item = message();
const auto item = data();
const auto overrided = media() && media()->overrideEditedDate();
if (item->hideEditedBadge() && !overrided) {
return TimeId(0);
@ -3703,7 +3700,7 @@ HistoryMessageEdited *Message::displayedEditBadge() {
return media->displayedEditBadge();
}
}
return message()->Get<HistoryMessageEdited>();
return data()->Get<HistoryMessageEdited>();
}
const HistoryMessageEdited *Message::displayedEditBadge() const {
@ -3712,7 +3709,7 @@ const HistoryMessageEdited *Message::displayedEditBadge() const {
return media->displayedEditBadge();
}
}
return message()->Get<HistoryMessageEdited>();
return data()->Get<HistoryMessageEdited>();
}
} // namespace HistoryView

View File

@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_bottom_info.h"
#include "ui/effects/animations.h"
class HistoryMessage;
class HistoryItem;
struct HistoryMessageEdited;
struct HistoryMessageForwarded;
struct HistoryMessageReplyMarkup;
@ -64,7 +64,7 @@ class Message final : public Element {
public:
Message(
not_null<ElementDelegate*> delegate,
not_null<HistoryMessage*> data,
not_null<HistoryItem*> data,
Element *replacing);
~Message();
@ -72,8 +72,6 @@ public:
const ClickHandlerPtr &handler,
bool pressed) override;
not_null<HistoryMessage*> message() const;
[[nodiscard]] const HistoryMessageEdited *displayedEditBadge() const;
[[nodiscard]] HistoryMessageEdited *displayedEditBadge();

View File

@ -7,11 +7,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "history/view/history_view_service_message.h"
#include "history/history.h"
#include "history/history_service.h"
#include "history/view/media/history_view_media.h"
#include "history/history_item_components.h"
#include "history/view/history_view_cursor_state.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "history/history_item_helpers.h"
#include "data/data_abstract_structure.h"
#include "data/data_chat.h"
#include "data/data_channel.h"
@ -400,15 +401,11 @@ QVector<int> ServiceMessagePainter::CountLineWidths(
Service::Service(
not_null<ElementDelegate*> delegate,
not_null<HistoryService*> data,
not_null<HistoryItem*> data,
Element *replacing)
: Element(delegate, data, replacing, Flag::ServiceMessage) {
}
not_null<HistoryService*> Service::message() const {
return static_cast<HistoryService*>(data().get());
}
QRect Service::innerGeometry() const {
return countGeometry();
}
@ -592,7 +589,7 @@ PointState Service::pointState(QPoint point) const {
}
TextState Service::textState(QPoint point, StateRequest request) const {
const auto item = message();
const auto item = data();
const auto media = this->media();
auto result = TextState(item);

View File

@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_element.h"
class HistoryService;
class HistoryItem;
namespace Ui {
class ChatStyle;
@ -30,7 +30,7 @@ class Service final : public Element {
public:
Service(
not_null<ElementDelegate*> delegate,
not_null<HistoryService*> data,
not_null<HistoryItem*> data,
Element *replacing);
int marginTop() const override;
@ -50,9 +50,7 @@ public:
QRect innerGeometry() const override;
private:
not_null<HistoryService*> message() const;
QRect countGeometry() const;
[[nodiscard]] QRect countGeometry() const;
QSize performCountOptimalSize() override;
QSize performCountCurrentSize(int newWidth) override;

View File

@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/media/history_view_media_grouped.h"
#include "history/history_item_components.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history.h"
#include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h"

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "history/view/reactions/history_view_reactions.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history.h"
#include "history/view/history_view_message.h"
#include "history/view/history_view_cursor_state.h"
@ -604,7 +604,7 @@ void InlineList::continueAnimations(base::flat_map<
InlineListData InlineListDataFromMessage(not_null<Message*> message) {
using Flag = InlineListData::Flag;
const auto item = message->message();
const auto item = message->data();
auto result = InlineListData();
result.reactions = item->reactions();
if (const auto user = item->history()->peer->asUser()) {

View File

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h"
#include "main/main_account.h"
#include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "history/history.h"
#include "core/application.h"
#include "storage/storage_shared_media.h"

View File

@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_download_manager.h"
#include "data/data_forum_topic.h"
#include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "history/history.h"
#include "history/view/history_view_cursor_state.h"
#include "history/view/history_view_service_message.h"
@ -892,7 +893,7 @@ void ListWidget::showContextMenu(
tr::lng_context_to_msg(tr::now),
[=] {
if (const auto item = MessageByGlobalId(globalId)) {
goToMessageClickHandler(item)->onClick({});
JumpToMessageClickHandler(item)->onClick({});
}
},
&st::menuIconShowInChat);

View File

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "data/data_session.h"
#include "data/data_chat.h"
#include "data/data_channel.h"

View File

@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/localstorage.h"
#include "lang/lang_keys.h"
#include "history/history.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "data/data_channel.h"
#include "ui/text/format_values.h" // Ui::FormatPhone

View File

@ -62,7 +62,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_key.h"
#include "history/history.h"
#include "history/history_widget.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history_item_helpers.h" // GetErrorTextForSending.
#include "history/view/media/history_view_media.h"
#include "history/view/history_view_service_message.h"
#include "history/view/history_view_element.h"

View File

@ -34,6 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_media_player.h"
#include "styles/style_media_view.h"
#include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "storage/storage_account.h"
#include "main/main_session.h"

View File

@ -46,7 +46,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "media/streaming/media_streaming_player.h"
#include "media/player/media_player_instance.h"
#include "history/history.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "history/view/media/history_view_media.h"
#include "data/data_media_types.h"
#include "data/data_session.h"

View File

@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "history/history_item_helpers.h"
#include "history/view/history_view_cursor_state.h"
#include "history/view/media/history_view_document.h" // DrawThumbnailAsSongCover
#include "base/unixtime.h"
@ -644,7 +645,7 @@ Voice::Voice(
lt_duration,
{ .text = Ui::FormatDurationText(duration()) },
Ui::Text::WithEntities));
_details.setLink(1, goToMessageClickHandler(parent));
_details.setLink(1, JumpToMessageClickHandler(parent));
}
void Voice::initDimensions() {
@ -944,7 +945,9 @@ Document::Document(
const style::OverviewFileLayout &st)
: RadialProgressItem(delegate, parent)
, _data(fields.document)
, _msgl(parent->isHistoryEntry() ? goToMessageClickHandler(parent) : nullptr)
, _msgl(parent->isHistoryEntry()
? JumpToMessageClickHandler(parent)
: nullptr)
, _namel(std::make_shared<DocumentOpenClickHandler>(
_data,
crl::guard(this, [=](FullMsgId id) {

View File

@ -16,7 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_file_origin.h"
#include "countries/countries_instance.h"
#include "history/history_item.h"
#include "history/history_service.h" // HistoryServicePayment.
#include "history/history_item_components.h"
#include "stripe/stripe_api_client.h"
#include "stripe/stripe_error.h"
#include "stripe/stripe_token.h"

View File

@ -21,7 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_element.h"
#include "history/view/history_view_message.h"
#include "history/history_item_components.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "history/history.h"
#include "calls/calls_instance.h"
#include "base/unixtime.h"
@ -188,7 +188,7 @@ AdminLog::OwnedItem GenerateForwardedItem(
history->nextNonHistoryEntryId(),
data,
MessageFlag::FakeHistoryItem);
}, [](auto &&) -> not_null<HistoryMessage*> {
}, [](auto &&) -> not_null<HistoryItem*> {
Unexpected("Type in GenerateForwardedItem.");
});

View File

@ -18,7 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "support/support_common.h"
#include "history/view/history_view_message.h"
#include "history/view/history_view_service_message.h"
#include "history/history_message.h"
#include "history/history_item.h"
#include "lang/lang_keys.h"
#include "base/unixtime.h"
#include "base/call_delayed.h"

View File

@ -54,8 +54,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_updates.h"
#include "mtproto/mtproto_config.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_message.h" // GetErrorTextForSending.
#include "history/history_item_helpers.h" // GetErrorTextForSending.
#include "history/view/history_view_context_menu.h"
#include "window/window_adaptive.h" // Adaptive::isThreeColumn
#include "window/window_session_controller.h"