2017-06-22 15:11:41 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-06-22 15:11:41 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-06-22 15:11:41 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/history_item.h"
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
namespace HistoryView {
|
|
|
|
class Service;
|
|
|
|
} // namespace HistoryView
|
|
|
|
|
2017-06-22 15:11:41 +00:00
|
|
|
struct HistoryServiceDependentData {
|
2021-03-30 11:43:47 +00:00
|
|
|
PeerId peerId = 0;
|
2017-06-22 15:11:41 +00:00
|
|
|
MsgId msgId = 0;
|
|
|
|
HistoryItem *msg = nullptr;
|
|
|
|
ClickHandlerPtr lnk;
|
|
|
|
};
|
|
|
|
|
2018-01-10 13:13:33 +00:00
|
|
|
struct HistoryServicePinned
|
2020-12-01 14:17:05 +00:00
|
|
|
: public RuntimeComponent<HistoryServicePinned, HistoryItem>
|
|
|
|
, public HistoryServiceDependentData {
|
2017-06-22 15:11:41 +00:00
|
|
|
};
|
|
|
|
|
2018-01-10 13:13:33 +00:00
|
|
|
struct HistoryServiceGameScore
|
2020-12-01 14:17:05 +00:00
|
|
|
: public RuntimeComponent<HistoryServiceGameScore, HistoryItem>
|
|
|
|
, public HistoryServiceDependentData {
|
2017-06-22 15:11:41 +00:00
|
|
|
int score = 0;
|
|
|
|
};
|
|
|
|
|
2018-01-10 13:13:33 +00:00
|
|
|
struct HistoryServicePayment
|
2020-12-01 14:17:05 +00:00
|
|
|
: public RuntimeComponent<HistoryServicePayment, HistoryItem>
|
|
|
|
, public HistoryServiceDependentData {
|
2017-06-22 15:11:41 +00:00
|
|
|
QString amount;
|
2021-03-30 11:43:47 +00:00
|
|
|
ClickHandlerPtr invoiceLink;
|
2017-06-22 15:11:41 +00:00
|
|
|
};
|
|
|
|
|
2018-01-10 13:13:33 +00:00
|
|
|
struct HistoryServiceSelfDestruct
|
2020-12-01 14:17:05 +00:00
|
|
|
: public RuntimeComponent<HistoryServiceSelfDestruct, HistoryItem> {
|
2017-07-17 20:09:55 +00:00
|
|
|
enum class Type {
|
|
|
|
Photo,
|
|
|
|
Video,
|
|
|
|
};
|
|
|
|
Type type = Type::Photo;
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time timeToLive = 0;
|
|
|
|
crl::time destructAt = 0;
|
2017-07-17 20:09:55 +00:00
|
|
|
};
|
|
|
|
|
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;
|
2021-04-06 14:02:43 +00:00
|
|
|
ClickHandlerPtr link;
|
2020-12-01 14:17:05 +00:00
|
|
|
rpl::lifetime lifetime;
|
|
|
|
};
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
namespace HistoryView {
|
2017-06-22 15:11:41 +00:00
|
|
|
class ServiceMessagePainter;
|
2018-01-09 17:08:31 +00:00
|
|
|
} // namespace HistoryView
|
2017-06-22 15:11:41 +00:00
|
|
|
|
2018-01-18 20:02:50 +00:00
|
|
|
class HistoryService : public HistoryItem {
|
2017-06-22 15:11:41 +00:00
|
|
|
public:
|
|
|
|
struct PreparedText {
|
|
|
|
QString text;
|
|
|
|
QList<ClickHandlerPtr> links;
|
|
|
|
};
|
|
|
|
|
2018-01-18 20:02:50 +00:00
|
|
|
HistoryService(
|
|
|
|
not_null<History*> history,
|
2021-09-30 11:30:39 +00:00
|
|
|
MsgId id,
|
2019-08-09 19:19:23 +00:00
|
|
|
const MTPDmessage &data,
|
2021-07-28 11:55:02 +00:00
|
|
|
MessageFlags localFlags);
|
2018-01-18 20:02:50 +00:00
|
|
|
HistoryService(
|
2018-01-30 12:32:00 +00:00
|
|
|
not_null<History*> history,
|
2021-09-30 11:30:39 +00:00
|
|
|
MsgId id,
|
2019-08-09 19:19:23 +00:00
|
|
|
const MTPDmessageService &data,
|
2021-07-28 11:55:02 +00:00
|
|
|
MessageFlags localFlags);
|
2019-08-09 19:19:23 +00:00
|
|
|
HistoryService(
|
|
|
|
not_null<History*> history,
|
2018-02-03 19:52:35 +00:00
|
|
|
MsgId id,
|
2021-07-28 11:55:02 +00:00
|
|
|
MessageFlags flags,
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId date,
|
2018-01-30 12:32:00 +00:00
|
|
|
const PreparedText &message,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId from = 0,
|
2018-01-18 20:02:50 +00:00
|
|
|
PhotoData *photo = nullptr);
|
2017-06-22 15:11:41 +00:00
|
|
|
|
|
|
|
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;
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time getSelfDestructIn(crl::time now) override;
|
2017-06-22 15:11:41 +00:00
|
|
|
|
2017-09-04 11:40:02 +00:00
|
|
|
Storage::SharedMediaTypesMask sharedMediaTypes() const override;
|
2017-06-22 15:11:41 +00:00
|
|
|
|
2021-03-31 10:00:13 +00:00
|
|
|
void dependencyItemRemoved(HistoryItem *dependency) override;
|
|
|
|
|
2020-11-09 09:36:15 +00:00
|
|
|
bool needCheck() const override;
|
2021-11-07 08:06:00 +00:00
|
|
|
bool isService() const override {
|
2017-06-22 15:11:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-10-01 12:42:44 +00:00
|
|
|
ItemPreview toPreview(ToPreviewOptions options) const override;
|
2017-06-22 15:11:41 +00:00
|
|
|
QString inReplyText() const override;
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
std::unique_ptr<HistoryView::Element> createView(
|
2020-06-16 16:53:44 +00:00
|
|
|
not_null<HistoryView::ElementDelegate*> delegate,
|
|
|
|
HistoryView::Element *replacing = nullptr) override;
|
2018-01-11 19:33:26 +00:00
|
|
|
|
2020-09-16 19:48:56 +00:00
|
|
|
void setServiceText(const PreparedText &prepared);
|
|
|
|
|
2017-06-22 15:11:41 +00:00
|
|
|
~HistoryService();
|
|
|
|
|
|
|
|
protected:
|
2018-01-09 17:08:31 +00:00
|
|
|
friend class HistoryView::ServiceMessagePainter;
|
2017-06-22 15:11:41 +00:00
|
|
|
|
2017-07-17 20:09:55 +00:00
|
|
|
void markMediaAsReadHook() override;
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
QString fromLinkText() const;
|
|
|
|
ClickHandlerPtr fromLink() const;
|
2017-06-22 15:11:41 +00:00
|
|
|
|
|
|
|
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);
|
2017-06-22 15:11:41 +00:00
|
|
|
void clearDependency();
|
|
|
|
|
2017-07-17 20:09:55 +00:00
|
|
|
void createFromMtp(const MTPDmessage &message);
|
2017-06-22 15:11:41 +00:00
|
|
|
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);
|
2017-06-22 15:11:41 +00:00
|
|
|
|
|
|
|
PreparedText preparePinnedText();
|
|
|
|
PreparedText prepareGameScoreText();
|
|
|
|
PreparedText preparePaymentSentText();
|
2020-12-08 11:51:18 +00:00
|
|
|
PreparedText prepareInvitedToCallText(
|
2021-08-25 08:15:05 +00:00
|
|
|
const QVector<MTPlong> &users,
|
2021-10-24 21:33:53 +00:00
|
|
|
CallId linkCallId);
|
2021-04-09 14:33:38 +00:00
|
|
|
PreparedText prepareCallScheduledText(
|
|
|
|
TimeId scheduleDate);
|
2017-06-22 15:11:41 +00:00
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
friend class HistoryView::Service;
|
|
|
|
|
2017-06-22 15:11:41 +00:00
|
|
|
};
|
|
|
|
|
2021-04-06 14:02:43 +00:00
|
|
|
[[nodiscard]] not_null<HistoryService*> GenerateJoinedMessage(
|
2018-01-30 12:32:00 +00:00
|
|
|
not_null<History*> history,
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId inviteDate,
|
2021-10-14 11:42:51 +00:00
|
|
|
not_null<UserData*> inviter,
|
|
|
|
bool viaRequest);
|
2021-04-06 14:02:43 +00:00
|
|
|
[[nodiscard]] std::optional<bool> PeerHasThisCall(
|
|
|
|
not_null<PeerData*> peer,
|
2021-10-24 21:33:53 +00:00
|
|
|
CallId id);
|