Show star senders in live stories.
This commit is contained in:
@@ -1721,6 +1721,8 @@ groupCallUserpicPadding: margins(2px, 2px, 4px, 2px);
|
||||
groupCallPinnedPadding: margins(10px, 4px, 10px, 2px);
|
||||
groupCallPinnedMaxWidth: 96px;
|
||||
groupCallPinnedUserpic: 22px;
|
||||
groupCallEffectPadding: margins(3px, 1px, 3px, 1px);
|
||||
groupCallEffectUserpicPadding: margins(1px, 1px, 3px, 1px);
|
||||
|
||||
groupCallTopReactorBadge: RoundCheckbox(defaultRoundCheckbox) {
|
||||
width: 1px;
|
||||
|
||||
@@ -69,12 +69,6 @@ constexpr auto kStarsStatsShortPollDelay = 30 * crl::time(1000);
|
||||
return PinFinishDate(message.peer, message.date, message.stars);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::optional<PeerId> MaybeShownPeer(
|
||||
uint32 privacySet,
|
||||
PeerId shownPeer) {
|
||||
return privacySet ? shownPeer : std::optional<PeerId>();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Messages::Messages(not_null<GroupCall*> call, not_null<MTP::Sender*> api)
|
||||
@@ -104,9 +98,7 @@ Messages::~Messages() {
|
||||
finishPaidSending({
|
||||
.count = int(_paid.sending),
|
||||
.valid = true,
|
||||
.shownPeer = MaybeShownPeer(
|
||||
_paid.sendingPrivacySet,
|
||||
_paid.sendingShownPeer),
|
||||
.shownPeer = _paid.sendingShownPeer,
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
@@ -517,26 +509,23 @@ PeerId Messages::reactionsLocalShownPeer() const {
|
||||
return entry.peer ? entry.peer->id : PeerId();
|
||||
}
|
||||
}
|
||||
return _session->userPeerId();
|
||||
return _call->messagesFrom()->id;
|
||||
//const auto api = &_session->api();
|
||||
//return api->globalPrivacy().paidReactionShownPeerCurrent();
|
||||
};
|
||||
return (_paid.scheduledFlag && _paid.scheduledPrivacySet)
|
||||
return _paid.scheduledFlag
|
||||
? _paid.scheduledShownPeer
|
||||
: (_paid.sendingFlag && _paid.sendingPrivacySet)
|
||||
: _paid.sendingFlag
|
||||
? _paid.sendingShownPeer
|
||||
: minePaidShownPeer();
|
||||
}
|
||||
|
||||
void Messages::reactionsPaidAdd(int count, std::optional<PeerId> shownPeer) {
|
||||
void Messages::reactionsPaidAdd(int count) {
|
||||
Expects(count >= 0);
|
||||
|
||||
_paid.scheduled += count;
|
||||
_paid.scheduledFlag = 1;
|
||||
if (shownPeer.has_value()) {
|
||||
_paid.scheduledShownPeer = *shownPeer;
|
||||
_paid.scheduledPrivacySet = true;
|
||||
}
|
||||
_paid.scheduledShownPeer = _call->messagesFrom()->id;
|
||||
if (count > 0) {
|
||||
_session->credits().lock(CreditsAmount(count));
|
||||
}
|
||||
@@ -555,7 +544,6 @@ void Messages::reactionsPaidScheduledCancel() {
|
||||
_paid.scheduled = 0;
|
||||
_paid.scheduledFlag = 0;
|
||||
_paid.scheduledShownPeer = 0;
|
||||
_paid.scheduledPrivacySet = 0;
|
||||
_paidChanges.fire({});
|
||||
}
|
||||
|
||||
@@ -570,17 +558,13 @@ Data::PaidReactionSend Messages::startPaidReactionSending() {
|
||||
_paid.sending = _paid.scheduled;
|
||||
_paid.sendingFlag = _paid.scheduledFlag;
|
||||
_paid.sendingShownPeer = _paid.scheduledShownPeer;
|
||||
_paid.sendingPrivacySet = _paid.scheduledPrivacySet;
|
||||
_paid.scheduled = 0;
|
||||
_paid.scheduledFlag = 0;
|
||||
_paid.scheduledShownPeer = 0;
|
||||
_paid.scheduledPrivacySet = 0;
|
||||
return {
|
||||
.count = int(_paid.sending),
|
||||
.valid = true,
|
||||
.shownPeer = MaybeShownPeer(
|
||||
_paid.sendingPrivacySet,
|
||||
_paid.sendingShownPeer),
|
||||
.shownPeer = _paid.sendingShownPeer,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -589,25 +573,24 @@ void Messages::finishPaidSending(
|
||||
bool success) {
|
||||
Expects(send.count == _paid.sending);
|
||||
Expects(send.valid == (_paid.sendingFlag == 1));
|
||||
Expects(send.shownPeer == MaybeShownPeer(
|
||||
_paid.sendingPrivacySet,
|
||||
_paid.sendingShownPeer));
|
||||
Expects(send.shownPeer == _paid.sendingShownPeer);
|
||||
|
||||
_paid.sending = 0;
|
||||
_paid.sendingFlag = 0;
|
||||
_paid.sendingShownPeer = 0;
|
||||
_paid.sendingPrivacySet = 0;
|
||||
if (const auto amount = send.count) {
|
||||
if (success) {
|
||||
const auto from = _session->data().peer(*send.shownPeer);
|
||||
_session->credits().withdrawLocked(CreditsAmount(amount));
|
||||
|
||||
auto &donors = _paid.top.topDonors;
|
||||
const auto i = ranges::find(donors, true, &StarsTopDonor::my);
|
||||
const auto i = ranges::find(donors, true, &StarsDonor::my);
|
||||
if (i != end(donors)) {
|
||||
i->peer = from;
|
||||
i->stars += amount;
|
||||
} else {
|
||||
donors.push_back({
|
||||
.peer = _session->user(),
|
||||
.peer = from,
|
||||
.stars = amount,
|
||||
.my = true,
|
||||
});
|
||||
@@ -632,7 +615,7 @@ void Messages::reactionsPaidSend() {
|
||||
const auto randomId = base::RandomValue<uint64>();
|
||||
_sendingIdByRandomId.emplace(randomId, localId);
|
||||
|
||||
const auto from = _call->messagesFrom();
|
||||
const auto from = _session->data().peer(*send.shownPeer);
|
||||
const auto stars = int(send.count);
|
||||
const auto skip = skipMessage({}, stars);
|
||||
if (skip) {
|
||||
@@ -676,7 +659,7 @@ void Messages::undoScheduledPaidOnDestroy() {
|
||||
|
||||
Messages::PaidLocalState Messages::starsLocalState() const {
|
||||
const auto &donors = _paid.top.topDonors;
|
||||
const auto i = ranges::find(donors, true, &StarsTopDonor::my);
|
||||
const auto i = ranges::find(donors, true, &StarsDonor::my);
|
||||
const auto local = int(_paid.scheduled);
|
||||
const auto my = (i != end(donors) ? i->stars : 0) + local;
|
||||
const auto total = _paid.top.total + local;
|
||||
@@ -728,7 +711,7 @@ void Messages::addStars(not_null<PeerData*> from, int stars, bool mine) {
|
||||
const auto i = ranges::find(
|
||||
_paid.top.topDonors,
|
||||
from.get(),
|
||||
&StarsTopDonor::peer);
|
||||
&StarsDonor::peer);
|
||||
if (i != end(_paid.top.topDonors)) {
|
||||
i->stars += stars;
|
||||
} else {
|
||||
@@ -741,8 +724,8 @@ void Messages::addStars(not_null<PeerData*> from, int stars, bool mine) {
|
||||
ranges::stable_sort(
|
||||
_paid.top.topDonors,
|
||||
ranges::greater(),
|
||||
&StarsTopDonor::stars);
|
||||
_paidChanges.fire({});
|
||||
&StarsDonor::stars);
|
||||
_paidChanges.fire({ .peer = from, .stars = stars });
|
||||
}
|
||||
|
||||
} // namespace Calls::Group
|
||||
|
||||
@@ -54,18 +54,18 @@ struct MessageDeleteRequest {
|
||||
bool reportSpam = false;
|
||||
};
|
||||
|
||||
struct StarsTopDonor {
|
||||
struct StarsDonor {
|
||||
PeerData *peer = nullptr;
|
||||
int stars = 0;
|
||||
bool my = false;
|
||||
|
||||
friend inline bool operator==(
|
||||
const StarsTopDonor &,
|
||||
const StarsTopDonor &) = default;
|
||||
const StarsDonor &,
|
||||
const StarsDonor &) = default;
|
||||
};
|
||||
|
||||
struct StarsTop {
|
||||
std::vector<StarsTopDonor> topDonors;
|
||||
std::vector<StarsDonor> topDonors;
|
||||
int total = 0;
|
||||
|
||||
friend inline bool operator==(
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
|
||||
[[nodiscard]] int reactionsPaidScheduled() const;
|
||||
[[nodiscard]] PeerId reactionsLocalShownPeer() const;
|
||||
void reactionsPaidAdd(int count, std::optional<PeerId> shownPeer = {});
|
||||
void reactionsPaidAdd(int count);
|
||||
void reactionsPaidScheduledCancel();
|
||||
void reactionsPaidSend();
|
||||
void undoScheduledPaidOnDestroy();
|
||||
@@ -101,7 +101,7 @@ public:
|
||||
int my = 0;
|
||||
};
|
||||
[[nodiscard]] PaidLocalState starsLocalState() const;
|
||||
[[nodiscard]] rpl::producer<> starsValueChanges() const {
|
||||
[[nodiscard]] rpl::producer<StarsDonor> starsValueChanges() const {
|
||||
return _paidChanges.events();
|
||||
}
|
||||
[[nodiscard]] const StarsTop &starsTop() const {
|
||||
@@ -155,7 +155,9 @@ private:
|
||||
const TextWithEntities &text,
|
||||
int stars) const;
|
||||
[[nodiscard]] Data::PaidReactionSend startPaidReactionSending();
|
||||
void finishPaidSending(Data::PaidReactionSend send, bool success);
|
||||
void finishPaidSending(
|
||||
Data::PaidReactionSend send,
|
||||
bool success);
|
||||
void addStars(not_null<PeerData*> from, int stars, bool mine);
|
||||
void requestStarsStats();
|
||||
|
||||
@@ -181,7 +183,7 @@ private:
|
||||
|
||||
mtpRequestId _starsTopRequestId = 0;
|
||||
Paid _paid;
|
||||
rpl::event_stream<> _paidChanges;
|
||||
rpl::event_stream<StarsDonor> _paidChanges;
|
||||
bool _paidSendingPending = false;
|
||||
|
||||
TimeId _ttl = 0;
|
||||
|
||||
Reference in New Issue
Block a user