2017-06-22 15:11:41 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
struct HistoryServiceDependentData {
|
|
|
|
MsgId msgId = 0;
|
|
|
|
HistoryItem *msg = nullptr;
|
|
|
|
ClickHandlerPtr lnk;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct HistoryServicePinned : public RuntimeComponent<HistoryServicePinned>, public HistoryServiceDependentData {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct HistoryServiceGameScore : public RuntimeComponent<HistoryServiceGameScore>, public HistoryServiceDependentData {
|
|
|
|
int score = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct HistoryServicePayment : public RuntimeComponent<HistoryServicePayment>, public HistoryServiceDependentData {
|
|
|
|
QString amount;
|
|
|
|
};
|
|
|
|
|
2017-07-17 20:09:55 +00:00
|
|
|
struct HistoryServiceSelfDestruct : public RuntimeComponent<HistoryServiceSelfDestruct> {
|
|
|
|
enum class Type {
|
|
|
|
Photo,
|
|
|
|
Video,
|
|
|
|
};
|
|
|
|
Type type = Type::Photo;
|
|
|
|
TimeMs timeToLive = 0;
|
|
|
|
TimeMs destructAt = 0;
|
|
|
|
};
|
|
|
|
|
2017-06-22 15:11:41 +00:00
|
|
|
namespace HistoryLayout {
|
|
|
|
class ServiceMessagePainter;
|
|
|
|
} // namespace HistoryLayout
|
|
|
|
|
|
|
|
class HistoryService : public HistoryItem, private HistoryItemInstantiated<HistoryService> {
|
|
|
|
public:
|
|
|
|
struct PreparedText {
|
|
|
|
QString text;
|
|
|
|
QList<ClickHandlerPtr> links;
|
|
|
|
};
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
static not_null<HistoryService*> create(not_null<History*> history, const MTPDmessage &message) {
|
2017-07-17 20:09:55 +00:00
|
|
|
return _create(history, message);
|
|
|
|
}
|
2017-08-17 08:31:24 +00:00
|
|
|
static not_null<HistoryService*> create(not_null<History*> history, const MTPDmessageService &message) {
|
2017-06-22 15:11:41 +00:00
|
|
|
return _create(history, message);
|
|
|
|
}
|
2017-08-17 08:31:24 +00:00
|
|
|
static not_null<HistoryService*> create(not_null<History*> history, MsgId msgId, QDateTime date, const PreparedText &message, MTPDmessage::Flags flags = 0, UserId from = 0, PhotoData *photo = nullptr) {
|
2017-06-22 15:11:41 +00:00
|
|
|
return _create(history, msgId, date, message, flags, from, photo);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect countGeometry() const;
|
|
|
|
|
|
|
|
void draw(Painter &p, QRect clip, TextSelection selection, TimeMs ms) const override;
|
|
|
|
bool hasPoint(QPoint point) const override;
|
|
|
|
HistoryTextState getState(QPoint point, HistoryStateRequest request) const override;
|
|
|
|
|
2017-10-13 19:07:04 +00:00
|
|
|
[[nodiscard]] TextSelection adjustSelection(
|
|
|
|
TextSelection selection,
|
|
|
|
TextSelectType type) const override {
|
2017-06-22 15:11:41 +00:00
|
|
|
return _text.adjustSelection(selection, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
|
|
|
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
|
|
|
|
|
|
|
|
void applyEdition(const MTPDmessageService &message) override;
|
2017-07-17 20:09:55 +00:00
|
|
|
TimeMs getSelfDestructIn(TimeMs now) override;
|
2017-06-22 15:11:41 +00:00
|
|
|
|
|
|
|
int32 addToOverview(AddToOverviewMethod method) override;
|
|
|
|
void eraseFromOverview() override;
|
2017-09-04 11:40:02 +00:00
|
|
|
Storage::SharedMediaTypesMask sharedMediaTypes() const override;
|
2017-06-22 15:11:41 +00:00
|
|
|
|
|
|
|
bool needCheck() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool serviceMsg() const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
TextWithEntities selectedText(TextSelection selection) const override;
|
2017-09-05 17:21:56 +00:00
|
|
|
QString inDialogsText(DrawInDialog way) const override;
|
2017-06-22 15:11:41 +00:00
|
|
|
QString inReplyText() const override;
|
|
|
|
|
|
|
|
~HistoryService();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class HistoryLayout::ServiceMessagePainter;
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
HistoryService(not_null<History*> history, const MTPDmessage &message);
|
|
|
|
HistoryService(not_null<History*> history, const MTPDmessageService &message);
|
|
|
|
HistoryService(not_null<History*> history, MsgId msgId, QDateTime date, const PreparedText &message, MTPDmessage::Flags flags = 0, UserId from = 0, PhotoData *photo = 0);
|
2017-06-22 15:11:41 +00:00
|
|
|
friend class HistoryItemInstantiated<HistoryService>;
|
|
|
|
|
|
|
|
void initDimensions() override;
|
|
|
|
int resizeContentGetHeight() override;
|
|
|
|
|
2017-07-17 20:09:55 +00:00
|
|
|
void markMediaAsReadHook() override;
|
|
|
|
|
2017-06-22 15:11:41 +00:00
|
|
|
void setServiceText(const PreparedText &prepared);
|
|
|
|
|
|
|
|
QString fromLinkText() const {
|
|
|
|
return textcmdLink(1, _from->name);
|
|
|
|
};
|
|
|
|
ClickHandlerPtr fromLink() const {
|
2017-07-05 18:11:31 +00:00
|
|
|
return _from->createOpenLink();
|
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();
|
|
|
|
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);
|
2017-07-17 20:09:55 +00:00
|
|
|
void setSelfDestruct(HistoryServiceSelfDestruct::Type type, int ttlSeconds);
|
2017-06-22 15:11:41 +00:00
|
|
|
|
|
|
|
PreparedText preparePinnedText();
|
|
|
|
PreparedText prepareGameScoreText();
|
|
|
|
PreparedText preparePaymentSentText();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class HistoryJoined : public HistoryService, private HistoryItemInstantiated<HistoryJoined> {
|
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
static not_null<HistoryJoined*> create(not_null<History*> history, const QDateTime &inviteDate, not_null<UserData*> inviter, MTPDmessage::Flags flags) {
|
2017-06-22 15:11:41 +00:00
|
|
|
return _create(history, inviteDate, inviter, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2017-08-17 08:31:24 +00:00
|
|
|
HistoryJoined(not_null<History*> history, const QDateTime &inviteDate, not_null<UserData*> inviter, MTPDmessage::Flags flags);
|
2017-06-22 15:11:41 +00:00
|
|
|
using HistoryItemInstantiated<HistoryJoined>::_create;
|
|
|
|
friend class HistoryItemInstantiated<HistoryJoined>;
|
|
|
|
|
|
|
|
private:
|
2017-08-17 08:31:24 +00:00
|
|
|
static PreparedText GenerateText(not_null<History*> history, not_null<UserData*> inviter);
|
2017-06-22 15:11:41 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
extern TextParseOptions _historySrvOptions;
|