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