mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 05:07:10 +02:00
Added ability to emplace badge in dialog row for subscribed channels.
This commit is contained in:
parent
81a79e2895
commit
dca61541d6
7 changed files with 42 additions and 11 deletions
|
@ -1028,6 +1028,14 @@ void ChannelData::updateLevelHint(int levelHint) {
|
|||
_levelHint = levelHint;
|
||||
}
|
||||
|
||||
TimeId ChannelData::subscriptionUntilDate() const {
|
||||
return _subscriptionUntilDate;
|
||||
}
|
||||
|
||||
void ChannelData::updateSubscriptionUntilDate(TimeId subscriptionUntilDate) {
|
||||
_subscriptionUntilDate = subscriptionUntilDate;
|
||||
}
|
||||
|
||||
namespace Data {
|
||||
|
||||
void ApplyMigration(
|
||||
|
|
|
@ -489,6 +489,9 @@ public:
|
|||
[[nodiscard]] int levelHint() const;
|
||||
void updateLevelHint(int levelHint);
|
||||
|
||||
[[nodiscard]] TimeId subscriptionUntilDate() const;
|
||||
void updateSubscriptionUntilDate(TimeId subscriptionUntilDate);
|
||||
|
||||
// Still public data members.
|
||||
uint64 access = 0;
|
||||
|
||||
|
@ -531,6 +534,7 @@ private:
|
|||
AdminRightFlags _adminRights;
|
||||
RestrictionFlags _restrictions;
|
||||
TimeId _restrictedUntil;
|
||||
TimeId _subscriptionUntilDate;
|
||||
|
||||
std::vector<Data::UnavailableReason> _unavailableReasons;
|
||||
std::unique_ptr<InvitePeek> _invitePeek;
|
||||
|
|
|
@ -508,6 +508,10 @@ bool ChannelHasActiveCall(not_null<ChannelData*> channel) {
|
|||
return (channel->flags() & ChannelDataFlag::CallNotEmpty);
|
||||
}
|
||||
|
||||
bool ChannelHasSubscriptionUntilDate(ChannelData *channel) {
|
||||
return channel && channel->subscriptionUntilDate() > 0;
|
||||
}
|
||||
|
||||
rpl::producer<QImage> PeerUserpicImageValue(
|
||||
not_null<PeerData*> peer,
|
||||
int size,
|
||||
|
|
|
@ -164,6 +164,7 @@ inline auto PeerFullFlagValue(
|
|||
[[nodiscard]] bool OnlineTextActive(not_null<UserData*> user, TimeId now);
|
||||
[[nodiscard]] bool IsUserOnline(not_null<UserData*> user, TimeId now = 0);
|
||||
[[nodiscard]] bool ChannelHasActiveCall(not_null<ChannelData*> channel);
|
||||
[[nodiscard]] bool ChannelHasSubscriptionUntilDate(ChannelData *channel);
|
||||
|
||||
[[nodiscard]] rpl::producer<QImage> PeerUserpicImageValue(
|
||||
not_null<PeerData*> peer,
|
||||
|
|
|
@ -880,6 +880,8 @@ not_null<PeerData*> Session::processChat(const MTPChat &data) {
|
|||
const auto wasCallNotEmpty = Data::ChannelHasActiveCall(channel);
|
||||
|
||||
channel->updateLevelHint(data.vlevel().value_or_empty());
|
||||
channel->updateSubscriptionUntilDate(
|
||||
data.vsubscription_until_date().value_or_empty());
|
||||
if (const auto count = data.vparticipants_count()) {
|
||||
channel->setMembersCount(count->v);
|
||||
}
|
||||
|
|
|
@ -301,11 +301,13 @@ void Row::updateCornerBadgeShown(
|
|||
Fn<void()> updateCallback) const {
|
||||
const auto user = peer->asUser();
|
||||
const auto now = user ? base::unixtime::now() : TimeId();
|
||||
const auto channel = user ? nullptr : peer->asChannel();
|
||||
const auto nextLayer = [&] {
|
||||
if (user && Data::IsUserOnline(user, now)) {
|
||||
return kTopLayer;
|
||||
} else if (peer->isChannel()
|
||||
&& Data::ChannelHasActiveCall(peer->asChannel())) {
|
||||
} else if (channel
|
||||
&& (Data::ChannelHasActiveCall(channel)
|
||||
|| Data::ChannelHasSubscriptionUntilDate(channel))) {
|
||||
return kTopLayer;
|
||||
} else if (peer->messagesTTL()) {
|
||||
return kBottomLayer;
|
||||
|
@ -332,7 +334,8 @@ void Row::PaintCornerBadgeFrame(
|
|||
PeerData *peer,
|
||||
Ui::VideoUserpic *videoUserpic,
|
||||
Ui::PeerUserpicView &view,
|
||||
const Ui::PaintContext &context) {
|
||||
const Ui::PaintContext &context,
|
||||
bool subscribed) {
|
||||
data->frame.fill(Qt::transparent);
|
||||
|
||||
Painter q(&data->frame);
|
||||
|
@ -389,6 +392,11 @@ void Row::PaintCornerBadgeFrame(
|
|||
Ui::PaintOutlineSegments(q, outline, segments);
|
||||
}
|
||||
|
||||
if (subscribed) {
|
||||
// Draw badge.
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &manager = data->layersManager;
|
||||
if (const auto p = manager.progressForLayer(kBottomLayer); p > 0.) {
|
||||
const auto size = photoSize;
|
||||
|
@ -419,6 +427,7 @@ void Row::PaintCornerBadgeFrame(
|
|||
? st::dialogsOnlineBadgeSkip
|
||||
: st::dialogsCallBadgeSkip;
|
||||
const auto shrink = (size / 2) * (1. - topLayerProgress);
|
||||
const auto doubleShrink = shrink * 2;
|
||||
|
||||
auto pen = QPen(Qt::transparent);
|
||||
pen.setWidthF(stroke * topLayerProgress);
|
||||
|
@ -427,11 +436,10 @@ void Row::PaintCornerBadgeFrame(
|
|||
? st::dialogsOnlineBadgeFgActive
|
||||
: st::dialogsOnlineBadgeFg);
|
||||
q.drawEllipse(QRectF(
|
||||
photoSize - skip.x() - size,
|
||||
photoSize - skip.y() - size,
|
||||
size,
|
||||
size
|
||||
).marginsRemoved({ shrink, shrink, shrink, shrink }));
|
||||
photoSize - skip.x() - size - shrink,
|
||||
photoSize - skip.y() - size - shrink,
|
||||
size + doubleShrink,
|
||||
size + doubleShrink));
|
||||
}
|
||||
|
||||
void Row::paintUserpic(
|
||||
|
@ -509,6 +517,8 @@ void Row::paintUserpic(
|
|||
if (keyChanged) {
|
||||
_cornerBadgeUserpic->cacheTTL = QImage();
|
||||
}
|
||||
const auto subscribed = Data::ChannelHasSubscriptionUntilDate(
|
||||
peer ? peer->asChannel() : nullptr);
|
||||
if (keyChanged
|
||||
|| !_cornerBadgeUserpic->layersManager.isFinished()
|
||||
|| _cornerBadgeUserpic->active != active
|
||||
|
@ -530,14 +540,15 @@ void Row::paintUserpic(
|
|||
peer,
|
||||
videoUserpic,
|
||||
userpicView(),
|
||||
context);
|
||||
context,
|
||||
subscribed);
|
||||
}
|
||||
p.drawImage(
|
||||
context.st->padding.left() - framePadding,
|
||||
context.st->padding.top() - framePadding,
|
||||
_cornerBadgeUserpic->frame);
|
||||
const auto history = _id.history();
|
||||
if (!history || history->peer->isUser()) {
|
||||
if (!history || history->peer->isUser() || subscribed) {
|
||||
return;
|
||||
}
|
||||
const auto actionPainter = history->sendActionPainter();
|
||||
|
|
|
@ -192,7 +192,8 @@ private:
|
|||
PeerData *peer,
|
||||
Ui::VideoUserpic *videoUserpic,
|
||||
Ui::PeerUserpicView &view,
|
||||
const Ui::PaintContext &context);
|
||||
const Ui::PaintContext &context,
|
||||
bool subscribed);
|
||||
|
||||
Key _id;
|
||||
mutable std::unique_ptr<CornerBadgeUserpic> _cornerBadgeUserpic;
|
||||
|
|
Loading…
Add table
Reference in a new issue