mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Don't destroy by timer single-view media.
This commit is contained in:
parent
36f1a18b3b
commit
c3340fd016
4 changed files with 41 additions and 18 deletions
|
@ -2619,7 +2619,7 @@ void Session::checkSelfDestructItems() {
|
||||||
auto nextDestructIn = crl::time(0);
|
auto nextDestructIn = crl::time(0);
|
||||||
for (auto i = _selfDestructItems.begin(); i != _selfDestructItems.cend();) {
|
for (auto i = _selfDestructItems.begin(); i != _selfDestructItems.cend();) {
|
||||||
if (const auto item = message(*i)) {
|
if (const auto item = message(*i)) {
|
||||||
if (auto destructIn = item->getSelfDestructIn(now)) {
|
if (const auto destructIn = item->getSelfDestructIn(now)) {
|
||||||
if (nextDestructIn > 0) {
|
if (nextDestructIn > 0) {
|
||||||
accumulate_min(nextDestructIn, destructIn);
|
accumulate_min(nextDestructIn, destructIn);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1212,9 +1212,15 @@ void HistoryItem::markMediaAndMentionRead() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const auto selfdestruct = Get<HistoryServiceSelfDestruct>()) {
|
if (const auto selfdestruct = Get<HistoryServiceSelfDestruct>()) {
|
||||||
if (!selfdestruct->destructAt) {
|
if (selfdestruct->destructAt == crl::time()) {
|
||||||
selfdestruct->destructAt = crl::now() + selfdestruct->timeToLive;
|
const auto ttl = selfdestruct->timeToLive;
|
||||||
_history->owner().selfDestructIn(this, selfdestruct->timeToLive);
|
if (const auto maybeTime = std::get_if<crl::time>(&ttl)) {
|
||||||
|
const auto time = *maybeTime;
|
||||||
|
selfdestruct->destructAt = crl::now() + time;
|
||||||
|
_history->owner().selfDestructIn(this, time);
|
||||||
|
} else {
|
||||||
|
selfdestruct->destructAt = TimeToLiveSingleView();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3430,7 +3436,7 @@ void HistoryItem::createServiceFromMtp(const MTPDmessage &message) {
|
||||||
const auto ttl = data.vttl_seconds();
|
const auto ttl = data.vttl_seconds();
|
||||||
Assert(ttl != nullptr);
|
Assert(ttl != nullptr);
|
||||||
|
|
||||||
setSelfDestruct(HistoryServiceSelfDestruct::Type::Photo, ttl->v);
|
setSelfDestruct(HistoryServiceSelfDestruct::Type::Photo, *ttl);
|
||||||
if (out()) {
|
if (out()) {
|
||||||
setServiceText({
|
setServiceText({
|
||||||
tr::lng_ttl_photo_sent(tr::now, Ui::Text::WithEntities)
|
tr::lng_ttl_photo_sent(tr::now, Ui::Text::WithEntities)
|
||||||
|
@ -3455,7 +3461,7 @@ void HistoryItem::createServiceFromMtp(const MTPDmessage &message) {
|
||||||
const auto ttl = data.vttl_seconds();
|
const auto ttl = data.vttl_seconds();
|
||||||
Assert(ttl != nullptr);
|
Assert(ttl != nullptr);
|
||||||
|
|
||||||
setSelfDestruct(HistoryServiceSelfDestruct::Type::Video, ttl->v);
|
setSelfDestruct(HistoryServiceSelfDestruct::Type::Video, *ttl);
|
||||||
if (out()) {
|
if (out()) {
|
||||||
setServiceText({
|
setServiceText({
|
||||||
tr::lng_ttl_video_sent(tr::now, Ui::Text::WithEntities)
|
tr::lng_ttl_video_sent(tr::now, Ui::Text::WithEntities)
|
||||||
|
@ -4558,10 +4564,16 @@ void HistoryItem::applyAction(const MTPMessageAction &action) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryItem::setSelfDestruct(HistoryServiceSelfDestruct::Type type, int ttlSeconds) {
|
void HistoryItem::setSelfDestruct(
|
||||||
|
HistoryServiceSelfDestruct::Type type,
|
||||||
|
MTPint mtpTTLvalue) {
|
||||||
UpdateComponents(HistoryServiceSelfDestruct::Bit());
|
UpdateComponents(HistoryServiceSelfDestruct::Bit());
|
||||||
auto selfdestruct = Get<HistoryServiceSelfDestruct>();
|
const auto selfdestruct = Get<HistoryServiceSelfDestruct>();
|
||||||
selfdestruct->timeToLive = ttlSeconds * 1000LL;
|
if (mtpTTLvalue.v == TimeId(0x7FFFFFFF)) {
|
||||||
|
selfdestruct->timeToLive = TimeToLiveSingleView();
|
||||||
|
} else {
|
||||||
|
selfdestruct->timeToLive = mtpTTLvalue.v * crl::time(1000);
|
||||||
|
}
|
||||||
selfdestruct->type = type;
|
selfdestruct->type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4949,10 +4961,12 @@ ClickHandlerPtr HistoryItem::fromLink() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
crl::time HistoryItem::getSelfDestructIn(crl::time now) {
|
crl::time HistoryItem::getSelfDestructIn(crl::time now) {
|
||||||
if (auto selfdestruct = Get<HistoryServiceSelfDestruct>()) {
|
if (const auto selfdestruct = Get<HistoryServiceSelfDestruct>()) {
|
||||||
if (selfdestruct->destructAt > 0) {
|
const auto at = std::get_if<crl::time>(&selfdestruct->destructAt);
|
||||||
if (selfdestruct->destructAt <= now) {
|
if (at && (*at) > 0) {
|
||||||
auto text = [selfdestruct] {
|
const auto destruct = *at;
|
||||||
|
if (destruct <= now) {
|
||||||
|
auto text = [&] {
|
||||||
switch (selfdestruct->type) {
|
switch (selfdestruct->type) {
|
||||||
case HistoryServiceSelfDestruct::Type::Photo:
|
case HistoryServiceSelfDestruct::Type::Photo:
|
||||||
return tr::lng_ttl_photo_expired(tr::now);
|
return tr::lng_ttl_photo_expired(tr::now);
|
||||||
|
@ -4961,10 +4975,10 @@ crl::time HistoryItem::getSelfDestructIn(crl::time now) {
|
||||||
}
|
}
|
||||||
Unexpected("Type in HistoryServiceSelfDestruct::Type");
|
Unexpected("Type in HistoryServiceSelfDestruct::Type");
|
||||||
};
|
};
|
||||||
setServiceText({ TextWithEntities{.text = text() } });
|
setServiceText({ TextWithEntities{ .text = text() } });
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return selfdestruct->destructAt - now;
|
return destruct - now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -575,7 +575,7 @@ private:
|
||||||
void translationToggle(
|
void translationToggle(
|
||||||
not_null<HistoryMessageTranslation*> translation,
|
not_null<HistoryMessageTranslation*> translation,
|
||||||
bool used);
|
bool used);
|
||||||
void setSelfDestruct(HistorySelfDestructType type, int ttlSeconds);
|
void setSelfDestruct(HistorySelfDestructType type, MTPint mtpTTLvalue);
|
||||||
|
|
||||||
TextWithEntities fromLinkText() const;
|
TextWithEntities fromLinkText() const;
|
||||||
ClickHandlerPtr fromLink() const;
|
ClickHandlerPtr fromLink() const;
|
||||||
|
|
|
@ -599,13 +599,22 @@ enum class HistorySelfDestructType {
|
||||||
Video,
|
Video,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct TimeToLiveSingleView {
|
||||||
|
friend inline auto operator<=>(
|
||||||
|
TimeToLiveSingleView,
|
||||||
|
TimeToLiveSingleView) = default;
|
||||||
|
friend inline bool operator==(
|
||||||
|
TimeToLiveSingleView,
|
||||||
|
TimeToLiveSingleView) = default;
|
||||||
|
};
|
||||||
|
|
||||||
struct HistoryServiceSelfDestruct
|
struct HistoryServiceSelfDestruct
|
||||||
: public RuntimeComponent<HistoryServiceSelfDestruct, HistoryItem> {
|
: public RuntimeComponent<HistoryServiceSelfDestruct, HistoryItem> {
|
||||||
using Type = HistorySelfDestructType;
|
using Type = HistorySelfDestructType;
|
||||||
|
|
||||||
Type type = Type::Photo;
|
Type type = Type::Photo;
|
||||||
crl::time timeToLive = 0;
|
std::variant<crl::time, TimeToLiveSingleView> timeToLive = crl::time();
|
||||||
crl::time destructAt = 0;
|
std::variant<crl::time, TimeToLiveSingleView> destructAt = crl::time();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HistoryServiceOngoingCall
|
struct HistoryServiceOngoingCall
|
||||||
|
|
Loading…
Add table
Reference in a new issue