Correctly display discussion posts sender.

This commit is contained in:
John Preston 2019-05-25 17:05:57 +02:00
parent 01054858a4
commit a64c8c52b4
7 changed files with 37 additions and 46 deletions

View File

@ -740,14 +740,8 @@ void RowPainter::paint(
auto history = item->history();
auto cloudDraft = nullptr;
const auto from = [&] {
if (const auto searchChat = row->searchInChat()) {
if (const auto peer = searchChat.peer()) {
if (peer->isSelf()) {
return item->senderOriginal();
} else if (!peer->isChannel() || peer->isMegagroup()) {
return item->from().get();
}
}
if (row->searchInChat()) {
return item->displayFrom();
}
return history->peer->migrateTo()
? history->peer->migrateTo()

View File

@ -218,6 +218,32 @@ ReplyKeyboard *HistoryItem::inlineReplyKeyboard() {
return nullptr;
}
ChannelData *HistoryItem::discussionPostOriginalSender() const {
if (!history()->peer->isMegagroup()) {
return nullptr;
}
if (const auto forwarded = Get<HistoryMessageForwarded>()) {
const auto from = forwarded->savedFromPeer;
if (const auto result = from ? from->asChannel() : nullptr) {
return result;
}
}
return nullptr;
}
bool HistoryItem::isDiscussionPost() const {
return (discussionPostOriginalSender() != nullptr);
}
PeerData *HistoryItem::displayFrom() const {
if (const auto sender = discussionPostOriginalSender()) {
return sender;
} else if (history()->peer->isSelf()) {
return senderOriginal();
}
return author().get();
}
void HistoryItem::invalidateChatListEntry() {
if (const auto main = App::main()) {
// #TODO feeds search results
@ -706,7 +732,7 @@ QString HistoryItem::inDialogsText(DrawInDialog way) const {
if (isPost() || isEmpty() || (way == DrawInDialog::WithoutSender)) {
return nullptr;
} else if (!_history->peer->isUser() || out()) {
return author();
return displayFrom();
} else if (_history->peer->isSelf() && !Has<HistoryMessageForwarded>()) {
return senderOriginal();
}

View File

@ -305,6 +305,10 @@ public:
HistoryMessageReplyMarkup *inlineReplyMarkup();
ReplyKeyboard *inlineReplyKeyboard();
[[nodiscard]] ChannelData *discussionPostOriginalSender() const;
[[nodiscard]] bool isDiscussionPost() const;
[[nodiscard]] PeerData *displayFrom() const;
virtual std::unique_ptr<HistoryView::Element> createView(
not_null<HistoryView::ElementDelegate*> delegate) = 0;

View File

@ -234,10 +234,8 @@ bool HistoryMessageReply::isNameUpdated() const {
void HistoryMessageReply::updateName() const {
if (replyToMsg) {
const auto from = [&] {
if (const auto message = replyToMsg->toHistoryMessage()) {
if (const auto from = message->displayFrom()) {
return from;
}
if (const auto from = replyToMsg->displayFrom()) {
return from;
}
return replyToMsg->author().get();
}();

View File

@ -577,32 +577,6 @@ int HistoryMessage::viewsCount() const {
return HistoryItem::viewsCount();
}
ChannelData *HistoryMessage::discussionPostOriginalSender() const {
if (!history()->peer->isMegagroup()) {
return nullptr;
}
if (const auto forwarded = Get<HistoryMessageForwarded>()) {
const auto from = forwarded->savedFromPeer;
if (const auto result = from ? from->asChannel() : nullptr) {
return result;
}
}
return nullptr;
}
bool HistoryMessage::isDiscussionPost() const {
return (discussionPostOriginalSender() != nullptr);
}
PeerData *HistoryMessage::displayFrom() const {
if (const auto sender = discussionPostOriginalSender()) {
return sender;
} else if (history()->peer->isSelf()) {
return senderOriginal();
}
return author().get();
}
bool HistoryMessage::updateDependencyItem() {
if (const auto reply = Get<HistoryMessageReply>()) {
return reply->updateData(this, true);

View File

@ -131,13 +131,10 @@ public:
[[nodiscard]] bool textHasLinks() const override;
[[nodiscard]] int viewsCount() const override;
[[nodiscard]] PeerData *displayFrom() const;
bool updateDependencyItem() override;
[[nodiscard]] MsgId dependencyMsgId() const override {
return replyToId();
}
[[nodiscard]] ChannelData *discussionPostOriginalSender() const;
[[nodiscard]] bool isDiscussionPost() const;
// dynamic_cast optimization.
[[nodiscard]] HistoryMessage *toHistoryMessage() override {

View File

@ -6437,10 +6437,8 @@ void HistoryWidget::updateReplyToName() {
}
const auto from = [&] {
const auto item = _replyEditMsg ? _replyEditMsg : _kbReplyTo;
if (const auto message = item->toHistoryMessage()) {
if (const auto from = message->displayFrom()) {
return from;
}
if (const auto from = item->displayFrom()) {
return from;
}
return item->author().get();
}();