Always use fresh admin rank, remembered user rank.

This commit is contained in:
John Preston
2026-02-16 23:53:02 +04:00
parent cefce69fda
commit f60dfaf14a
5 changed files with 39 additions and 15 deletions
@@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_user.h"
#include "main/main_session.h" #include "main/main_session.h"
namespace Data { namespace Data {
@@ -76,12 +77,24 @@ void ChannelMemberRankChanges::feed(
} }
ChannelMemberRankChanges::~ChannelMemberRankChanges() { ChannelMemberRankChanges::~ChannelMemberRankChanges() {
if (_changes.size() > 1 if (_changes.empty()) {
|| (!_changes.empty() return;
&& _changes.front() != _channel->session().userId())) { }
const auto info = _channel->mgInfo.get();
auto adminChanges = base::flat_set<UserId>();
for (const auto &userId : _changes) {
if (info->admins.contains(userId)
|| (info->creator
&& peerToUser(info->creator->id) == userId)) {
adminChanges.emplace(userId);
}
}
if (adminChanges.size() > 1
|| (!adminChanges.empty()
&& adminChanges.front() != _channel->session().userId())) {
if (const auto history if (const auto history
= _channel->owner().historyLoaded(_channel)) { = _channel->owner().historyLoaded(_channel)) {
history->applyGroupAdminChanges(_changes); history->applyGroupAdminChanges(adminChanges);
} }
} }
} }
@@ -2117,6 +2117,15 @@ void HistoryItem::applyEdition(HistoryMessageEdition &&edition) {
applyTTL(edition.ttl); applyTTL(edition.ttl);
setFactcheck(FromMTP(this, edition.mtpFactcheck)); setFactcheck(FromMTP(this, edition.mtpFactcheck));
if (!edition.fromRank.isEmpty()) {
if (!Has<HistoryMessageFromRank>()) {
AddComponents(HistoryMessageFromRank::Bit());
}
Get<HistoryMessageFromRank>()->rank = edition.fromRank;
} else {
RemoveComponents(HistoryMessageFromRank::Bit());
}
finishEdition(keyboardTop); finishEdition(keyboardTop);
} }
@@ -34,6 +34,9 @@ HistoryMessageEdition::HistoryMessageEdition(
replies = HistoryMessageRepliesData(mtpReplies); replies = HistoryMessageRepliesData(mtpReplies);
} }
invertMedia = message.is_invert_media(); invertMedia = message.is_invert_media();
if (const auto rank = message.vfrom_rank()) {
fromRank = qs(*rank);
}
const auto period = message.vttl_period(); const auto period = message.vttl_period();
ttl = (period && period->v > 0) ? (message.vdate().v + period->v) : 0; ttl = (period && period->v > 0) ? (message.vdate().v + period->v) : 0;
@@ -41,4 +41,5 @@ struct HistoryMessageEdition {
const MTPMessageMedia *mtpMedia = nullptr; const MTPMessageMedia *mtpMedia = nullptr;
const MTPMessageReactions *mtpReactions = nullptr; const MTPMessageReactions *mtpReactions = nullptr;
const MTPFactCheck *mtpFactcheck = nullptr; const MTPFactCheck *mtpFactcheck = nullptr;
QString fromRank;
}; };
@@ -293,18 +293,16 @@ void Message::refreshRightBadge() {
} }
const auto info = channel->mgInfo.get(); const auto info = channel->mgInfo.get();
const auto userId = peerToUser(user->id); const auto userId = peerToUser(user->id);
const auto isCreator = (info->creator == user);
const auto isAdmin = info->admins.contains(userId); const auto isAdmin = info->admins.contains(userId);
const auto r = info->memberRanks.find(userId); if (isCreator || isAdmin) {
const auto custom = (r != info->memberRanks.end()) const auto r = info->memberRanks.find(userId);
? r->second if (r != info->memberRanks.end() && !r->second.isEmpty()) {
: QString(); return { r->second, true };
if (!custom.isEmpty()) { }
return { custom, isAdmin || info->creator == user }; if (isCreator) {
} return { tr::lng_owner_badge(tr::now), true };
if (info->creator == user) { }
return { tr::lng_owner_badge(tr::now), true };
}
if (isAdmin) {
return { tr::lng_admin_badge(tr::now), true }; return { tr::lng_admin_badge(tr::now), true };
} }
const auto fromRank = item->fromRank(); const auto fromRank = item->fromRank();