Show "Topic Author" fake admin rank.

This commit is contained in:
John Preston 2022-10-28 12:54:06 +04:00
parent aa5f9467f2
commit af6ca8d4f1
17 changed files with 59 additions and 5 deletions

View File

@ -1682,6 +1682,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_admin_badge" = "admin";
"lng_owner_badge" = "owner";
"lng_channel_badge" = "channel";
"lng_topic_author_badge" = "Topic Author";
"lng_fast_reply" = "Reply";
"lng_cancel_edit_post_sure" = "Cancel editing?";
"lng_cancel_edit_post_yes" = "Yes";

View File

@ -149,6 +149,7 @@ ForumTopic::ForumTopic(not_null<Forum*> forum, MsgId rootId)
rootId))
, _rootId(rootId)
, _lastKnownServerMessageId(rootId)
, _creatorId(creating() ? forum->session().userPeerId() : 0)
, _creationDate(creating() ? base::unixtime::now() : 0)
, _flags(creating() ? Flag::My : Flag()) {
Thread::setMuted(owner().notifySettings().isMuted(this));
@ -203,6 +204,10 @@ MsgId ForumTopic::rootId() const {
return _rootId;
}
PeerId ForumTopic::creatorId() const {
return _creatorId;
}
TimeId ForumTopic::creationDate() const {
return _creationDate;
}
@ -267,6 +272,7 @@ void ForumTopic::readTillEnd() {
void ForumTopic::applyTopic(const MTPDforumTopic &data) {
Expects(_rootId == data.vid().v);
_creatorId = peerFromMTP(data.vfrom_id());
_creationDate = data.vdate().v;
applyTitle(qs(data.vtitle()));

View File

@ -60,6 +60,7 @@ public:
[[nodiscard]] not_null<Forum*> forum() const;
[[nodiscard]] rpl::producer<> destroyed() const;
[[nodiscard]] MsgId rootId() const;
[[nodiscard]] PeerId creatorId() const;
[[nodiscard]] TimeId creationDate() const;
[[nodiscard]] bool my() const;
@ -172,8 +173,9 @@ private:
DocumentId _iconId = 0;
base::flat_set<QString> _titleWords;
base::flat_set<QChar> _titleFirstLetters;
int _titleVersion = 0;
PeerId _creatorId = 0;
TimeId _creationDate = 0;
int _titleVersion = 0;
int32 _colorId = 0;
Flags _flags;

View File

@ -687,6 +687,10 @@ void InnerWidget::elementStartPremium(
void InnerWidget::elementCancelPremium(not_null<const Element*> view) {
}
QString InnerWidget::elementAuthorRank(not_null<const Element*> view) {
return {};
}
void InnerWidget::saveState(not_null<SectionMemento*> memento) {
memento->setFilter(std::move(_filter));
memento->setAdmins(std::move(_admins));

View File

@ -143,6 +143,8 @@ public:
HistoryView::Element *replacing) override;
void elementCancelPremium(
not_null<const HistoryView::Element*> view) override;
QString elementAuthorRank(
not_null<const HistoryView::Element*> view) override;
~InnerWidget();

View File

@ -275,6 +275,10 @@ public:
}
}
QString elementAuthorRank(not_null<const Element*> view) override {
return {};
}
not_null<HistoryView::ElementDelegate*> delegate() override {
return this;
}

View File

@ -225,6 +225,11 @@ void SimpleElementDelegate::elementCancelPremium(
not_null<const Element*> view) {
}
QString SimpleElementDelegate::elementAuthorRank(
not_null<const Element*> view) {
return {};
}
TextSelection UnshiftItemSelection(
TextSelection selection,
uint16 byLength) {

View File

@ -107,6 +107,7 @@ public:
not_null<const Element*> view,
Element *replacing) = 0;
virtual void elementCancelPremium(not_null<const Element*> view) = 0;
virtual QString elementAuthorRank(not_null<const Element*> view) = 0;
virtual ~ElementDelegate() {
}
@ -168,6 +169,8 @@ public:
not_null<const Element*> view,
Element *replacing) override;
void elementCancelPremium(not_null<const Element*> view) override;
QString elementAuthorRank(not_null<const Element*> view) override;
protected:
[[nodiscard]] not_null<Window::SessionController*> controller() const {

View File

@ -1658,6 +1658,10 @@ void ListWidget::elementCancelPremium(not_null<const Element*> view) {
_emojiInteractions->cancelPremiumEffect(view);
}
QString ListWidget::elementAuthorRank(not_null<const Element*> view) {
return _delegate->listElementAuthorRank(view);
}
void ListWidget::saveState(not_null<ListMemento*> memento) {
memento->setAroundPosition(_aroundPosition);
auto state = countScrollState();

View File

@ -139,6 +139,7 @@ public:
virtual void listPaintEmpty(
Painter &p,
const Ui::ChatPaintContext &context) = 0;
virtual QString listElementAuthorRank(not_null<const Element*> view) = 0;
};
struct SelectionData {
@ -319,6 +320,7 @@ public:
not_null<const Element*> view,
Element *replacing) override;
void elementCancelPremium(not_null<const Element*> view) override;
QString elementAuthorRank(not_null<const Element*> view) override;
void setEmptyInfoWidget(base::unique_qptr<Ui::RpWidget> &&w);

View File

@ -329,7 +329,10 @@ not_null<HistoryMessage*> Message::message() const {
void Message::refreshRightBadge() {
const auto text = [&] {
if (data()->isDiscussionPost()) {
const auto author = delegate()->elementAuthorRank(this);
if (!author.isEmpty()) {
return author;
} else if (data()->isDiscussionPost()) {
return (delegate()->elementContext() == Context::Replies)
? QString()
: tr::lng_channel_badge(tr::now);
@ -345,8 +348,8 @@ void Message::refreshRightBadge() {
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())
const auto i = info->admins.find(peerToUser(user->id));
const auto custom = (i != info->admins.end())
? i->second
: (info->creator == user)
? info->creatorRank
@ -355,7 +358,7 @@ void Message::refreshRightBadge() {
? custom
: (info->creator == user)
? tr::lng_owner_badge(tr::now)
: (i != channel->mgInfo->admins.end())
: (i != info->admins.end())
? tr::lng_admin_badge(tr::now)
: QString();
}();

View File

@ -613,6 +613,10 @@ void PinnedWidget::listPaintEmpty(
const Ui::ChatPaintContext &context) {
}
QString PinnedWidget::listElementAuthorRank(not_null<const Element*> view) {
return {};
}
void PinnedWidget::confirmDeleteSelected() {
ConfirmDeleteSelectedItems(_inner);
}

View File

@ -124,6 +124,7 @@ public:
void listPaintEmpty(
Painter &p,
const Ui::ChatPaintContext &context) override;
QString listElementAuthorRank(not_null<const Element*> view) override;
// CornerButtonsDelegate delegate.
void cornerButtonsShowAtPosition(

View File

@ -2453,6 +2453,12 @@ void RepliesWidget::listPaintEmpty(
_emptyPainter->paint(p, context.st, width(), _scroll->height());
}
QString RepliesWidget::listElementAuthorRank(not_null<const Element*> view) {
return (_topic && view->data()->from()->id == _topic->creatorId())
? tr::lng_topic_author_badge(tr::now)
: QString();
}
void RepliesWidget::setupEmptyPainter() {
Expects(_topic != nullptr);

View File

@ -165,6 +165,7 @@ public:
void listPaintEmpty(
Painter &p,
const Ui::ChatPaintContext &context) override;
QString listElementAuthorRank(not_null<const Element*> view) override;
// CornerButtonsDelegate delegate.
void cornerButtonsShowAtPosition(

View File

@ -1288,6 +1288,11 @@ void ScheduledWidget::listPaintEmpty(
const Ui::ChatPaintContext &context) {
}
QString ScheduledWidget::listElementAuthorRank(
not_null<const Element*> view) {
return {};
}
void ScheduledWidget::confirmSendNowSelected() {
ConfirmSendNowSelectedItems(_inner);
}

View File

@ -147,6 +147,7 @@ public:
void listPaintEmpty(
Painter &p,
const Ui::ChatPaintContext &context) override;
QString listElementAuthorRank(not_null<const Element*> view) override;
// CornerButtonsDelegate delegate.
void cornerButtonsShowAtPosition(