Use ttl_period from service messages as well.
This commit is contained in:
parent
8188ab3033
commit
05488022c7
|
@ -809,6 +809,41 @@ bool HistoryItem::canUpdateDate() const {
|
|||
return isScheduled();
|
||||
}
|
||||
|
||||
void HistoryItem::applyTTL(const MTPDmessage &data) {
|
||||
if (const auto period = data.vttl_period()) {
|
||||
if (period->v > 0) {
|
||||
applyTTL(data.vdate().v + period->v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryItem::applyTTL(const MTPDmessageService &data) {
|
||||
if (const auto period = data.vttl_period()) {
|
||||
if (period->v > 0) {
|
||||
applyTTL(data.vdate().v + period->v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryItem::applyTTL(TimeId destroyAt) {
|
||||
const auto previousDestroyAt = std::exchange(_ttlDestroyAt, destroyAt);
|
||||
if (previousDestroyAt) {
|
||||
history()->owner().unregisterMessageTTL(previousDestroyAt, this);
|
||||
}
|
||||
if (!_ttlDestroyAt) {
|
||||
return;
|
||||
} else if (base::unixtime::now() >= _ttlDestroyAt) {
|
||||
const auto session = &history()->session();
|
||||
crl::on_main(session, [session, id = fullId()]{
|
||||
if (const auto item = session->data().message(id)) {
|
||||
item->destroy();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
history()->owner().registerMessageTTL(_ttlDestroyAt, this);
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryItem::sendFailed() {
|
||||
Expects(_clientFlags & MTPDmessage_ClientFlag::f_sending);
|
||||
Expects(!(_clientFlags & MTPDmessage_ClientFlag::f_failed));
|
||||
|
@ -957,7 +992,9 @@ void HistoryItem::drawInDialog(
|
|||
p.restoreTextPalette();
|
||||
}
|
||||
|
||||
HistoryItem::~HistoryItem() = default;
|
||||
HistoryItem::~HistoryItem() {
|
||||
applyTTL(0);
|
||||
}
|
||||
|
||||
QDateTime ItemDateTime(not_null<const HistoryItem*> item) {
|
||||
return base::unixtime::parse(item->date());
|
||||
|
|
|
@ -79,9 +79,6 @@ public:
|
|||
[[nodiscard]] virtual bool notificationReady() const {
|
||||
return true;
|
||||
}
|
||||
[[nodiscard]] virtual TimeId ttlDestroyAt() const {
|
||||
return 0;
|
||||
}
|
||||
[[nodiscard]] PeerData *specialNotificationPeer() const;
|
||||
|
||||
[[nodiscard]] UserData *viaBot() const;
|
||||
|
@ -399,6 +396,10 @@ public:
|
|||
void updateDate(TimeId newDate);
|
||||
[[nodiscard]] bool canUpdateDate() const;
|
||||
|
||||
[[nodiscard]] TimeId ttlDestroyAt() const {
|
||||
return _ttlDestroyAt;
|
||||
}
|
||||
|
||||
virtual ~HistoryItem();
|
||||
|
||||
MsgId id;
|
||||
|
@ -427,6 +428,10 @@ protected:
|
|||
|
||||
void setGroupId(MessageGroupId groupId);
|
||||
|
||||
void applyTTL(const MTPDmessage &data);
|
||||
void applyTTL(const MTPDmessageService &data);
|
||||
void applyTTL(TimeId destroyAt);
|
||||
|
||||
Ui::Text::String _text = { st::msgMinWidth };
|
||||
int _textWidth = -1;
|
||||
int _textHeight = 0;
|
||||
|
@ -440,7 +445,9 @@ protected:
|
|||
std::unique_ptr<Data::Media> _media;
|
||||
|
||||
private:
|
||||
|
||||
TimeId _date = 0;
|
||||
TimeId _ttlDestroyAt = 0;
|
||||
|
||||
HistoryView::Element *_mainView = nullptr;
|
||||
friend class HistoryView::Element;
|
||||
|
|
|
@ -525,11 +525,7 @@ HistoryMessage::HistoryMessage(
|
|||
MessageGroupId::FromRaw(history->peer->id, groupedId->v));
|
||||
}
|
||||
|
||||
if (const auto period = data.vttl_period()) {
|
||||
if (period->v > 0) {
|
||||
applyTTL(data.vdate().v + period->v);
|
||||
}
|
||||
}
|
||||
applyTTL(data);
|
||||
}
|
||||
|
||||
HistoryMessage::HistoryMessage(
|
||||
|
@ -566,6 +562,8 @@ HistoryMessage::HistoryMessage(
|
|||
}, [](const auto &) {
|
||||
Unexpected("Service message action type in HistoryMessage.");
|
||||
});
|
||||
|
||||
applyTTL(data);
|
||||
}
|
||||
|
||||
HistoryMessage::HistoryMessage(
|
||||
|
@ -1403,25 +1401,6 @@ void HistoryMessage::applyEdition(const MTPDmessageService &message) {
|
|||
}
|
||||
}
|
||||
|
||||
void HistoryMessage::applyTTL(TimeId destroyAt) {
|
||||
const auto previousDestroyAt = std::exchange(_ttlDestroyAt, destroyAt);
|
||||
if (previousDestroyAt) {
|
||||
history()->owner().unregisterMessageTTL(previousDestroyAt, this);
|
||||
}
|
||||
if (!_ttlDestroyAt) {
|
||||
return;
|
||||
} else if (base::unixtime::now() >= _ttlDestroyAt) {
|
||||
const auto session = &history()->session();
|
||||
crl::on_main(session, [session, id = fullId()]{
|
||||
if (const auto item = session->data().message(id)) {
|
||||
item->destroy();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
history()->owner().registerMessageTTL(_ttlDestroyAt, this);
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryMessage::updateSentContent(
|
||||
const TextWithEntities &textWithEntities,
|
||||
const MTPMessageMedia *media) {
|
||||
|
@ -1927,7 +1906,6 @@ std::unique_ptr<HistoryView::Element> HistoryMessage::createView(
|
|||
}
|
||||
|
||||
HistoryMessage::~HistoryMessage() {
|
||||
applyTTL(0);
|
||||
_media.reset();
|
||||
clearSavedMedia();
|
||||
if (auto reply = Get<HistoryMessageReply>()) {
|
||||
|
|
|
@ -194,10 +194,6 @@ public:
|
|||
const MTPDupdateShortSentMessage &data,
|
||||
bool wasAlready) override;
|
||||
|
||||
[[nodiscard]] TimeId ttlDestroyAt() const override {
|
||||
return _ttlDestroyAt;
|
||||
}
|
||||
|
||||
// dynamic_cast optimization.
|
||||
[[nodiscard]] HistoryMessage *toHistoryMessage() override {
|
||||
return this;
|
||||
|
@ -250,8 +246,6 @@ private:
|
|||
const TextWithEntities &textWithEntities) const;
|
||||
void reapplyText();
|
||||
|
||||
void applyTTL(TimeId destroyAt);
|
||||
|
||||
[[nodiscard]] bool checkRepliesPts(const MTPMessageReplies &data) const;
|
||||
|
||||
QString _timeText;
|
||||
|
@ -259,8 +253,6 @@ private:
|
|||
|
||||
mutable int32 _fromNameVersion = 0;
|
||||
|
||||
TimeId _ttlDestroyAt = 0;
|
||||
|
||||
friend class HistoryView::Element;
|
||||
friend class HistoryView::Message;
|
||||
|
||||
|
|
|
@ -749,6 +749,7 @@ HistoryService::HistoryService(
|
|||
data.vdate().v,
|
||||
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) {
|
||||
createFromMtp(data);
|
||||
applyTTL(data);
|
||||
}
|
||||
|
||||
HistoryService::HistoryService(
|
||||
|
@ -763,6 +764,7 @@ HistoryService::HistoryService(
|
|||
data.vdate().v,
|
||||
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) {
|
||||
createFromMtp(data);
|
||||
applyTTL(data);
|
||||
}
|
||||
|
||||
HistoryService::HistoryService(
|
||||
|
|
|
@ -3716,8 +3716,8 @@ bool HistoryWidget::isJoinChannel() const {
|
|||
|
||||
bool HistoryWidget::isMuteUnmute() const {
|
||||
return _peer
|
||||
&& ((_peer->isBroadcast()
|
||||
&& !_peer->asChannel()->canPublish())
|
||||
&& ((_peer->isBroadcast() && !_peer->asChannel()->canPublish())
|
||||
|| (_peer->isGigagroup() && !_peer->asChannel()->canWrite())
|
||||
|| _peer->isRepliesChat());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue