tdesktop/Telegram/SourceFiles/history/history_service.h

183 lines
4.5 KiB
C
Raw Normal View History

/*
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 {
2021-03-30 11:43:47 +00:00
PeerId peerId = 0;
MsgId msgId = 0;
HistoryItem *msg = nullptr;
ClickHandlerPtr lnk;
};
struct HistoryServicePinned
2020-12-01 14:17:05 +00:00
: public RuntimeComponent<HistoryServicePinned, HistoryItem>
, public HistoryServiceDependentData {
};
struct HistoryServiceGameScore
2020-12-01 14:17:05 +00:00
: public RuntimeComponent<HistoryServiceGameScore, HistoryItem>
, public HistoryServiceDependentData {
int score = 0;
};
struct HistoryServicePayment
2020-12-01 14:17:05 +00:00
: public RuntimeComponent<HistoryServicePayment, HistoryItem>
, public HistoryServiceDependentData {
QString amount;
2021-03-30 11:43:47 +00:00
ClickHandlerPtr invoiceLink;
};
struct HistoryServiceSelfDestruct
2020-12-01 14:17:05 +00:00
: public RuntimeComponent<HistoryServiceSelfDestruct, HistoryItem> {
enum class Type {
Photo,
Video,
};
Type type = Type::Photo;
crl::time timeToLive = 0;
crl::time destructAt = 0;
};
2020-12-01 14:17:05 +00:00
struct HistoryServiceOngoingCall
: public RuntimeComponent<HistoryServiceOngoingCall, HistoryItem> {
2021-10-24 21:33:53 +00:00
CallId id = 0;
ClickHandlerPtr link;
2020-12-01 14:17:05 +00:00
rpl::lifetime lifetime;
};
2018-01-09 17:08:31 +00:00
namespace HistoryView {
class ServiceMessagePainter;
2018-01-09 17:08:31 +00:00
} // namespace HistoryView
2018-01-18 20:02:50 +00:00
class HistoryService : public HistoryItem {
public:
struct PreparedText {
QString text;
QList<ClickHandlerPtr> links;
};
2018-01-18 20:02:50 +00:00
HistoryService(
not_null<History*> history,
MsgId id,
const MTPDmessage &data,
2021-07-28 11:55:02 +00:00
MessageFlags localFlags);
2018-01-18 20:02:50 +00:00
HistoryService(
not_null<History*> history,
MsgId id,
const MTPDmessageService &data,
2021-07-28 11:55:02 +00:00
MessageFlags localFlags);
HistoryService(
not_null<History*> history,
MsgId id,
2021-07-28 11:55:02 +00:00
MessageFlags flags,
TimeId date,
const PreparedText &message,
PeerId from = 0,
2018-01-18 20:02:50 +00:00
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;
}
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;
QString inReplyText() const override;
std::unique_ptr<HistoryView::Element> createView(
not_null<HistoryView::ElementDelegate*> delegate,
HistoryView::Element *replacing = nullptr) override;
void setServiceText(const PreparedText &prepared);
~HistoryService();
protected:
2018-01-09 17:08:31 +00:00
friend class HistoryView::ServiceMessagePainter;
void markMediaAsReadHook() override;
QString fromLinkText() const;
ClickHandlerPtr fromLink() const;
void removeMedia();
private:
HistoryServiceDependentData *GetDependentData() {
if (auto pinned = Get<HistoryServicePinned>()) {
return pinned;
} else if (auto gamescore = Get<HistoryServiceGameScore>()) {
return gamescore;
} else if (auto payment = Get<HistoryServicePayment>()) {
return payment;
}
return nullptr;
}
const HistoryServiceDependentData *GetDependentData() const {
return const_cast<HistoryService*>(this)->GetDependentData();
}
bool updateDependent(bool force = false);
void updateDependentText();
2020-12-01 14:17:05 +00:00
void updateText(PreparedText &&text);
void clearDependency();
void createFromMtp(const MTPDmessage &message);
void createFromMtp(const MTPDmessageService &message);
void setMessageByAction(const MTPmessageAction &action);
2019-01-15 11:57:45 +00:00
void setSelfDestruct(
HistoryServiceSelfDestruct::Type type,
int ttlSeconds);
void applyAction(const MTPMessageAction &action);
PreparedText preparePinnedText();
PreparedText prepareGameScoreText();
PreparedText preparePaymentSentText();
PreparedText prepareInvitedToCallText(
2021-08-25 08:15:05 +00:00
const QVector<MTPlong> &users,
2021-10-24 21:33:53 +00:00
CallId linkCallId);
PreparedText prepareCallScheduledText(
TimeId scheduleDate);
friend class HistoryView::Service;
};
[[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,
2021-10-24 21:33:53 +00:00
CallId id);