From be1445629034532dc5b000af5e4c061fe78919c1 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 11 Sep 2020 19:22:14 +0300 Subject: [PATCH] Show correct reply in Replies bot. --- .../export/data/export_data_types.cpp | 5 +++- .../export/output/export_output_html.cpp | 8 ++++-- .../export/output/export_output_json.cpp | 3 +++ Telegram/SourceFiles/history/history_item.cpp | 2 +- .../history/history_item_components.cpp | 4 ++- .../history/history_item_components.h | 5 ++++ .../SourceFiles/history/history_message.cpp | 25 +++++++++++++++---- .../SourceFiles/history/history_service.cpp | 25 +++++++++++-------- .../SourceFiles/history/history_widget.cpp | 2 ++ .../window/notifications_manager_default.cpp | 3 +++ 10 files changed, 62 insertions(+), 20 deletions(-) diff --git a/Telegram/SourceFiles/export/data/export_data_types.cpp b/Telegram/SourceFiles/export/data/export_data_types.cpp index 83b6419cc..ee68b0c91 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.cpp +++ b/Telegram/SourceFiles/export/data/export_data_types.cpp @@ -1153,6 +1153,9 @@ Message ParseMessage( result.replyToPeerId = data.vreply_to_peer_id() ? ParsePeerId(*data.vreply_to_peer_id()) : 0; + if (result.replyToPeerId == result.peerId) { + result.replyToPeerId = 0; + } }); } } @@ -1712,7 +1715,7 @@ MessagesSlice ParseMessagesSlice( MessagesSlice AdjustMigrateMessageIds(MessagesSlice slice) { for (auto &message : slice.list) { message.id += kMigratedMessagesIdShift; - if (message.replyToMsgId) { + if (message.replyToMsgId && !message.replyToPeerId) { message.replyToMsgId += kMigratedMessagesIdShift; } } diff --git a/Telegram/SourceFiles/export/output/export_output_html.cpp b/Telegram/SourceFiles/export/output/export_output_html.cpp index 281e17192..0744fd97d 100644 --- a/Telegram/SourceFiles/export/output/export_output_html.cpp +++ b/Telegram/SourceFiles/export/output/export_output_html.cpp @@ -1192,8 +1192,12 @@ auto HtmlWriter::Wrap::pushMessage( } if (message.replyToMsgId) { block.append(pushDiv("reply_to details")); - block.append("In reply to "); - block.append(wrapReplyToLink("this message")); + if (message.replyToPeerId) { + block.append("In reply to a message in another chat"); + } else { + block.append("In reply to "); + block.append(wrapReplyToLink("this message")); + } block.append(popTag()); } diff --git a/Telegram/SourceFiles/export/output/export_output_json.cpp b/Telegram/SourceFiles/export/output/export_output_json.cpp index 1710332a2..f1de9d524 100644 --- a/Telegram/SourceFiles/export/output/export_output_json.cpp +++ b/Telegram/SourceFiles/export/output/export_output_json.cpp @@ -303,6 +303,9 @@ QByteArray SerializeMessage( const QByteArray &label = "reply_to_message_id") { if (message.replyToMsgId) { push(label, message.replyToMsgId); + if (message.replyToPeerId) { + push("reply_to_peer_id", message.replyToPeerId); + } } }; const auto pushUserNames = [&]( diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index c6d7c5118..5c5aaa819 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -957,7 +957,7 @@ not_null HistoryItem::Create( data.vid().v, data.vflags().v, clientFlags, - 0, // #TODO replies data.vreply_to() + MsgId(0), // No need to pass reply_to data here. data.vvia_bot_id().value_or_empty(), data.vdate().v, data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)); diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index ad78d252a..70c76b279 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -204,7 +204,9 @@ bool HistoryMessageReply::updateData( } if (!replyToMsg) { replyToMsg = holder->history()->owner().message( - holder->channelId(), + (replyToPeerId + ? peerToChannel(replyToPeerId) + : holder->channelId()), replyToMsgId); if (replyToMsg) { if (replyToMsg->isEmpty()) { diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 2125c9f14..79a2b34cc 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -105,6 +105,7 @@ struct HistoryMessageReply : public RuntimeComponentmatch([&](const MTPDmessageReplyHeader &data) { - // #TODO replies reply_to_peer_id. + if (const auto peer = data.vreply_to_peer_id()) { + config.replyToPeer = peerFromMTP(*peer); + if (config.replyToPeer == history->peer->id) { + config.replyToPeer = 0; + } + } config.replyTo = data.vreply_to_msg_id().v; config.replyToTop = data.vreply_to_top_id().value_or( config.replyTo); @@ -514,9 +520,14 @@ HistoryMessage::HistoryMessage( if (const auto reply = data.vreply_to()) { reply->match([&](const MTPDmessageReplyHeader &data) { - config.replyTo = data.vreply_to_msg_id().v; - config.replyToTop = data.vreply_to_top_id().value_or( - config.replyTo); + const auto peer = data.vreply_to_peer_id() + ? peerFromMTP(*data.vreply_to_peer_id()) + : history->peer->id; + if (!peer || peer == history->peer->id) { + config.replyTo = data.vreply_to_msg_id().v; + config.replyToTop = data.vreply_to_top_id().value_or( + config.replyTo); + } }); } @@ -911,11 +922,15 @@ void HistoryMessage::createComponents(const CreateConfig &config) { UpdateComponents(mask); if (const auto reply = Get()) { + reply->replyToPeerId = config.replyToPeer; reply->replyToMsgId = config.replyTo; reply->replyToMsgTop = isScheduled() ? 0 : config.replyToTop; if (!reply->updateData(this)) { history()->session().api().requestMessageData( - history()->peer->asChannel(), + (peerIsChannel(reply->replyToPeerId) + ? history()->owner().channel( + peerToChannel(reply->replyToPeerId)).get() + : history()->peer->asChannel()), reply->replyToMsgId, HistoryDependentItemCallback(this)); } diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 6efd3b6c0..45ef389be 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -681,17 +681,22 @@ void HistoryService::createFromMtp(const MTPDmessageService &message) { Get()->amount = HistoryView::FillAmountAndCurrency(amount, currency); } if (const auto replyTo = message.vreply_to()) { - if (message.vaction().type() == mtpc_messageActionPinMessage) { - UpdateComponents(HistoryServicePinned::Bit()); - } replyTo->match([&](const MTPDmessageReplyHeader &data) { - if (const auto dependent = GetDependentData()) { - dependent->msgId = data.vreply_to_msg_id().v; - if (!updateDependent()) { - history()->session().api().requestMessageData( - history()->peer->asChannel(), - dependent->msgId, - HistoryDependentItemCallback(this)); + const auto peer = data.vreply_to_peer_id() + ? peerFromMTP(*data.vreply_to_peer_id()) + : history()->peer->id; + if (!peer || peer == history()->peer->id) { + if (message.vaction().type() == mtpc_messageActionPinMessage) { + UpdateComponents(HistoryServicePinned::Bit()); + } + if (const auto dependent = GetDependentData()) { + dependent->msgId = data.vreply_to_msg_id().v; + if (!updateDependent()) { + history()->session().api().requestMessageData( + history()->peer->asChannel(), + dependent->msgId, + HistoryDependentItemCallback(this)); + } } } }); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index ff3a3d805..8a38f89bf 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1794,6 +1794,8 @@ void HistoryWidget::showHistory( updateNotifyControls(); session().data().requestNotifySettings(_peer); refreshSilentToggle(); + } else if (_peer->isRepliesChat()) { + updateNotifyControls(); } refreshScheduledToggle(); diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index b159f6c6a..83d3aea6c 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -737,6 +737,9 @@ void Notification::updateNotifyDisplay() { if (_fromScheduled && _history->peer->isSelf()) { Ui::EmptyUserpic::PaintSavedMessages(p, st::notifyPhotoPos.x(), st::notifyPhotoPos.y(), width(), st::notifyPhotoSize); _userpicLoaded = true; + } else if (_history->peer->isRepliesChat()) { + Ui::EmptyUserpic::PaintRepliesMessages(p, st::notifyPhotoPos.x(), st::notifyPhotoPos.y(), width(), st::notifyPhotoSize); + _userpicLoaded = true; } else { _userpicView = _history->peer->createUserpicView(); _history->peer->loadUserpic();