mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Support pin ttl for paid messages in streams.
This commit is contained in:
@@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "api/api_text_entities.h"
|
||||
#include "base/random.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "calls/group/ui/calls_group_stars_coloring.h"
|
||||
#include "calls/group/calls_group_call.h"
|
||||
#include "calls/group/calls_group_message_encryption.h"
|
||||
#include "data/data_group_call.h"
|
||||
@@ -123,7 +124,6 @@ void Messages::received(const MTPDupdateGroupCallMessage &data) {
|
||||
fields.vmessage(),
|
||||
fields.vdate().v,
|
||||
fields.vpaid_message_stars().value_or_empty());
|
||||
pushChanges();
|
||||
}
|
||||
|
||||
void Messages::received(const MTPDupdateGroupCallEncryptedMessage &data) {
|
||||
@@ -159,7 +159,6 @@ void Messages::received(const MTPDupdateGroupCallEncryptedMessage &data) {
|
||||
base::unixtime::now(), // date
|
||||
0, // stars
|
||||
true); // checkCustomEmoji
|
||||
pushChanges();
|
||||
}
|
||||
|
||||
void Messages::deleted(const MTPDupdateDeleteGroupCallMessages &data) {
|
||||
@@ -245,26 +244,29 @@ void Messages::received(
|
||||
allowedEntityTypes),
|
||||
.stars = stars,
|
||||
});
|
||||
ranges::sort(_messages, ranges::less(), &Message::id);
|
||||
checkDestroying(true);
|
||||
}
|
||||
|
||||
void Messages::checkDestroying(bool afterChanges) {
|
||||
auto next = TimeId();
|
||||
const auto now = base::unixtime::now();
|
||||
const auto destroyTime = now - _ttl;
|
||||
const auto initial = _messages.size();
|
||||
for (auto i = begin(_messages); i != end(_messages);) {
|
||||
const auto date = i->date;
|
||||
const auto ttl = i->stars
|
||||
? (Ui::StarsColoringForCount(i->stars).minutesPin * 60)
|
||||
: _ttl;
|
||||
if (!date) {
|
||||
if (i->id < 0) {
|
||||
++i;
|
||||
} else {
|
||||
i = _messages.erase(i);
|
||||
}
|
||||
} else if (date <= destroyTime) {
|
||||
} else if (date + ttl <= now) {
|
||||
i = _messages.erase(i);
|
||||
} else if (!next) {
|
||||
next = date + _ttl - now;
|
||||
} else if (!next || next > date + ttl - now) {
|
||||
next = date + ttl - now;
|
||||
++i;
|
||||
} else {
|
||||
++i;
|
||||
@@ -301,7 +303,14 @@ void Messages::sendPending() {
|
||||
}
|
||||
|
||||
void Messages::pushChanges() {
|
||||
_changes.fire_copy(_messages);
|
||||
if (_changesScheduled) {
|
||||
return;
|
||||
}
|
||||
_changesScheduled = true;
|
||||
Ui::PostponeCall(this, [=] {
|
||||
_changesScheduled = false;
|
||||
_changes.fire_copy(_messages);
|
||||
});
|
||||
}
|
||||
|
||||
void Messages::failed(uint64 randomId, const MTP::Response &response) {
|
||||
|
||||
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#pragma once
|
||||
|
||||
#include "base/timer.h"
|
||||
#include "base/weak_ptr.h"
|
||||
|
||||
namespace Calls {
|
||||
class GroupCall;
|
||||
@@ -38,7 +39,7 @@ struct MessageIdUpdate {
|
||||
MsgId realId = 0;
|
||||
};
|
||||
|
||||
class Messages final {
|
||||
class Messages final : public base::has_weak_ptr {
|
||||
public:
|
||||
Messages(not_null<GroupCall*> call, not_null<MTP::Sender*> api);
|
||||
|
||||
@@ -91,6 +92,7 @@ private:
|
||||
rpl::event_stream<MessageIdUpdate> _idUpdates;
|
||||
|
||||
TimeId _ttl = 0;
|
||||
bool _changesScheduled = false;
|
||||
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
|
||||
@@ -336,7 +336,7 @@ void MessagesUi::setContent(
|
||||
int stars) {
|
||||
if (stars) {
|
||||
entry.price = Ui::Text::String(
|
||||
st::messageTextStyle,
|
||||
st::whoReadDateStyle,
|
||||
Ui::Text::IconEmoji(
|
||||
&st::starIconEmojiSmall
|
||||
).append(Lang::FormatCountDecimal(stars)),
|
||||
|
||||
@@ -584,6 +584,7 @@ void PaidReactionsBox(
|
||||
rpl::single(Text::Bold(args.name)),
|
||||
Text::RichLangValue)),
|
||||
dark ? st::darkEditStarsText : st::boostText);
|
||||
label->setTryMakeSimilarLines(true);
|
||||
labelWrap->widthValue() | rpl::start_with_next([=](int width) {
|
||||
label->resizeToWidth(width);
|
||||
}, label->lifetime());
|
||||
|
||||
Reference in New Issue
Block a user