Show via_business_bot name in signature.

This commit is contained in:
John Preston 2024-03-17 10:02:14 +04:00
parent 90e572c8b1
commit caa4c5428a
5 changed files with 29 additions and 16 deletions

View file

@ -146,6 +146,7 @@ struct HistoryItem::CreateConfig {
ReplyFields reply; ReplyFields reply;
UserId viaBotId = 0; UserId viaBotId = 0;
UserId viaBusinessBotId = 0;
int viewsCount = -1; int viewsCount = -1;
int forwardsCount = -1; int forwardsCount = -1;
int boostsApplied = 0; int boostsApplied = 0;
@ -2577,8 +2578,8 @@ QString HistoryItem::originalPostAuthor() const {
if (const auto forwarded = Get<HistoryMessageForwarded>()) { if (const auto forwarded = Get<HistoryMessageForwarded>()) {
return forwarded->originalPostAuthor; return forwarded->originalPostAuthor;
} else if (const auto msgsigned = Get<HistoryMessageSigned>()) { } else if (const auto msgsigned = Get<HistoryMessageSigned>()) {
if (!msgsigned->isAnonymousRank) { if (!msgsigned->isAnonymousRank && !msgsigned->viaBusinessBot) {
return msgsigned->postAuthor; return msgsigned->author;
} }
} }
return QString(); return QString();
@ -2650,7 +2651,9 @@ void HistoryItem::setForwardsCount(int count) {
void HistoryItem::setPostAuthor(const QString &postAuthor) { void HistoryItem::setPostAuthor(const QString &postAuthor) {
auto msgsigned = Get<HistoryMessageSigned>(); auto msgsigned = Get<HistoryMessageSigned>();
if (postAuthor.isEmpty()) { if (msgsigned && msgsigned->viaBusinessBot) {
return;
} else if (postAuthor.isEmpty()) {
if (!msgsigned) { if (!msgsigned) {
return; return;
} }
@ -2661,10 +2664,10 @@ void HistoryItem::setPostAuthor(const QString &postAuthor) {
if (!msgsigned) { if (!msgsigned) {
AddComponents(HistoryMessageSigned::Bit()); AddComponents(HistoryMessageSigned::Bit());
msgsigned = Get<HistoryMessageSigned>(); msgsigned = Get<HistoryMessageSigned>();
} else if (msgsigned->postAuthor == postAuthor) { } else if (msgsigned->author == postAuthor) {
return; return;
} }
msgsigned->postAuthor = postAuthor; msgsigned->author = postAuthor;
msgsigned->isAnonymousRank = !isDiscussionPost() msgsigned->isAnonymousRank = !isDiscussionPost()
&& this->author()->isMegagroup(); && this->author()->isMegagroup();
history()->owner().requestItemResize(this); history()->owner().requestItemResize(this);
@ -3272,7 +3275,7 @@ void HistoryItem::createComponents(CreateConfig &&config) {
if (config.viewsCount >= 0 || !config.replies.isNull) { if (config.viewsCount >= 0 || !config.replies.isNull) {
mask |= HistoryMessageViews::Bit(); mask |= HistoryMessageViews::Bit();
} }
if (!config.postAuthor.isEmpty()) { if (!config.postAuthor.isEmpty() || config.viaBusinessBotId) {
mask |= HistoryMessageSigned::Bit(); mask |= HistoryMessageSigned::Bit();
} else if (_history->peer->isMegagroup() // Discussion posts signatures. } else if (_history->peer->isMegagroup() // Discussion posts signatures.
&& config.savedFromPeer && config.savedFromPeer
@ -3345,11 +3348,17 @@ void HistoryItem::createComponents(CreateConfig &&config) {
edited->date = config.editDate; edited->date = config.editDate;
} }
if (const auto msgsigned = Get<HistoryMessageSigned>()) { if (const auto msgsigned = Get<HistoryMessageSigned>()) {
msgsigned->postAuthor = config.postAuthor.isEmpty() if (config.viaBusinessBotId) {
? config.originalPostAuthor msgsigned->viaBusinessBot = _history->owner().user(
: config.postAuthor; config.viaBusinessBotId);
msgsigned->isAnonymousRank = !isDiscussionPost() msgsigned->author = msgsigned->viaBusinessBot->name();
&& author()->isMegagroup(); } else {
msgsigned->author = config.postAuthor.isEmpty()
? config.originalPostAuthor
: config.postAuthor;
msgsigned->isAnonymousRank = !isDiscussionPost()
&& author()->isMegagroup();
}
} }
setupForwardedComponent(config); setupForwardedComponent(config);
if (const auto markup = Get<HistoryMessageReplyMarkup>()) { if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
@ -3636,6 +3645,7 @@ void HistoryItem::createComponents(const MTPDmessage &data) {
config.reply = ReplyFieldsFromMTP(this, *reply); config.reply = ReplyFieldsFromMTP(this, *reply);
} }
config.viaBotId = data.vvia_bot_id().value_or_empty(); config.viaBotId = data.vvia_bot_id().value_or_empty();
config.viaBusinessBotId = data.vvia_business_bot_id().value_or_empty();
config.viewsCount = data.vviews().value_or(-1); config.viewsCount = data.vviews().value_or(-1);
config.forwardsCount = data.vforwards().value_or(-1); config.forwardsCount = data.vforwards().value_or(-1);
config.replies = isScheduled() config.replies = isScheduled()

View file

@ -78,7 +78,8 @@ struct HistoryMessageViews : public RuntimeComponent<HistoryMessageViews, Histor
}; };
struct HistoryMessageSigned : public RuntimeComponent<HistoryMessageSigned, HistoryItem> { struct HistoryMessageSigned : public RuntimeComponent<HistoryMessageSigned, HistoryItem> {
QString postAuthor; QString author;
UserData *viaBusinessBot = nullptr;
bool isAnonymousRank = false; bool isAnonymousRank = false;
}; };

View file

@ -663,7 +663,7 @@ BottomInfo::Data BottomInfoDataFromMessage(not_null<Message*> message) {
} }
if (const auto msgsigned = item->Get<HistoryMessageSigned>()) { if (const auto msgsigned = item->Get<HistoryMessageSigned>()) {
if (!msgsigned->isAnonymousRank) { if (!msgsigned->isAnonymousRank) {
result.author = msgsigned->postAuthor; result.author = msgsigned->author;
} }
} }
if (message->displayedEditDate()) { if (message->displayedEditDate()) {

View file

@ -279,7 +279,7 @@ QString DateTooltipText(not_null<Element*> view) {
dateText += '\n' + tr::lng_signed_author( dateText += '\n' + tr::lng_signed_author(
tr::now, tr::now,
lt_user, lt_user,
msgsigned->postAuthor); msgsigned->author);
} }
} }
if (item->isScheduled() && item->isSilent()) { if (item->isScheduled() && item->isSilent()) {

View file

@ -462,8 +462,10 @@ void Message::refreshRightBadge() {
: tr::lng_channel_badge(tr::now); : tr::lng_channel_badge(tr::now);
} else if (item->author()->isMegagroup()) { } else if (item->author()->isMegagroup()) {
if (const auto msgsigned = item->Get<HistoryMessageSigned>()) { if (const auto msgsigned = item->Get<HistoryMessageSigned>()) {
Assert(msgsigned->isAnonymousRank); if (!msgsigned->viaBusinessBot) {
return msgsigned->postAuthor; Assert(msgsigned->isAnonymousRank);
return msgsigned->author;
}
} }
} }
const auto channel = item->history()->peer->asMegagroup(); const auto channel = item->history()->peer->asMegagroup();