diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index d3b2bec0d..94092403c 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -689,7 +689,7 @@ QString ApiWrap::exportDirectMessageLink( auto linkItemId = item->id; auto linkCommentId = MsgId(); auto linkThreadId = MsgId(); - //auto linkThreadIsTopic = false; + auto linkThreadIsTopic = false; if (inRepliesContext) { if (const auto rootId = item->replyToTop()) { const auto root = item->history()->owner().message( @@ -711,7 +711,7 @@ QString ApiWrap::exportDirectMessageLink( } else { // Reply in a thread, maybe comment in a private channel. linkThreadId = rootId; - //linkThreadIsTopic = (item->topicRootId() == rootId); + linkThreadIsTopic = (item->topicRootId() == rootId); } } } @@ -723,7 +723,7 @@ QString ApiWrap::exportDirectMessageLink( + '/' + (linkCommentId ? (post + "?comment=" + QString::number(linkCommentId.bare)) - : (linkThreadId/* && !linkThreadIsTopic*/) + : (linkThreadId && !linkThreadIsTopic) ? (post + "?thread=" + QString::number(linkThreadId.bare)) : linkThreadId ? (QString::number(linkThreadId.bare) + '/' + post) diff --git a/Telegram/SourceFiles/data/data_forum_topic.h b/Telegram/SourceFiles/data/data_forum_topic.h index 9ec4a971a..7720981e4 100644 --- a/Telegram/SourceFiles/data/data_forum_topic.h +++ b/Telegram/SourceFiles/data/data_forum_topic.h @@ -51,6 +51,8 @@ class Forum; class ForumTopic final : public Thread { public: + static constexpr auto kGeneralId = 1; + ForumTopic(not_null forum, MsgId rootId); ~ForumTopic(); @@ -58,6 +60,10 @@ public: return history(); } + [[nodiscard]] bool isGeneral() const { + return (_rootId == kGeneralId); + } + [[nodiscard]] std::shared_ptr replies() const; [[nodiscard]] not_null channel() const; [[nodiscard]] not_null history() const; diff --git a/Telegram/SourceFiles/data/data_replies_list.cpp b/Telegram/SourceFiles/data/data_replies_list.cpp index f28152393..a1a159edc 100644 --- a/Telegram/SourceFiles/data/data_replies_list.cpp +++ b/Telegram/SourceFiles/data/data_replies_list.cpp @@ -304,7 +304,7 @@ void RepliesList::injectRootMessage(not_null viewer) { return; } const auto root = lookupRoot(); - if (!root || root->topicRootId()) { + if (!root || root->topicRootId() != Data::ForumTopic::kGeneralId) { return; } injectRootDivider(root, slice); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 50744ca93..8f834c83a 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2088,14 +2088,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { const auto itemId = item->fullId(); const auto canReply = [&] { const auto peer = item->history()->peer; - if (const auto forum = peer->forum()) { - const auto topicRootId = item->topicRootId(); - const auto topic = item->topic(); - return topic - ? topic->canWrite() - : peer->canWrite(!topicRootId); - } - return peer->canWrite(); + const auto topic = item->topic(); + return topic ? topic->canWrite() : peer->canWrite(); }(); if (canReply) { _menu->addAction(tr::lng_context_reply_msg(tr::now), [=] { diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 44b0df858..b9d939634 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -231,7 +231,8 @@ MsgId LookupReplyToTop(HistoryItem *replyTo) { } bool LookupReplyIsTopicPost(HistoryItem *replyTo) { - return replyTo && (replyTo->topicRootId() != 0); + return replyTo + && (replyTo->topicRootId() != Data::ForumTopic::kGeneralId); } MTPMessageReplyHeader NewMessageReplyHeader(const Api::SendAction &action) { @@ -1502,7 +1503,7 @@ MsgId HistoryMessage::topicRootId() const { ; reply && reply->topicPost) { return reply->replyToTop(); } - return 0; + return Data::ForumTopic::kGeneralId; } void HistoryMessage::setText(const TextWithEntities &textWithEntities) { diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 5ccde9939..6e26c53a3 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -1344,7 +1344,7 @@ MsgId HistoryService::topicRootId() const { } else if (Has()) { return id; } - return 0; + return Data::ForumTopic::kGeneralId; } void HistoryService::setReplyFields( diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 15f5ffead..1132f3313 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -6721,7 +6721,7 @@ void HistoryWidget::processReply() { return processCancel(); } else if (const auto forum = _peer->forum()) { const auto topicRootId = _processingReplyItem->topicRootId(); - if (!topicRootId || forum->topicDeleted(topicRootId)) { + if (forum->topicDeleted(topicRootId)) { return processCancel(); } else if (const auto topic = forum->topicFor(topicRootId)) { if (!topic->canWrite()) { diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 1b3931950..1b0746a83 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -686,7 +686,7 @@ auto Element::contextDependentServiceText() -> TextWithLinks { } const auto peerId = item->history()->peer->id; const auto topicRootId = item->topicRootId(); - if (!topicRootId || !peerIsChannel(peerId)) { + if (!peerIsChannel(peerId)) { return {}; } const auto from = item->from(); diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index a822c5067..dcc5d41a5 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -2711,13 +2711,8 @@ bool Message::displayFastReply() const { const auto canWrite = [&] { const auto item = data(); const auto peer = item->history()->peer; - if (peer->isForum()) { - const auto topic = item->topic(); - return topic - ? topic->canWrite() - : peer->canWrite(!item->topicRootId()); - } - return peer->canWrite(); + const auto topic = item->topic(); + return topic ? topic->canWrite() : peer->canWrite(); }; return hasFastReply() diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index efffd00c6..58c28b845 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -1467,7 +1467,11 @@ void RepliesWidget::refreshTopBarActiveChat() { MsgId RepliesWidget::replyToId() const { const auto custom = _composeControls->replyingToMessage().msg; - return custom ? custom : _rootId; + return custom + ? custom + : (_rootId == Data::ForumTopic::kGeneralId) + ? MsgId() + : _rootId; } void RepliesWidget::refreshUnreadCountBadge(std::optional count) { diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 993b50543..a32bf38fa 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -4166,9 +4166,9 @@ void OverlayWidget::setContext( not_null> context) { if (const auto item = std::get_if(&context)) { _message = item->item; - _topicRootId = item->topicRootId; _history = _message->history(); _peer = _history->peer; + _topicRootId = _peer->isForum() ? item->topicRootId : MsgId(); } else if (const auto peer = std::get_if>(&context)) { _peer = *peer; _history = _peer->owner().history(_peer); diff --git a/Telegram/SourceFiles/storage/file_upload.cpp b/Telegram/SourceFiles/storage/file_upload.cpp index 160314022..a30b6a495 100644 --- a/Telegram/SourceFiles/storage/file_upload.cpp +++ b/Telegram/SourceFiles/storage/file_upload.cpp @@ -257,10 +257,12 @@ void Uploader::sendProgressUpdate( const auto history = item->history(); auto &manager = _api->session().sendProgressManager(); manager.update(history, type, progress); - if (const auto replyTo = item->topicRootId()) { + if (const auto replyTo = item->replyToTop()) { if (history->peer->isMegagroup()) { manager.update(history, replyTo, type, progress); } + } else if (history->peer->isForum()) { + manager.update(history, item->topicRootId(), type, progress); } _api->session().data().requestItemRepaint(item); }