/* 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 , public HistoryServiceDependentData { }; struct HistoryServiceTopicInfo : public RuntimeComponent , public HistoryServiceDependentData { QString title; DocumentId iconId = 0; bool closed = false; bool reopened = false; bool reiconed = false; bool renamed = false; }; struct HistoryServiceGameScore : public RuntimeComponent , public HistoryServiceDependentData { int score = 0; }; struct HistoryServicePayment : public RuntimeComponent , public HistoryServiceDependentData { QString slug; QString amount; ClickHandlerPtr invoiceLink; bool recurringInit = false; bool recurringUsed = false; }; struct HistoryServiceSelfDestruct : public RuntimeComponent { enum class Type { Photo, Video, }; Type type = Type::Photo; crl::time timeToLive = 0; crl::time destructAt = 0; }; struct HistoryServiceOngoingCall : public RuntimeComponent { CallId id = 0; ClickHandlerPtr link; rpl::lifetime lifetime; }; struct HistoryServiceChatThemeChange : public RuntimeComponent { ClickHandlerPtr link; }; struct HistoryServiceTTLChange : public RuntimeComponent { ClickHandlerPtr link; }; namespace HistoryView { class ServiceMessagePainter; } // namespace HistoryView class HistoryService : public HistoryItem { public: struct PreparedText { TextWithEntities text; std::vector links; }; HistoryService( not_null history, MsgId id, const MTPDmessage &data, MessageFlags localFlags); HistoryService( not_null history, MsgId id, const MTPDmessageService &data, MessageFlags localFlags); HistoryService( not_null 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 &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 createView( not_null 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()) { return pinned; } else if (const auto gamescore = Get()) { return gamescore; } else if (const auto payment = Get()) { return payment; } else if (const auto info = Get()) { return info; } return nullptr; } const HistoryServiceDependentData *GetDependentData() const { return const_cast(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 &users, CallId linkCallId); PreparedText prepareCallScheduledText( TimeId scheduleDate); friend class HistoryView::Service; std::vector _textLinks; }; [[nodiscard]] not_null GenerateJoinedMessage( not_null history, TimeId inviteDate, not_null inviter, bool viaRequest); [[nodiscard]] std::optional PeerHasThisCall( not_null peer, CallId id);