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