mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Request and store top donors in video streams.
This commit is contained in:
@@ -25,6 +25,29 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/ui_utility.h"
|
||||
|
||||
namespace Calls::Group {
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] StarsTop ParseStarsTop(
|
||||
not_null<Data::Session*> owner,
|
||||
const MTPphone_GroupCallStars &stars) {
|
||||
const auto &data = stars.data();
|
||||
const auto &list = data.vtop_donors().v;
|
||||
auto result = StarsTop{ .total = int(data.vtotal_stars().v) };
|
||||
result.topDonors.reserve(list.size());
|
||||
for (const auto &entry : list) {
|
||||
const auto &fields = entry.data();
|
||||
result.topDonors.push_back({
|
||||
.peer = (fields.vpeer_id()
|
||||
? owner->peer(peerFromMTP(*fields.vpeer_id())).get()
|
||||
: nullptr),
|
||||
.stars = int(fields.vstars().v),
|
||||
.my = fields.is_my(),
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Messages::Messages(not_null<GroupCall*> call, not_null<MTP::Sender*> api)
|
||||
: _call(call)
|
||||
@@ -41,6 +64,23 @@ Messages::Messages(not_null<GroupCall*> call, not_null<MTP::Sender*> api)
|
||||
Unexpected("Not ready call.");
|
||||
}
|
||||
}, _lifetime);
|
||||
|
||||
_call->stateValue() | rpl::filter([=](GroupCall::State state) {
|
||||
return (state == GroupCall::State::Joined);
|
||||
}) | rpl::start_with_next([=] {
|
||||
_api->request(base::take(_starsTopRequestId)).cancel();
|
||||
_starsTopRequestId = _api->request(MTPphone_GetGroupCallStars(
|
||||
_call->inputCall()
|
||||
)).done([=](const MTPphone_GroupCallStars &result) {
|
||||
const auto &data = result.data();
|
||||
|
||||
const auto owner = &_call->peer()->owner();
|
||||
owner->processUsers(data.vusers());
|
||||
owner->processChats(data.vchats());
|
||||
|
||||
_starsTop = ParseStarsTop(owner, result);
|
||||
}).send();
|
||||
}, _lifetime);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,25 @@ struct MessageIdUpdate {
|
||||
MsgId realId = 0;
|
||||
};
|
||||
|
||||
struct StarsTopDonor {
|
||||
PeerData *peer = nullptr;
|
||||
int stars = 0;
|
||||
bool my = false;
|
||||
|
||||
friend inline bool operator==(
|
||||
const StarsTopDonor &,
|
||||
const StarsTopDonor &) = default;
|
||||
};
|
||||
|
||||
struct StarsTop {
|
||||
std::vector<StarsTopDonor> topDonors;
|
||||
int total = 0;
|
||||
|
||||
friend inline bool operator==(
|
||||
const StarsTop &,
|
||||
const StarsTop &) = default;
|
||||
};
|
||||
|
||||
class Messages final : public base::has_weak_ptr {
|
||||
public:
|
||||
Messages(not_null<GroupCall*> call, not_null<MTP::Sender*> api);
|
||||
@@ -53,6 +72,10 @@ public:
|
||||
[[nodiscard]] rpl::producer<std::vector<Message>> listValue() const;
|
||||
[[nodiscard]] rpl::producer<MessageIdUpdate> idUpdates() const;
|
||||
|
||||
[[nodiscard]] rpl::producer<StarsTop> starsTopValue() const {
|
||||
return _starsTop.value();
|
||||
}
|
||||
|
||||
private:
|
||||
struct Pending {
|
||||
TextWithTags text;
|
||||
@@ -91,6 +114,9 @@ private:
|
||||
rpl::event_stream<std::vector<Message>> _changes;
|
||||
rpl::event_stream<MessageIdUpdate> _idUpdates;
|
||||
|
||||
mtpRequestId _starsTopRequestId = 0;
|
||||
rpl::variable<StarsTop> _starsTop;
|
||||
|
||||
TimeId _ttl = 0;
|
||||
bool _changesScheduled = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user