mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Improve root message layout in Replies section.
This commit is contained in:
parent
9a96298ef7
commit
883c3ecf65
8 changed files with 84 additions and 79 deletions
|
@ -3283,7 +3283,7 @@ void History::clearUpTill(MsgId availableMinId) {
|
||||||
void History::applyGroupAdminChanges(const base::flat_set<UserId> &changes) {
|
void History::applyGroupAdminChanges(const base::flat_set<UserId> &changes) {
|
||||||
for (const auto &block : blocks) {
|
for (const auto &block : blocks) {
|
||||||
for (const auto &message : block->messages) {
|
for (const auto &message : block->messages) {
|
||||||
message->data()->applyGroupAdminChanges(changes);
|
message->applyGroupAdminChanges(changes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,9 +80,6 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
[[nodiscard]] PeerData *specialNotificationPeer() const;
|
[[nodiscard]] PeerData *specialNotificationPeer() const;
|
||||||
virtual void applyGroupAdminChanges(
|
|
||||||
const base::flat_set<UserId> &changes) {
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] UserData *viaBot() const;
|
[[nodiscard]] UserData *viaBot() const;
|
||||||
[[nodiscard]] UserData *getMessageBot() const;
|
[[nodiscard]] UserData *getMessageBot() const;
|
||||||
|
|
|
@ -501,8 +501,6 @@ HistoryMessage::HistoryMessage(
|
||||||
setGroupId(
|
setGroupId(
|
||||||
MessageGroupId::FromRaw(history->peer->id, groupedId->v));
|
MessageGroupId::FromRaw(history->peer->id, groupedId->v));
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshMessageBadge();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryMessage::HistoryMessage(
|
HistoryMessage::HistoryMessage(
|
||||||
|
@ -879,48 +877,6 @@ bool HistoryMessage::updateDependencyItem() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryMessage::refreshMessageBadge() {
|
|
||||||
const auto text = [&] {
|
|
||||||
if (isDiscussionPost()) {
|
|
||||||
return tr::lng_channel_badge(tr::now);
|
|
||||||
}
|
|
||||||
const auto channel = history()->peer->asMegagroup();
|
|
||||||
const auto user = author()->asUser();
|
|
||||||
if (!channel || !user) {
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
const auto info = channel->mgInfo.get();
|
|
||||||
const auto i = channel->mgInfo->admins.find(peerToUser(user->id));
|
|
||||||
const auto custom = (i != channel->mgInfo->admins.end())
|
|
||||||
? i->second
|
|
||||||
: (info->creator == user)
|
|
||||||
? info->creatorRank
|
|
||||||
: QString();
|
|
||||||
return !custom.isEmpty()
|
|
||||||
? custom
|
|
||||||
: (info->creator == user)
|
|
||||||
? tr::lng_owner_badge(tr::now)
|
|
||||||
: (i != channel->mgInfo->admins.end())
|
|
||||||
? tr::lng_admin_badge(tr::now)
|
|
||||||
: QString();
|
|
||||||
}();
|
|
||||||
if (text.isEmpty()) {
|
|
||||||
_messageBadge.clear();
|
|
||||||
} else {
|
|
||||||
_messageBadge.setText(
|
|
||||||
st::defaultTextStyle,
|
|
||||||
TextUtilities::RemoveEmoji(TextUtilities::SingleLine(text)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HistoryMessage::applyGroupAdminChanges(
|
|
||||||
const base::flat_set<UserId> &changes) {
|
|
||||||
if (!out() && changes.contains(peerToUser(author()->id))) {
|
|
||||||
refreshMessageBadge();
|
|
||||||
history()->owner().requestItemResize(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HistoryMessage::allowsForward() const {
|
bool HistoryMessage::allowsForward() const {
|
||||||
if (id < 0 || !isHistoryEntry()) {
|
if (id < 0 || !isHistoryEntry()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -119,19 +119,10 @@ public:
|
||||||
[[nodiscard]] bool allowsEdit(TimeId now) const override;
|
[[nodiscard]] bool allowsEdit(TimeId now) const override;
|
||||||
[[nodiscard]] bool uploading() const;
|
[[nodiscard]] bool uploading() const;
|
||||||
|
|
||||||
[[nodiscard]] const Ui::Text::String &messageBadge() const {
|
|
||||||
return _messageBadge;
|
|
||||||
}
|
|
||||||
[[nodiscard]] bool hasMessageBadge() const {
|
|
||||||
return !_messageBadge.isEmpty();
|
|
||||||
}
|
|
||||||
[[nodiscard]] bool hideEditedBadge() const {
|
[[nodiscard]] bool hideEditedBadge() const {
|
||||||
return (_flags & MTPDmessage::Flag::f_edit_hide);
|
return (_flags & MTPDmessage::Flag::f_edit_hide);
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyGroupAdminChanges(
|
|
||||||
const base::flat_set<UserId> &changes) override;
|
|
||||||
|
|
||||||
void setViewsCount(int count) override;
|
void setViewsCount(int count) override;
|
||||||
void setForwardsCount(int count) override;
|
void setForwardsCount(int count) override;
|
||||||
void setReplies(const MTPMessageReplies &data) override;
|
void setReplies(const MTPMessageReplies &data) override;
|
||||||
|
@ -228,14 +219,11 @@ private:
|
||||||
CreateConfig &config,
|
CreateConfig &config,
|
||||||
const MTPDmessageFwdHeader &data);
|
const MTPDmessageFwdHeader &data);
|
||||||
|
|
||||||
void refreshMessageBadge();
|
|
||||||
[[nodiscard]] bool generateLocalEntitiesByReply() const;
|
[[nodiscard]] bool generateLocalEntitiesByReply() const;
|
||||||
[[nodiscard]] TextWithEntities withLocalEntities(
|
[[nodiscard]] TextWithEntities withLocalEntities(
|
||||||
const TextWithEntities &textWithEntities) const;
|
const TextWithEntities &textWithEntities) const;
|
||||||
void reapplyText();
|
void reapplyText();
|
||||||
|
|
||||||
Ui::Text::String _messageBadge;
|
|
||||||
|
|
||||||
QString _timeText;
|
QString _timeText;
|
||||||
int _timeWidth = 0;
|
int _timeWidth = 0;
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ class Media;
|
||||||
|
|
||||||
enum class Context : char {
|
enum class Context : char {
|
||||||
History,
|
History,
|
||||||
|
Replies,
|
||||||
//Feed, // #feed
|
//Feed, // #feed
|
||||||
AdminLog,
|
AdminLog,
|
||||||
ContactPreview
|
ContactPreview
|
||||||
|
@ -271,6 +272,9 @@ public:
|
||||||
virtual TimeId displayedEditDate() const;
|
virtual TimeId displayedEditDate() const;
|
||||||
virtual bool hasVisibleText() const;
|
virtual bool hasVisibleText() const;
|
||||||
virtual HistoryMessageReply *displayedReply() const;
|
virtual HistoryMessageReply *displayedReply() const;
|
||||||
|
virtual void applyGroupAdminChanges(
|
||||||
|
const base::flat_set<UserId> &changes) {
|
||||||
|
}
|
||||||
|
|
||||||
struct VerticalRepaintRange {
|
struct VerticalRepaintRange {
|
||||||
int top = 0;
|
int top = 0;
|
||||||
|
|
|
@ -236,6 +236,51 @@ not_null<HistoryMessage*> Message::message() const {
|
||||||
return static_cast<HistoryMessage*>(data().get());
|
return static_cast<HistoryMessage*>(data().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Message::refreshRightBadge() {
|
||||||
|
const auto text = [&] {
|
||||||
|
if (data()->isDiscussionPost()) {
|
||||||
|
return (delegate()->elementContext() == Context::Replies)
|
||||||
|
? QString()
|
||||||
|
: tr::lng_channel_badge(tr::now);
|
||||||
|
}
|
||||||
|
const auto channel = data()->history()->peer->asMegagroup();
|
||||||
|
const auto user = data()->author()->asUser();
|
||||||
|
if (!channel || !user) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
const auto info = channel->mgInfo.get();
|
||||||
|
const auto i = channel->mgInfo->admins.find(peerToUser(user->id));
|
||||||
|
const auto custom = (i != channel->mgInfo->admins.end())
|
||||||
|
? i->second
|
||||||
|
: (info->creator == user)
|
||||||
|
? info->creatorRank
|
||||||
|
: QString();
|
||||||
|
return !custom.isEmpty()
|
||||||
|
? custom
|
||||||
|
: (info->creator == user)
|
||||||
|
? tr::lng_owner_badge(tr::now)
|
||||||
|
: (i != channel->mgInfo->admins.end())
|
||||||
|
? tr::lng_admin_badge(tr::now)
|
||||||
|
: QString();
|
||||||
|
}();
|
||||||
|
if (text.isEmpty()) {
|
||||||
|
_rightBadge.clear();
|
||||||
|
} else {
|
||||||
|
_rightBadge.setText(
|
||||||
|
st::defaultTextStyle,
|
||||||
|
TextUtilities::RemoveEmoji(TextUtilities::SingleLine(text)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Message::applyGroupAdminChanges(
|
||||||
|
const base::flat_set<UserId> &changes) {
|
||||||
|
if (!data()->out()
|
||||||
|
&& changes.contains(peerToUser(data()->author()->id))) {
|
||||||
|
refreshRightBadge();
|
||||||
|
history()->owner().requestViewResize(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QSize Message::performCountOptimalSize() {
|
QSize Message::performCountOptimalSize() {
|
||||||
const auto item = message();
|
const auto item = message();
|
||||||
const auto media = this->media();
|
const auto media = this->media();
|
||||||
|
@ -330,8 +375,8 @@ QSize Message::performCountOptimalSize() {
|
||||||
const auto replyWidth = hasFastReply()
|
const auto replyWidth = hasFastReply()
|
||||||
? st::msgFont->width(FastReplyText())
|
? st::msgFont->width(FastReplyText())
|
||||||
: 0;
|
: 0;
|
||||||
if (item->hasMessageBadge()) {
|
if (!_rightBadge.isEmpty()) {
|
||||||
const auto badgeWidth = item->messageBadge().maxWidth();
|
const auto badgeWidth = _rightBadge.maxWidth();
|
||||||
namew += st::msgPadding.right()
|
namew += st::msgPadding.right()
|
||||||
+ std::max(badgeWidth, replyWidth);
|
+ std::max(badgeWidth, replyWidth);
|
||||||
} else if (replyWidth) {
|
} else if (replyWidth) {
|
||||||
|
@ -745,12 +790,7 @@ void Message::paintFromName(
|
||||||
bool selected) const {
|
bool selected) const {
|
||||||
const auto item = message();
|
const auto item = message();
|
||||||
if (displayFromName()) {
|
if (displayFromName()) {
|
||||||
const auto badgeWidth = [&] {
|
const auto badgeWidth = _rightBadge.isEmpty() ? 0 : _rightBadge.maxWidth();
|
||||||
if (item->hasMessageBadge()) {
|
|
||||||
return item->messageBadge().maxWidth();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}();
|
|
||||||
const auto replyWidth = [&] {
|
const auto replyWidth = [&] {
|
||||||
if (isUnderCursor() && displayFastReply()) {
|
if (isUnderCursor() && displayFastReply()) {
|
||||||
return st::msgFont->width(FastReplyText());
|
return st::msgFont->width(FastReplyText());
|
||||||
|
@ -808,7 +848,7 @@ void Message::paintFromName(
|
||||||
trect.top() + st::msgFont->ascent,
|
trect.top() + st::msgFont->ascent,
|
||||||
FastReplyText());
|
FastReplyText());
|
||||||
} else {
|
} else {
|
||||||
item->messageBadge().draw(
|
_rightBadge.draw(
|
||||||
p,
|
p,
|
||||||
trect.left() + trect.width() - rightWidth,
|
trect.left() + trect.width() - rightWidth,
|
||||||
trect.top(),
|
trect.top(),
|
||||||
|
@ -1066,7 +1106,8 @@ bool Message::hasFromPhoto() const {
|
||||||
case Context::AdminLog:
|
case Context::AdminLog:
|
||||||
//case Context::Feed: // #feed
|
//case Context::Feed: // #feed
|
||||||
return true;
|
return true;
|
||||||
case Context::History: {
|
case Context::History:
|
||||||
|
case Context::Replies: {
|
||||||
const auto item = message();
|
const auto item = message();
|
||||||
if (item->isPost() || item->isEmpty()) {
|
if (item->isPost() || item->isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1657,7 +1698,9 @@ void Message::drawInfo(
|
||||||
auto left = infoRight - infoW;
|
auto left = infoRight - infoW;
|
||||||
const auto iconTop = infoBottom + st::historyViewsTop;
|
const auto iconTop = infoBottom + st::historyViewsTop;
|
||||||
const auto textTop = infoBottom - st::msgDateFont->descent;
|
const auto textTop = infoBottom - st::msgDateFont->descent;
|
||||||
if (views->replies.count > 0 && !views->commentsChannelId) {
|
if (views->replies.count > 0
|
||||||
|
&& !views->commentsChannelId
|
||||||
|
&& context() != Context::Replies) {
|
||||||
auto icon = [&] {
|
auto icon = [&] {
|
||||||
if (item->id > 0) {
|
if (item->id > 0) {
|
||||||
if (outbg) {
|
if (outbg) {
|
||||||
|
@ -1774,7 +1817,9 @@ int Message::infoWidth() const {
|
||||||
+ views->views.textWidth
|
+ views->views.textWidth
|
||||||
+ st::historyViewsWidth;
|
+ st::historyViewsWidth;
|
||||||
}
|
}
|
||||||
if (views->replies.count > 0 && !views->commentsChannelId) {
|
if (views->replies.count > 0
|
||||||
|
&& !views->commentsChannelId
|
||||||
|
&& context() != Context::Replies) {
|
||||||
result += st::historyViewsSpace
|
result += st::historyViewsSpace
|
||||||
+ views->replies.textWidth
|
+ views->replies.textWidth
|
||||||
+ st::historyViewsWidth;
|
+ st::historyViewsWidth;
|
||||||
|
@ -1823,7 +1868,9 @@ int Message::timeLeft() const {
|
||||||
if (views->views.count >= 0) {
|
if (views->views.count >= 0) {
|
||||||
result += st::historyViewsSpace + views->views.textWidth + st::historyViewsWidth;
|
result += st::historyViewsSpace + views->views.textWidth + st::historyViewsWidth;
|
||||||
}
|
}
|
||||||
if (views->replies.count > 0 && !views->commentsChannelId) {
|
if (views->replies.count > 0
|
||||||
|
&& !views->commentsChannelId
|
||||||
|
&& context() != Context::Replies) {
|
||||||
result += st::historyViewsSpace + views->replies.textWidth + st::historyViewsWidth;
|
result += st::historyViewsSpace + views->replies.textWidth + st::historyViewsWidth;
|
||||||
}
|
}
|
||||||
} else if (item->id < 0 && item->history()->peer->isSelf()) {
|
} else if (item->id < 0 && item->history()->peer->isSelf()) {
|
||||||
|
@ -1882,7 +1929,8 @@ bool Message::hasFromName() const {
|
||||||
case Context::AdminLog:
|
case Context::AdminLog:
|
||||||
//case Context::Feed: // #feed
|
//case Context::Feed: // #feed
|
||||||
return true;
|
return true;
|
||||||
case Context::History: {
|
case Context::History:
|
||||||
|
case Context::Replies: {
|
||||||
const auto item = message();
|
const auto item = message();
|
||||||
return (!hasOutLayout() || item->from()->isMegagroup())
|
return (!hasOutLayout() || item->from()->isMegagroup())
|
||||||
&& (!item->history()->peer->isUser()
|
&& (!item->history()->peer->isUser()
|
||||||
|
@ -1951,7 +1999,11 @@ bool Message::hasBubble() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Message::hasFastReply() const {
|
bool Message::hasFastReply() const {
|
||||||
if (context() != Context::History) {
|
if (context() == Context::Replies) {
|
||||||
|
if (data()->isDiscussionPost()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (context() != Context::History) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto peer = data()->history()->peer;
|
const auto peer = data()->history()->peer;
|
||||||
|
@ -1997,7 +2049,8 @@ bool Message::displayGoToOriginal() const {
|
||||||
if (const auto forwarded = item->Get<HistoryMessageForwarded>()) {
|
if (const auto forwarded = item->Get<HistoryMessageForwarded>()) {
|
||||||
return forwarded->savedFromPeer
|
return forwarded->savedFromPeer
|
||||||
&& forwarded->savedFromMsgId
|
&& forwarded->savedFromMsgId
|
||||||
&& (!item->externalReply() || !hasBubble());
|
&& (!item->externalReply() || !hasBubble())
|
||||||
|
&& !(context() == Context::Replies);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2123,8 +2176,8 @@ void Message::fromNameUpdated(int width) const {
|
||||||
const auto replyWidth = hasFastReply()
|
const auto replyWidth = hasFastReply()
|
||||||
? st::msgFont->width(FastReplyText())
|
? st::msgFont->width(FastReplyText())
|
||||||
: 0;
|
: 0;
|
||||||
if (item->hasMessageBadge()) {
|
if (!_rightBadge.isEmpty()) {
|
||||||
const auto badgeWidth = item->messageBadge().maxWidth();
|
const auto badgeWidth = _rightBadge.maxWidth();
|
||||||
width -= st::msgPadding.right() + std::max(badgeWidth, replyWidth);
|
width -= st::msgPadding.right() + std::max(badgeWidth, replyWidth);
|
||||||
} else if (replyWidth) {
|
} else if (replyWidth) {
|
||||||
width -= st::msgPadding.right() + replyWidth;
|
width -= st::msgPadding.right() + replyWidth;
|
||||||
|
|
|
@ -107,6 +107,9 @@ public:
|
||||||
|
|
||||||
VerticalRepaintRange verticalRepaintRange() const override;
|
VerticalRepaintRange verticalRepaintRange() const override;
|
||||||
|
|
||||||
|
void applyGroupAdminChanges(
|
||||||
|
const base::flat_set<UserId> &changes) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void refreshDataIdHook() override;
|
void refreshDataIdHook() override;
|
||||||
|
|
||||||
|
@ -186,9 +189,13 @@ private:
|
||||||
[[nodiscard]] ClickHandlerPtr psaTooltipLink() const;
|
[[nodiscard]] ClickHandlerPtr psaTooltipLink() const;
|
||||||
void psaTooltipToggled(bool shown) const;
|
void psaTooltipToggled(bool shown) const;
|
||||||
|
|
||||||
|
void refreshRightBadge();
|
||||||
|
|
||||||
mutable ClickHandlerPtr _rightActionLink;
|
mutable ClickHandlerPtr _rightActionLink;
|
||||||
mutable ClickHandlerPtr _fastReplyLink;
|
mutable ClickHandlerPtr _fastReplyLink;
|
||||||
mutable std::unique_ptr<CommentsButton> _comments;
|
mutable std::unique_ptr<CommentsButton> _comments;
|
||||||
|
|
||||||
|
Ui::Text::String _rightBadge;
|
||||||
int _bubbleWidthLimit = 0;
|
int _bubbleWidthLimit = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1381,7 +1381,7 @@ QRect RepliesWidget::floatPlayerAvailableRect() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Context RepliesWidget::listContext() {
|
Context RepliesWidget::listContext() {
|
||||||
return Context::History;
|
return Context::Replies;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepliesWidget::listScrollTo(int top) {
|
void RepliesWidget::listScrollTo(int top) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue