diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index bfa68bed59..cec1042d53 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -146,6 +146,7 @@ struct HistoryItem::CreateConfig { ReplyFields reply; UserId viaBotId = 0; + UserId viaBusinessBotId = 0; int viewsCount = -1; int forwardsCount = -1; int boostsApplied = 0; @@ -2577,8 +2578,8 @@ QString HistoryItem::originalPostAuthor() const { if (const auto forwarded = Get()) { return forwarded->originalPostAuthor; } else if (const auto msgsigned = Get()) { - if (!msgsigned->isAnonymousRank) { - return msgsigned->postAuthor; + if (!msgsigned->isAnonymousRank && !msgsigned->viaBusinessBot) { + return msgsigned->author; } } return QString(); @@ -2650,7 +2651,9 @@ void HistoryItem::setForwardsCount(int count) { void HistoryItem::setPostAuthor(const QString &postAuthor) { auto msgsigned = Get(); - if (postAuthor.isEmpty()) { + if (msgsigned && msgsigned->viaBusinessBot) { + return; + } else if (postAuthor.isEmpty()) { if (!msgsigned) { return; } @@ -2661,10 +2664,10 @@ void HistoryItem::setPostAuthor(const QString &postAuthor) { if (!msgsigned) { AddComponents(HistoryMessageSigned::Bit()); msgsigned = Get(); - } else if (msgsigned->postAuthor == postAuthor) { + } else if (msgsigned->author == postAuthor) { return; } - msgsigned->postAuthor = postAuthor; + msgsigned->author = postAuthor; msgsigned->isAnonymousRank = !isDiscussionPost() && this->author()->isMegagroup(); history()->owner().requestItemResize(this); @@ -3272,7 +3275,7 @@ void HistoryItem::createComponents(CreateConfig &&config) { if (config.viewsCount >= 0 || !config.replies.isNull) { mask |= HistoryMessageViews::Bit(); } - if (!config.postAuthor.isEmpty()) { + if (!config.postAuthor.isEmpty() || config.viaBusinessBotId) { mask |= HistoryMessageSigned::Bit(); } else if (_history->peer->isMegagroup() // Discussion posts signatures. && config.savedFromPeer @@ -3345,11 +3348,17 @@ void HistoryItem::createComponents(CreateConfig &&config) { edited->date = config.editDate; } if (const auto msgsigned = Get()) { - msgsigned->postAuthor = config.postAuthor.isEmpty() - ? config.originalPostAuthor - : config.postAuthor; - msgsigned->isAnonymousRank = !isDiscussionPost() - && author()->isMegagroup(); + if (config.viaBusinessBotId) { + msgsigned->viaBusinessBot = _history->owner().user( + config.viaBusinessBotId); + msgsigned->author = msgsigned->viaBusinessBot->name(); + } else { + msgsigned->author = config.postAuthor.isEmpty() + ? config.originalPostAuthor + : config.postAuthor; + msgsigned->isAnonymousRank = !isDiscussionPost() + && author()->isMegagroup(); + } } setupForwardedComponent(config); if (const auto markup = Get()) { @@ -3636,6 +3645,7 @@ void HistoryItem::createComponents(const MTPDmessage &data) { config.reply = ReplyFieldsFromMTP(this, *reply); } 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.forwardsCount = data.vforwards().value_or(-1); config.replies = isScheduled() diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 4d60ff9a34..61b1d86f4b 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -78,7 +78,8 @@ struct HistoryMessageViews : public RuntimeComponent { - QString postAuthor; + QString author; + UserData *viaBusinessBot = nullptr; bool isAnonymousRank = false; }; diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp index a13eb3fe58..a4000efe1c 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp @@ -663,7 +663,7 @@ BottomInfo::Data BottomInfoDataFromMessage(not_null message) { } if (const auto msgsigned = item->Get()) { if (!msgsigned->isAnonymousRank) { - result.author = msgsigned->postAuthor; + result.author = msgsigned->author; } } if (message->displayedEditDate()) { diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 3e142d0c9e..1f99b66c7b 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -279,7 +279,7 @@ QString DateTooltipText(not_null view) { dateText += '\n' + tr::lng_signed_author( tr::now, lt_user, - msgsigned->postAuthor); + msgsigned->author); } } if (item->isScheduled() && item->isSilent()) { diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 2e8f79f300..4196440955 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -462,8 +462,10 @@ void Message::refreshRightBadge() { : tr::lng_channel_badge(tr::now); } else if (item->author()->isMegagroup()) { if (const auto msgsigned = item->Get()) { - Assert(msgsigned->isAnonymousRank); - return msgsigned->postAuthor; + if (!msgsigned->viaBusinessBot) { + Assert(msgsigned->isAnonymousRank); + return msgsigned->author; + } } } const auto channel = item->history()->peer->asMegagroup();