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_components.h
history/history_item_edition.cpp history/history_item_edition.cpp
history/history_item_edition.h 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.cpp
history/history_item_reply_markup.h history/history_item_reply_markup.h
history/history_item_text.cpp history/history_item_text.cpp
@ -772,10 +774,6 @@ PRIVATE
history/history_inner_widget.h history/history_inner_widget.h
history/history_location_manager.cpp history/history_location_manager.cpp
history/history_location_manager.h 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.cpp
history/history_unread_things.h history/history_unread_things.h
history/history_view_highlight_manager.cpp 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_poll.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "history/history.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" #include "main/main_session.h"
namespace Api { namespace Api {

View file

@ -20,7 +20,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_changes.h" #include "data/data_changes.h"
#include "data/stickers/data_stickers.h" #include "data/stickers/data_stickers.h"
#include "history/history.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/message_field.h" // ConvertTextTagsToEntities.
#include "chat_helpers/stickers_dice_pack.h" // DicePacks::kDiceString. #include "chat_helpers/stickers_dice_pack.h" // DicePacks::kDiceString.
#include "ui/text/text_entity.h" // TextWithEntities. #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 "boxes/add_contact_box.h"
#include "mtproto/mtproto_config.h" #include "mtproto/mtproto_config.h"
#include "history/history.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_components.h"
#include "history/history_item_helpers.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "main/main_session_settings.h" #include "main/main_session_settings.h"
#include "main/main_account.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/painter.h"
#include "ui/ui_utility.h" #include "ui/ui_utility.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_message.h" #include "history/history_item.h"
#include "history/view/history_view_message.h" #include "history/view/history_view_message.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "apiwrap.h" #include "apiwrap.h"

View file

@ -32,7 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/painter.h" #include "ui/painter.h"
#include "boxes/share_box.h" #include "boxes/share_box.h"
#include "history/view/history_view_group_call_bar.h" // GenerateUserpics... #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 "history/history.h"
#include "ui/boxes/confirm_box.h" #include "ui/boxes/confirm_box.h"
#include "boxes/peer_list_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 "data/data_session.h"
#include "history/admin_log/history_admin_log_item.h" #include "history/admin_log/history_admin_log_item.h"
#include "history/history.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/history_view_element.h"
#include "history/view/reactions/history_view_reactions_strip.h" #include "history/view/reactions/history_view_reactions_strip.h"
#include "lang/lang_keys.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_check_item.h"
#include "menu/menu_send.h" #include "menu/menu_send.h"
#include "history/history.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_element.h" // HistoryView::Context.
#include "history/view/history_view_context_menu.h" // CopyPostLink. #include "history/view/history_view_context_menu.h" // CopyPostLink.
#include "history/view/history_view_schedule_box.h" #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 "calls/calls_instance.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "main/main_session.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 "lang/lang_keys.h"
#include "boxes/share_box.h" #include "boxes/share_box.h"
#include "history/view/history_view_schedule_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 "history/history.h"
#include "data/data_histories.h" #include "data/data_histories.h"
#include "data/data_session.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_widget.h"
#include "history/history.h" // History::session #include "history/history.h" // History::session
#include "history/history_item.h" // HistoryItem::originalText #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_regex.h"
#include "base/qthelp_url.h" #include "base/qthelp_url.h"
#include "base/event_filter.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 "storage/storage_account.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_message.h" #include "history/history_item_helpers.h"
#include "core/application.h" #include "core/application.h"
#include "core/mime_type.h" #include "core/mime_type.h"
#include "ui/controls/download_bar.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 "data/data_media_types.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h" // CreateMedia.
#include "history/history_message.h" // CreateMedia.
#include "history/history_location_manager.h" #include "history/history_location_manager.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_item_preview.h" #include "history/view/history_view_item_preview.h"
@ -235,7 +234,7 @@ template <typename MediaType>
bool UpdateExtendedMedia( bool UpdateExtendedMedia(
Invoice &invoice, Invoice &invoice,
not_null<HistoryMessage*> item, not_null<HistoryItem*> item,
const MTPMessageExtendedMedia &media) { const MTPMessageExtendedMedia &media) {
return media.match([&](const MTPDmessageExtendedMediaPreview &data) { return media.match([&](const MTPDmessageExtendedMediaPreview &data) {
if (invoice.extendedMedia) { if (invoice.extendedMedia) {
@ -269,7 +268,7 @@ bool UpdateExtendedMedia(
} }
return changed; return changed;
}, [&](const MTPDmessageExtendedMedia &data) { }, [&](const MTPDmessageExtendedMedia &data) {
invoice.extendedMedia = HistoryMessage::CreateMedia( invoice.extendedMedia = HistoryItem::CreateMedia(
item, item,
data.vmedia()); data.vmedia());
return true; return true;
@ -291,7 +290,7 @@ TextForMimeData WithCaptionClipboardText(
} }
Invoice ComputeInvoiceData( Invoice ComputeInvoiceData(
not_null<HistoryMessage*> item, not_null<HistoryItem*> item,
const MTPDmessageMediaInvoice &data) { const MTPDmessageMediaInvoice &data) {
auto description = qs(data.vdescription()); auto description = qs(data.vdescription());
auto result = Invoice{ auto result = Invoice{
@ -1639,7 +1638,7 @@ bool MediaInvoice::updateSentMedia(const MTPMessageMedia &media) {
} }
bool MediaInvoice::updateExtendedMedia( bool MediaInvoice::updateExtendedMedia(
not_null<HistoryMessage*> item, not_null<HistoryItem*> item,
const MTPMessageExtendedMedia &media) { const MTPMessageExtendedMedia &media) {
Expects(item == parent()); Expects(item == parent());

View file

@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class Image; class Image;
class History; class History;
class HistoryItem; class HistoryItem;
class HistoryMessage;
namespace base { namespace base {
template <typename Enum> template <typename Enum>
@ -140,7 +139,7 @@ public:
virtual bool updateInlineResultMedia(const MTPMessageMedia &media) = 0; virtual bool updateInlineResultMedia(const MTPMessageMedia &media) = 0;
virtual bool updateSentMedia(const MTPMessageMedia &media) = 0; virtual bool updateSentMedia(const MTPMessageMedia &media) = 0;
virtual bool updateExtendedMedia( virtual bool updateExtendedMedia(
not_null<HistoryMessage*> item, not_null<HistoryItem*> item,
const MTPMessageExtendedMedia &media) { const MTPMessageExtendedMedia &media) {
return false; return false;
} }
@ -428,7 +427,7 @@ public:
bool updateInlineResultMedia(const MTPMessageMedia &media) override; bool updateInlineResultMedia(const MTPMessageMedia &media) override;
bool updateSentMedia(const MTPMessageMedia &media) override; bool updateSentMedia(const MTPMessageMedia &media) override;
bool updateExtendedMedia( bool updateExtendedMedia(
not_null<HistoryMessage*> item, not_null<HistoryItem*> item,
const MTPMessageExtendedMedia &media) override; const MTPMessageExtendedMedia &media) override;
std::unique_ptr<HistoryView::Media> createView( std::unique_ptr<HistoryView::Media> createView(
not_null<HistoryView::Element*> message, not_null<HistoryView::Element*> message,
@ -541,7 +540,7 @@ private:
TextForMimeData &&caption); TextForMimeData &&caption);
[[nodiscard]] Invoice ComputeInvoiceData( [[nodiscard]] Invoice ComputeInvoiceData(
not_null<HistoryMessage*> item, not_null<HistoryItem*> item,
const MTPDmessageMediaInvoice &data); const MTPDmessageMediaInvoice &data);
[[nodiscard]] Call ComputeCallData(const MTPDmessageActionPhoneCall &call); [[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.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_service.h" #include "history/history_item_helpers.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "data/data_histories.h" #include "data/data_histories.h"
#include "data/data_session.h" #include "data/data_session.h"
@ -30,15 +30,15 @@ constexpr auto kMessagesPerPage = 50;
constexpr auto kReadRequestTimeout = 3 * crl::time(1000); constexpr auto kReadRequestTimeout = 3 * crl::time(1000);
constexpr auto kMaxMessagesToDeleteMyTopic = 10; constexpr auto kMaxMessagesToDeleteMyTopic = 10;
[[nodiscard]] HistoryService *GenerateDivider( [[nodiscard]] HistoryItem *GenerateDivider(
not_null<History*> history, not_null<History*> history,
TimeId date, TimeId date,
const QString &text) { const QString &text) {
return history->makeServiceMessage( return history->makeMessage(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
MessageFlag::FakeHistoryItem, MessageFlag::FakeHistoryItem,
date, date,
HistoryService::PreparedText{ { .text = text } }); PreparedServiceText{ { .text = text } });
} }
[[nodiscard]] bool IsCreating(not_null<History*> history, MsgId rootId) { [[nodiscard]] bool IsCreating(not_null<History*> history, MsgId rootId) {
@ -345,7 +345,7 @@ void RepliesList::injectRootDivider(
text()); text());
} else if (_dividerWithComments != withComments) { } else if (_dividerWithComments != withComments) {
_dividerWithComments = withComments; _dividerWithComments = withComments;
_divider->setServiceText(HistoryService::PreparedText{ { text() } }); _divider->updateServiceText(PreparedServiceText{ { text() } });
} }
slice->ids.push_back(_divider->fullId()); slice->ids.push_back(_divider->fullId());
} }

View file

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

View file

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

View file

@ -19,8 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class Image; class Image;
class HistoryItem; class HistoryItem;
class HistoryMessage;
class HistoryService;
struct WebPageCollage; struct WebPageCollage;
enum class WebPageType; enum class WebPageType;
enum class NewMessageType; 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_session.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "history/history.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/history_view_element.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "ui/image/image_location_factory.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_send_action.h"
#include "history/view/history_view_item_preview.h" #include "history/view/history_view_item_preview.h"
#include "history/history_unread_things.h" #include "history/history_unread_things.h"
#include "history/history_item_components.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_item_components.h"
#include "history/history_item_helpers.h"
#include "history/history.h" #include "history/history.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "data/data_channel.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/history.h"
#include "history/view/media/history_view_media.h" #include "history/view/media/history_view_media.h"
#include "history/view/media/history_view_web_page.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_components.h"
#include "history/history_item_text.h" #include "history/history_item_text.h"
#include "history/admin_log/history_admin_log_section.h" #include "history/admin_log/history_admin_log_section.h"
@ -582,18 +582,6 @@ HistoryView::Context InnerWidget::elementContext() {
return HistoryView::Context::AdminLog; 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( bool InnerWidget::elementUnderCursor(
not_null<const HistoryView::Element*> view) { not_null<const HistoryView::Element*> view) {
return (Element::Hovered() == view); return (Element::Hovered() == view);
@ -1294,7 +1282,6 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
_antiSpamValidator.addAction(_menu, itemId); _antiSpamValidator.addAction(_menu, itemId);
auto msg = dynamic_cast<HistoryMessage*>(item);
if (isUponSelected > 0) { if (isUponSelected > 0) {
_menu->addAction( _menu->addAction(
tr::lng_context_copy_selected(tr::now), tr::lng_context_copy_selected(tr::now),
@ -1311,7 +1298,7 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
}), &st::menuIconDownload); }), &st::menuIconDownload);
} }
} }
if (msg if (!item->isService()
&& !link && !link
&& (view->hasVisibleText() && (view->hasVisibleText()
|| mediaHasTextForCopy || mediaHasTextForCopy

View file

@ -91,12 +91,6 @@ public:
// HistoryView::ElementDelegate interface. // HistoryView::ElementDelegate interface.
HistoryView::Context elementContext() override; 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( bool elementUnderCursor(
not_null<const HistoryView::Element*> view) override; not_null<const HistoryView::Element*> view) override;
[[nodiscard]] float64 elementHighlightOpacity( [[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/admin_log/history_admin_log_inner.h"
#include "history/view/history_view_element.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.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_chat_participants.h"
#include "api/api_text_entities.h" #include "api/api_text_entities.h"
#include "data/data_channel.h" #include "data/data_channel.h"
@ -773,10 +773,10 @@ void GenerateItems(
const TextWithEntities &text, const TextWithEntities &text,
MsgId realId = MsgId(), MsgId realId = MsgId(),
PhotoData *photo = nullptr) { PhotoData *photo = nullptr) {
auto message = HistoryService::PreparedText{ text }; auto message = PreparedServiceText{ text };
message.links.push_back(fromLink); message.links.push_back(fromLink);
addPart( addPart(
history->makeServiceMessage( history->makeMessage(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
MessageFlag::AdminLogEntry, MessageFlag::AdminLogEntry,
date, date,
@ -1117,10 +1117,10 @@ void GenerateItems(
Ui::LayerOption::CloseOther); Ui::LayerOption::CloseOther);
} }
}); });
auto message = HistoryService::PreparedText { text }; auto message = PreparedServiceText{ text };
message.links.push_back(fromLink); message.links.push_back(fromLink);
message.links.push_back(setLink); message.links.push_back(setLink);
addPart(history->makeServiceMessage( addPart(history->makeMessage(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
MessageFlag::AdminLogEntry, MessageFlag::AdminLogEntry,
date, date,
@ -1198,10 +1198,10 @@ void GenerateItems(
window->showPeerHistory(now); window->showPeerHistory(now);
} }
}); });
auto message = HistoryService::PreparedText{ text }; auto message = PreparedServiceText{ text };
message.links.push_back(fromLink); message.links.push_back(fromLink);
message.links.push_back(chatLink); message.links.push_back(chatLink);
addPart(history->makeServiceMessage( addPart(history->makeMessage(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
MessageFlag::AdminLogEntry, MessageFlag::AdminLogEntry,
date, date,
@ -1294,10 +1294,10 @@ void GenerateItems(
const auto addServiceMessageWithLink = [&]( const auto addServiceMessageWithLink = [&](
const TextWithEntities &text, const TextWithEntities &text,
const ClickHandlerPtr &link) { const ClickHandlerPtr &link) {
auto message = HistoryService::PreparedText{ text }; auto message = PreparedServiceText{ text };
message.links.push_back(fromLink); message.links.push_back(fromLink);
message.links.push_back(link); message.links.push_back(link);
addPart(history->makeServiceMessage( addPart(history->makeMessage(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
MessageFlag::AdminLogEntry, MessageFlag::AdminLogEntry,
date, date,
@ -1363,7 +1363,7 @@ void GenerateItems(
const TextWithEntities &text, const TextWithEntities &text,
const MTPExportedChatInvite &data, const MTPExportedChatInvite &data,
ClickHandlerPtr additional = nullptr) { ClickHandlerPtr additional = nullptr) {
auto message = HistoryService::PreparedText{ text }; auto message = PreparedServiceText{ text };
message.links.push_back(fromLink); message.links.push_back(fromLink);
if (!ExtractInviteLink(data).endsWith(Ui::kQEllipsis)) { if (!ExtractInviteLink(data).endsWith(Ui::kQEllipsis)) {
message.links.push_back(std::make_shared<UrlClickHandler>( message.links.push_back(std::make_shared<UrlClickHandler>(
@ -1372,7 +1372,7 @@ void GenerateItems(
if (additional) { if (additional) {
message.links.push_back(std::move(additional)); message.links.push_back(std::move(additional));
} }
addPart(history->makeServiceMessage( addPart(history->makeMessage(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
MessageFlag::AdminLogEntry, MessageFlag::AdminLogEntry,
date, 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_element.h"
#include "history/view/history_view_item_preview.h" #include "history/view/history_view_item_preview.h"
#include "history/history_message.h" #include "history/history_item.h"
#include "history/history_service.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_item_helpers.h"
#include "history/history_inner_widget.h" #include "history/history_inner_widget.h"
#include "history/history_unread_things.h" #include "history/history_unread_things.h"
#include "dialogs/dialogs_indexed_list.h" #include "dialogs/dialogs_indexed_list.h"
@ -419,7 +419,9 @@ not_null<HistoryItem*> History::createItem(
} }
return result; 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( std::vector<not_null<HistoryItem*>> History::createItems(
@ -3080,7 +3082,7 @@ MsgRange History::rangeForDifferenceRequest() const {
return MsgRange(); return MsgRange();
} }
HistoryService *History::insertJoinedMessage() { HistoryItem *History::insertJoinedMessage() {
const auto channel = peer->asChannel(); const auto channel = peer->asChannel();
if (!channel if (!channel
|| _joinedMessage || _joinedMessage

View file

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

View file

@ -11,7 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/crash_reports.h" #include "core/crash_reports.h"
#include "core/click_handler_types.h" #include "core/click_handler_types.h"
#include "history/history.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_media.h"
#include "history/view/media/history_view_sticker.h" #include "history/view/media/history_view_sticker.h"
#include "history/view/media/history_view_web_page.h" #include "history/view/media/history_view_web_page.h"
@ -145,22 +146,6 @@ public:
HistoryView::Context elementContext() override { HistoryView::Context elementContext() override {
return HistoryView::Context::History; 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( bool elementUnderCursor(
not_null<const Element*> view) override { not_null<const Element*> view) override {
return (Element::Moused() == view); 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> #include <any>
class HiddenSenderInfo;
class History;
struct HistoryMessageReply;
struct HistoryMessageViews;
struct HistoryMessageMarkupData;
struct HistoryMessageReplyMarkup; struct HistoryMessageReplyMarkup;
struct HistoryServiceDependentData;
enum class HistorySelfDestructType;
struct PreparedServiceText;
class ReplyKeyboard; class ReplyKeyboard;
class HistoryMessage;
namespace base { namespace base {
template <typename Enum> template <typename Enum>
@ -47,6 +54,7 @@ struct MessageReaction;
class MessageReactions; class MessageReactions;
class ForumTopic; class ForumTopic;
class Thread; class Thread;
struct SponsoredFrom;
} // namespace Data } // namespace Data
namespace Main { namespace Main {
@ -68,46 +76,120 @@ enum class CursorState : char;
enum class PointState : char; enum class PointState : char;
enum class Context : char; enum class Context : char;
class ElementDelegate; class ElementDelegate;
class Element;
class Message;
class Service;
class ServiceMessagePainter;
} // namespace HistoryView } // namespace HistoryView
class HiddenSenderInfo; class HistoryItem final : public RuntimeComposer<HistoryItem> {
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> {
public: 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, not_null<History*> history,
MsgId id, MsgId id,
const MTPMessage &message, const MTPDmessage &data,
MessageFlags localFlags); 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 { struct Destroyer {
void operator()(HistoryItem *value); void operator()(HistoryItem *value);
}; };
virtual void dependencyItemRemoved(HistoryItem *dependency) { void dependencyItemRemoved(not_null<HistoryItem*> dependency);
} void updateDependencyItem();
virtual bool updateDependencyItem() { [[nodiscard]] MsgId dependencyMsgId() const;
return true; [[nodiscard]] bool notificationReady() const;
}
virtual MsgId dependencyMsgId() const {
return 0;
}
virtual void checkBuyButton() {
}
[[nodiscard]] virtual bool notificationReady() const {
return true;
}
[[nodiscard]] PeerData *specialNotificationPeer() const; [[nodiscard]] PeerData *specialNotificationPeer() const;
void checkBuyButton();
void updateServiceText(PreparedServiceText &&text);
[[nodiscard]] UserData *viaBot() const; [[nodiscard]] UserData *viaBot() const;
[[nodiscard]] UserData *getMessageBot() const; [[nodiscard]] UserData *getMessageBot() const;
@ -165,15 +247,13 @@ public:
void setIsPinned(bool isPinned); void setIsPinned(bool isPinned);
// For edit media in history_message. // For edit media in history_message.
virtual void returnSavedMedia(); void returnSavedMedia();
void savePreviousMedia(); void savePreviousMedia();
[[nodiscard]] bool isEditingMedia() const; [[nodiscard]] bool isEditingMedia() const;
void clearSavedMedia(); void clearSavedMedia();
// Zero result means this message is not self-destructing right now. // Zero result means this message is not self-destructing right now.
virtual crl::time getSelfDestructIn(crl::time now) { [[nodiscard]] crl::time getSelfDestructIn(crl::time now);
return 0;
}
[[nodiscard]] bool definesReplyKeyboard() const; [[nodiscard]] bool definesReplyKeyboard() const;
[[nodiscard]] ReplyMarkupFlags replyKeyboardFlags() const; [[nodiscard]] ReplyMarkupFlags replyKeyboardFlags() const;
@ -224,118 +304,75 @@ public:
[[nodiscard]] bool isRegular() const; [[nodiscard]] bool isRegular() const;
[[nodiscard]] bool isUploading() const; [[nodiscard]] bool isUploading() const;
void sendFailed(); void sendFailed();
[[nodiscard]] virtual int viewsCount() const { [[nodiscard]] int viewsCount() const;
return hasViews() ? 1 : -1; [[nodiscard]] int repliesCount() const;
} [[nodiscard]] bool repliesAreComments() const;
[[nodiscard]] virtual int repliesCount() const { [[nodiscard]] bool externalReply() const;
return 0;
}
[[nodiscard]] virtual bool repliesAreComments() const {
return false;
}
[[nodiscard]] virtual bool externalReply() const {
return false;
}
[[nodiscard]] bool hasExtendedMediaPreview() const; [[nodiscard]] bool hasExtendedMediaPreview() const;
virtual void setCommentsInboxReadTill(MsgId readTillId) { void setCommentsInboxReadTill(MsgId readTillId);
} void setCommentsMaxId(MsgId maxId);
virtual void setCommentsMaxId(MsgId maxId) { void setCommentsPossibleMaxId(MsgId possibleMaxId);
} [[nodiscard]] bool areCommentsUnread() const;
virtual void setCommentsPossibleMaxId(MsgId possibleMaxId) {
}
[[nodiscard]] virtual bool areCommentsUnread() const {
return false;
}
[[nodiscard]] virtual FullMsgId commentsItemId() const { [[nodiscard]] FullMsgId commentsItemId() const;
return FullMsgId(); void setCommentsItemId(FullMsgId id);
}
virtual void setCommentsItemId(FullMsgId id) {
}
[[nodiscard]] virtual bool needCheck() const; [[nodiscard]] bool needCheck() const;
[[nodiscard]] virtual bool isService() const { [[nodiscard]] bool isService() const;
return false; void applyEdition(HistoryMessageEdition &&edition);
}
virtual void applyEdition(HistoryMessageEdition &&edition) { void applyEdition(const MTPDmessageService &message);
} void applyEdition(const MTPMessageExtendedMedia &media);
virtual void applyEdition(const MTPDmessageService &message) { void updateForwardedInfo(const MTPMessageFwdHeader *fwd);
} void updateSentContent(
virtual void applyEdition(const MTPMessageExtendedMedia &media) {
}
void applyEditionToHistoryCleared();
virtual void updateSentContent(
const TextWithEntities &textWithEntities, const TextWithEntities &textWithEntities,
const MTPMessageMedia *media) { const MTPMessageMedia *media);
} void applySentMessage(const MTPDmessage &data);
virtual void updateReplyMarkup(HistoryMessageMarkupData &&markup) { void applySentMessage(
}
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 QString &text, const QString &text,
const MTPDupdateShortSentMessage &data, const MTPDupdateShortSentMessage &data,
bool wasAlready); 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(); void indexAsNewItem();
[[nodiscard]] virtual QString notificationHeader() const { [[nodiscard]] QString notificationHeader() const;
return QString(); [[nodiscard]] TextWithEntities notificationText() const;
}
[[nodiscard]] virtual TextWithEntities notificationText() const;
using ToPreviewOptions = HistoryView::ToPreviewOptions; using ToPreviewOptions = HistoryView::ToPreviewOptions;
using ItemPreview = HistoryView::ItemPreview; using ItemPreview = HistoryView::ItemPreview;
// Returns text with link-start and link-end commands for service-color highlighting. // 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" // Example: "[link1-start]You:[link1-end] [link1-start]Photo,[link1-end] caption text"
[[nodiscard]] virtual ItemPreview toPreview( [[nodiscard]] ItemPreview toPreview(ToPreviewOptions options) const;
ToPreviewOptions options) const; [[nodiscard]] TextWithEntities inReplyText() const;
[[nodiscard]] virtual TextWithEntities inReplyText() const; [[nodiscard]] TextWithEntities originalText() const;
[[nodiscard]] virtual TextWithEntities originalText() const { [[nodiscard]] TextWithEntities originalTextWithLocalEntities() const;
return TextWithEntities(); [[nodiscard]] const std::vector<ClickHandlerPtr> &customTextLinks() const;
} [[nodiscard]] TextForMimeData clipboardText() const;
[[nodiscard]] virtual auto originalTextWithLocalEntities() const
-> TextWithEntities {
return TextWithEntities();
}
[[nodiscard]] virtual auto customTextLinks() const
-> const std::vector<ClickHandlerPtr> &;
[[nodiscard]] virtual TextForMimeData clipboardText() const {
return TextForMimeData();
}
virtual bool changeViewsCount(int count) { bool changeViewsCount(int count);
return false; void setForwardsCount(int count);
} void setReplies(HistoryMessageRepliesData &&data);
virtual void setForwardsCount(int count) { void clearReplies();
} void changeRepliesCount(int delta, PeerId replier);
virtual void setReplies(HistoryMessageRepliesData &&data) { void setReplyFields(
}
virtual void clearReplies() {
}
virtual void changeRepliesCount(int delta, PeerId replier) {
}
virtual void setReplyFields(
MsgId replyTo, MsgId replyTo,
MsgId replyToTop, MsgId replyToTop,
bool isForumPost) = 0; bool isForumPost);
virtual void setPostAuthor(const QString &author) { void setPostAuthor(const QString &author);
} void setRealId(MsgId newId);
virtual void setRealId(MsgId newId); void incrementReplyToTopCounter();
virtual void incrementReplyToTopCounter() {
}
[[nodiscard]] bool emptyText() const { [[nodiscard]] bool emptyText() const {
return _text.empty(); return _text.empty();
@ -346,9 +383,9 @@ public:
[[nodiscard]] bool canStopPoll() const; [[nodiscard]] bool canStopPoll() const;
[[nodiscard]] bool forbidsForward() const; [[nodiscard]] bool forbidsForward() const;
[[nodiscard]] bool forbidsSaving() const; [[nodiscard]] bool forbidsSaving() const;
[[nodiscard]] virtual bool allowsSendNow() const; [[nodiscard]] bool allowsSendNow() const;
[[nodiscard]] virtual bool allowsForward() const; [[nodiscard]] bool allowsForward() const;
[[nodiscard]] virtual bool allowsEdit(TimeId now) const; [[nodiscard]] bool allowsEdit(TimeId now) const;
[[nodiscard]] bool canDelete() const; [[nodiscard]] bool canDelete() const;
[[nodiscard]] bool canDeleteForEveryone(TimeId now) const; [[nodiscard]] bool canDeleteForEveryone(TimeId now) const;
[[nodiscard]] bool suggestReport() const; [[nodiscard]] bool suggestReport() const;
@ -364,7 +401,6 @@ public:
void toggleReaction( void toggleReaction(
const Data::ReactionId &reaction, const Data::ReactionId &reaction,
ReactionSource source); ReactionSource source);
void updateReactions(const MTPMessageReactions *reactions);
void updateReactionsUnknown(); void updateReactionsUnknown();
[[nodiscard]] auto reactions() const [[nodiscard]] auto reactions() const
-> const std::vector<Data::MessageReaction> &; -> const std::vector<Data::MessageReaction> &;
@ -391,12 +427,11 @@ public:
return _media.get(); return _media.get();
} }
[[nodiscard]] bool computeDropForwardedInfo() const; [[nodiscard]] bool computeDropForwardedInfo() const;
virtual void setText(const TextWithEntities &textWithEntities) { void setText(const TextWithEntities &textWithEntities);
}
[[nodiscard]] virtual MsgId replyToId() const = 0; [[nodiscard]] MsgId replyToId() const;
[[nodiscard]] virtual MsgId replyToTop() const = 0; [[nodiscard]] MsgId replyToTop() const;
[[nodiscard]] virtual MsgId topicRootId() const = 0; [[nodiscard]] MsgId topicRootId() const;
[[nodiscard]] bool inThread(MsgId rootId) const; [[nodiscard]] bool inThread(MsgId rootId) const;
[[nodiscard]] not_null<PeerData*> author() const; [[nodiscard]] not_null<PeerData*> author() const;
@ -426,9 +461,9 @@ public:
[[nodiscard]] HistoryItem *lookupDiscussionPostOriginal() const; [[nodiscard]] HistoryItem *lookupDiscussionPostOriginal() const;
[[nodiscard]] PeerData *displayFrom() 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, not_null<HistoryView::ElementDelegate*> delegate,
HistoryView::Element *replacing = nullptr) = 0; HistoryView::Element *replacing = nullptr);
void updateDate(TimeId newDate); void updateDate(TimeId newDate);
[[nodiscard]] bool canUpdateDate() const; [[nodiscard]] bool canUpdateDate() const;
@ -438,11 +473,16 @@ public:
return _ttlDestroyAt; return _ttlDestroyAt;
} }
virtual ~HistoryItem();
MsgId id; MsgId id;
protected: private:
struct CreateConfig;
struct SavedMediaData {
TextWithEntities text;
std::unique_ptr<Data::Media> media;
};
HistoryItem( HistoryItem(
not_null<History*> history, not_null<History*> history,
MsgId id, MsgId id,
@ -450,63 +490,113 @@ protected:
TimeId date, TimeId date,
PeerId from); 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 finishEdition(int oldKeyboardTop);
void finishEditionToEmpty(); 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); void setReactions(const MTPMessageReactions *reactions);
[[nodiscard]] bool changeReactions(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<History*> _history;
const not_null<PeerData*> _from; const not_null<PeerData*> _from;
MessageFlags _flags = 0; MessageFlags _flags = 0;
void setGroupId(MessageGroupId groupId);
void applyTTL(const MTPDmessage &data);
void applyTTL(const MTPDmessageService &data);
void applyTTL(TimeId destroyAt);
TextWithEntities _text; TextWithEntities _text;
struct SavedMediaData {
TextWithEntities text;
std::unique_ptr<Data::Media> media;
};
std::unique_ptr<SavedMediaData> _savedLocalEditMediaData; std::unique_ptr<SavedMediaData> _savedLocalEditMediaData;
std::unique_ptr<Data::Media> _media; std::unique_ptr<Data::Media> _media;
std::unique_ptr<Data::MessageReactions> _reactions; std::unique_ptr<Data::MessageReactions> _reactions;
crl::time _reactionsLastRefreshed = 0; crl::time _reactionsLastRefreshed = 0;
private:
TimeId _date = 0; TimeId _date = 0;
TimeId _ttlDestroyAt = 0; TimeId _ttlDestroyAt = 0;
HistoryView::Element *_mainView = nullptr; HistoryView::Element *_mainView = nullptr;
friend class HistoryView::Element;
MessageGroupId _groupId = MessageGroupId(); 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/chat/chat_theme.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "history/history.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_message.h" // FromNameFg.
#include "history/view/history_view_service_message.h" #include "history/view/history_view_service_message.h"
#include "history/view/media/history_view_document.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.setMarkedText(st::fwdTextStyle, phrase);
text.setLink(1, fromChannel text.setLink(1, fromChannel
? goToMessageClickHandler(originalSender, originalId) ? JumpToMessageClickHandler(originalSender, originalId)
: originalSender : originalSender
? originalSender->openLink() ? originalSender->openLink()
: HiddenSenderInfo::ForwardClickHandler()); : HiddenSenderInfo::ForwardClickHandler());
@ -254,7 +255,7 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
} }
bool HistoryMessageReply::updateData( bool HistoryMessageReply::updateData(
not_null<HistoryMessage*> holder, not_null<HistoryItem*> holder,
bool force) { bool force) {
const auto guard = gsl::finally([&] { refreshReplyToMedia(); }); const auto guard = gsl::finally([&] { refreshReplyToMedia(); });
if (!force) { if (!force) {
@ -322,13 +323,13 @@ bool HistoryMessageReply::updateData(
} }
void HistoryMessageReply::setReplyToLinkFrom( void HistoryMessageReply::setReplyToLinkFrom(
not_null<HistoryMessage*> holder) { not_null<HistoryItem*> holder) {
replyToLnk = replyToMsg replyToLnk = replyToMsg
? goToMessageClickHandler(replyToMsg.get(), holder->fullId()) ? JumpToMessageClickHandler(replyToMsg.get(), holder->fullId())
: nullptr; : nullptr;
} }
void HistoryMessageReply::clearData(not_null<HistoryMessage*> holder) { void HistoryMessageReply::clearData(not_null<HistoryItem*> holder) {
replyToVia = nullptr; replyToVia = nullptr;
if (replyToMsg) { if (replyToMsg) {
holder->history()->owner().unregisterDependentMessage( holder->history()->owner().unregisterDependentMessage(
@ -341,7 +342,7 @@ void HistoryMessageReply::clearData(not_null<HistoryMessage*> holder) {
} }
PeerData *HistoryMessageReply::replyToFrom( PeerData *HistoryMessageReply::replyToFrom(
not_null<HistoryMessage*> holder) const { not_null<HistoryItem*> holder) const {
if (!replyToMsg) { if (!replyToMsg) {
return nullptr; return nullptr;
} else if (holder->Has<HistoryMessageForwarded>()) { } else if (holder->Has<HistoryMessageForwarded>()) {
@ -356,7 +357,7 @@ PeerData *HistoryMessageReply::replyToFrom(
} }
QString HistoryMessageReply::replyToFromName( QString HistoryMessageReply::replyToFromName(
not_null<HistoryMessage*> holder) const { not_null<HistoryItem*> holder) const {
if (!replyToMsg) { if (!replyToMsg) {
return QString(); return QString();
} else if (holder->Has<HistoryMessageForwarded>()) { } else if (holder->Has<HistoryMessageForwarded>()) {
@ -381,7 +382,7 @@ QString HistoryMessageReply::replyToFromName(
} }
bool HistoryMessageReply::isNameUpdated( bool HistoryMessageReply::isNameUpdated(
not_null<HistoryMessage*> holder) const { not_null<HistoryItem*> holder) const {
if (const auto from = replyToFrom(holder)) { if (const auto from = replyToFrom(holder)) {
if (replyToVersion < from->nameVersion()) { if (replyToVersion < from->nameVersion()) {
updateName(holder); updateName(holder);
@ -392,7 +393,7 @@ bool HistoryMessageReply::isNameUpdated(
} }
void HistoryMessageReply::updateName( void HistoryMessageReply::updateName(
not_null<HistoryMessage*> holder) const { not_null<HistoryItem*> holder) const {
if (const auto name = replyToFromName(holder); !name.isEmpty()) { if (const auto name = replyToFromName(holder); !name.isEmpty()) {
replyToName.setText(st::fwdTextStyle, name, Ui::NameTextOptions()); replyToName.setText(st::fwdTextStyle, name, Ui::NameTextOptions());
if (const auto from = replyToFrom(holder)) { if (const auto from = replyToFrom(holder)) {
@ -423,7 +424,7 @@ void HistoryMessageReply::resize(int width) const {
} }
void HistoryMessageReply::itemRemoved( void HistoryMessageReply::itemRemoved(
HistoryMessage *holder, HistoryItem *holder,
HistoryItem *removed) { HistoryItem *removed) {
if (replyToMsg.get() == removed) { if (replyToMsg.get() == removed) {
clearData(holder); clearData(holder);

View file

@ -195,20 +195,19 @@ struct HistoryMessageReply
Expects(replyToVia == nullptr); 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. // Must be called before destructor.
void clearData(not_null<HistoryMessage*> holder); void clearData(not_null<HistoryItem*> holder);
[[nodiscard]] PeerData *replyToFrom( [[nodiscard]] PeerData *replyToFrom(not_null<HistoryItem*> holder) const;
not_null<HistoryMessage*> holder) const;
[[nodiscard]] QString replyToFromName( [[nodiscard]] QString replyToFromName(
not_null<HistoryMessage*> holder) const; not_null<HistoryItem*> holder) const;
[[nodiscard]] QString replyToFromName(not_null<PeerData*> peer) const; [[nodiscard]] QString replyToFromName(not_null<PeerData*> peer) const;
[[nodiscard]] bool isNameUpdated(not_null<HistoryMessage*> holder) const; [[nodiscard]] bool isNameUpdated(not_null<HistoryItem*> holder) const;
void updateName(not_null<HistoryMessage*> holder) const; void updateName(not_null<HistoryItem*> holder) const;
void resize(int width) const; void resize(int width) const;
void itemRemoved(HistoryMessage *holder, HistoryItem *removed); void itemRemoved(HistoryItem *holder, HistoryItem *removed);
void paint( void paint(
Painter &p, Painter &p,
@ -234,8 +233,7 @@ struct HistoryMessageReply
[[nodiscard]] ClickHandlerPtr replyToLink() const { [[nodiscard]] ClickHandlerPtr replyToLink() const {
return replyToLnk; return replyToLnk;
} }
void setReplyToLinkFrom( void setReplyToLinkFrom(not_null<HistoryItem*> holder);
not_null<HistoryMessage*> holder);
void refreshReplyToMedia(); void refreshReplyToMedia();
@ -452,7 +450,7 @@ private:
// Special type of Component for the channel actions log. // Special type of Component for the channel actions log.
struct HistoryMessageLogEntryOriginal struct HistoryMessageLogEntryOriginal
: public RuntimeComponent<HistoryMessageLogEntryOriginal, HistoryItem> { : public RuntimeComponent<HistoryMessageLogEntryOriginal, HistoryItem> {
HistoryMessageLogEntryOriginal(); HistoryMessageLogEntryOriginal();
HistoryMessageLogEntryOriginal(HistoryMessageLogEntryOriginal &&other); HistoryMessageLogEntryOriginal(HistoryMessageLogEntryOriginal &&other);
HistoryMessageLogEntryOriginal &operator=(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; class FileClickHandler;
struct HistoryDocumentThumbed : public RuntimeComponent<HistoryDocumentThumbed, HistoryView::Document> { struct HistoryDocumentThumbed : public RuntimeComponent<HistoryDocumentThumbed, HistoryView::Document> {
std::shared_ptr<FileClickHandler> linksavel; 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 "data/stickers/data_custom_emoji.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.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_drag_area.h"
#include "history/history_inner_widget.h" #include "history/history_inner_widget.h"
#include "history/history_item_components.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/view/controls/history_view_forward_panel.h"
#include "history/history.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/history_item_components.h"
#include "history/view/history_view_item_preview.h" #include "history/view/history_view_item_preview.h"
#include "data/data_session.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 "ui/painter.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_message.h" #include "history/history_item.h"
#include "history/history.h" #include "history/history.h"
#include "history/view/history_view_message.h" #include "history/view/history_view_message.h"
#include "history/view/history_view_cursor_state.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) { BottomInfo::Data BottomInfoDataFromMessage(not_null<Message*> message) {
using Flag = BottomInfo::Data::Flag; using Flag = BottomInfo::Data::Flag;
const auto item = message->message(); const auto item = message->data();
auto result = BottomInfo::Data(); auto result = BottomInfo::Data();
result.date = message->dateTime(); 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/view/history_view_cursor_state.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_message.h"
#include "history/history_item_text.h" #include "history/history_item_text.h"
#include "history/view/history_view_schedule_box.h" #include "history/view/history_view_schedule_box.h"
#include "history/view/media/history_view_media.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 "api/api_chat_invite.h"
#include "history/view/history_view_service_message.h" #include "history/view/history_view_service_message.h"
#include "history/view/history_view_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.h"
#include "history/view/media/history_view_media_grouped.h" #include "history/view/media/history_view_media_grouped.h"
#include "history/view/media/history_view_sticker.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_cursor_state.h"
#include "history/view/history_view_spoiler_click_handler.h" #include "history/view/history_view_spoiler_click_handler.h"
#include "history/history.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 "base/unixtime.h"
#include "core/application.h" #include "core/application.h"
#include "core/core_settings.h" #include "core/core_settings.h"
@ -118,18 +118,6 @@ SimpleElementDelegate::SimpleElementDelegate(
SimpleElementDelegate::~SimpleElementDelegate() = default; 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( bool SimpleElementDelegate::elementUnderCursor(
not_null<const Element*> view) { not_null<const Element*> view) {
return false; return false;

View file

@ -15,8 +15,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class History; class History;
class HistoryBlock; class HistoryBlock;
class HistoryItem; class HistoryItem;
class HistoryMessage;
class HistoryService;
struct HistoryMessageReply; struct HistoryMessageReply;
namespace Data { namespace Data {
@ -64,12 +62,6 @@ class Element;
class ElementDelegate { class ElementDelegate {
public: public:
virtual Context elementContext() = 0; 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; virtual bool elementUnderCursor(not_null<const Element*> view) = 0;
[[nodiscard]] virtual float64 elementHighlightOpacity( [[nodiscard]] virtual float64 elementHighlightOpacity(
not_null<const HistoryItem*> item) const = 0; not_null<const HistoryItem*> item) const = 0;
@ -126,12 +118,6 @@ public:
Fn<void()> update); Fn<void()> update);
~SimpleElementDelegate(); ~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; bool elementUnderCursor(not_null<const Element*> view) override;
[[nodiscard]] float64 elementHighlightOpacity( [[nodiscard]] float64 elementHighlightOpacity(
not_null<const HistoryItem*> item) const override; 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/unixtime.h"
#include "base/qt/qt_key_modifiers.h" #include "base/qt/qt_key_modifiers.h"
#include "base/qt/qt_common_adapters.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_components.h"
#include "history/history_item_helpers.h"
#include "history/history_item_text.h" #include "history/history_item_text.h"
#include "history/view/media/history_view_media.h" #include "history/view/media/history_view_media.h"
#include "history/view/media/history_view_sticker.h" #include "history/view/media/history_view_sticker.h"
@ -1614,18 +1615,6 @@ Context ListWidget::elementContext() {
return _delegate->listContext(); 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( bool ListWidget::elementUnderCursor(
not_null<const HistoryView::Element*> view) { not_null<const HistoryView::Element*> view) {
return (_overElement == view); return (_overElement == view);

View file

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

View file

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_chat.h" #include "data/data_chat.h"
#include "data/data_channel.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 "storage/localstorage.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_message.h" #include "history/history_item.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "ui/text/format_values.h" // Ui::FormatPhone #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 "dialogs/dialogs_key.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_widget.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/media/history_view_media.h"
#include "history/view/history_view_service_message.h" #include "history/view/history_view_service_message.h"
#include "history/view/history_view_element.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_player.h"
#include "styles/style_media_view.h" #include "styles/style_media_view.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "storage/storage_account.h" #include "storage/storage_account.h"
#include "main/main_session.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/streaming/media_streaming_player.h"
#include "media/player/media_player_instance.h" #include "media/player/media_player_instance.h"
#include "history/history.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_media.h"
#include "data/data_media_types.h" #include "data/data_media_types.h"
#include "data/data_session.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.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_item_helpers.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/view/media/history_view_document.h" // DrawThumbnailAsSongCover #include "history/view/media/history_view_document.h" // DrawThumbnailAsSongCover
#include "base/unixtime.h" #include "base/unixtime.h"
@ -644,7 +645,7 @@ Voice::Voice(
lt_duration, lt_duration,
{ .text = Ui::FormatDurationText(duration()) }, { .text = Ui::FormatDurationText(duration()) },
Ui::Text::WithEntities)); Ui::Text::WithEntities));
_details.setLink(1, goToMessageClickHandler(parent)); _details.setLink(1, JumpToMessageClickHandler(parent));
} }
void Voice::initDimensions() { void Voice::initDimensions() {
@ -944,7 +945,9 @@ Document::Document(
const style::OverviewFileLayout &st) const style::OverviewFileLayout &st)
: RadialProgressItem(delegate, parent) : RadialProgressItem(delegate, parent)
, _data(fields.document) , _data(fields.document)
, _msgl(parent->isHistoryEntry() ? goToMessageClickHandler(parent) : nullptr) , _msgl(parent->isHistoryEntry()
? JumpToMessageClickHandler(parent)
: nullptr)
, _namel(std::make_shared<DocumentOpenClickHandler>( , _namel(std::make_shared<DocumentOpenClickHandler>(
_data, _data,
crl::guard(this, [=](FullMsgId id) { 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 "data/data_file_origin.h"
#include "countries/countries_instance.h" #include "countries/countries_instance.h"
#include "history/history_item.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_api_client.h"
#include "stripe/stripe_error.h" #include "stripe/stripe_error.h"
#include "stripe/stripe_token.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_element.h"
#include "history/view/history_view_message.h" #include "history/view/history_view_message.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/history_message.h" #include "history/history_item.h"
#include "history/history.h" #include "history/history.h"
#include "calls/calls_instance.h" #include "calls/calls_instance.h"
#include "base/unixtime.h" #include "base/unixtime.h"
@ -188,7 +188,7 @@ AdminLog::OwnedItem GenerateForwardedItem(
history->nextNonHistoryEntryId(), history->nextNonHistoryEntryId(),
data, data,
MessageFlag::FakeHistoryItem); MessageFlag::FakeHistoryItem);
}, [](auto &&) -> not_null<HistoryMessage*> { }, [](auto &&) -> not_null<HistoryItem*> {
Unexpected("Type in GenerateForwardedItem."); Unexpected("Type in GenerateForwardedItem.");
}); });

View file

@ -18,7 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "support/support_common.h" #include "support/support_common.h"
#include "history/view/history_view_message.h" #include "history/view/history_view_message.h"
#include "history/view/history_view_service_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 "lang/lang_keys.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "base/call_delayed.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 "api/api_updates.h"
#include "mtproto/mtproto_config.h" #include "mtproto/mtproto_config.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item_helpers.h" // GetErrorTextForSending.
#include "history/history_message.h" // GetErrorTextForSending.
#include "history/view/history_view_context_menu.h" #include "history/view/history_view_context_menu.h"
#include "window/window_adaptive.h" // Adaptive::isThreeColumn #include "window/window_adaptive.h" // Adaptive::isThreeColumn
#include "window/window_session_controller.h" #include "window/window_session_controller.h"