From dd8fdfc3d43eb76a2b0e17a6bf93f641c42899bb Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 2 Jun 2025 18:19:16 +0400 Subject: [PATCH] Allow forwarding polls to monoforums. --- .../data/data_chat_participant_status.cpp | 6 --- Telegram/SourceFiles/data/data_peer.cpp | 2 + .../SourceFiles/data/data_peer_values.cpp | 6 --- .../dialogs/dialogs_inner_widget.cpp | 41 +++++++++++-------- .../dialogs/dialogs_inner_widget.h | 6 ++- .../SourceFiles/dialogs/dialogs_widget.cpp | 15 ++++++- .../dialogs/ui/dialogs_message_view.cpp | 9 +++- .../SourceFiles/history/history_widget.cpp | 7 +++- .../view/history_view_subsection_tabs.cpp | 1 + 9 files changed, 60 insertions(+), 33 deletions(-) diff --git a/Telegram/SourceFiles/data/data_chat_participant_status.cpp b/Telegram/SourceFiles/data/data_chat_participant_status.cpp index b3e318d076..2a85f44d13 100644 --- a/Telegram/SourceFiles/data/data_chat_participant_status.cpp +++ b/Telegram/SourceFiles/data/data_chat_participant_status.cpp @@ -156,12 +156,6 @@ bool CanSendAnyOf( } return false; } else if (const auto channel = peer->asChannel()) { - if (channel->isMonoforum()) { - rights &= ~ChatRestriction::SendPolls; - if (!rights) { - return false; - } - } using Flag = ChannelDataFlag; const auto allowed = channel->amIn() || ((channel->flags() & Flag::HasLink) diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 8f639faf0f..7359ef5af4 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -668,6 +668,8 @@ bool PeerData::canCreatePolls() const { && !user->isSupport() && !user->isRepliesChat() && !user->isVerifyCodes()); + } else if (isMonoforum()) { + return false; } return Data::CanSend(this, ChatRestriction::SendPolls); } diff --git a/Telegram/SourceFiles/data/data_peer_values.cpp b/Telegram/SourceFiles/data/data_peer_values.cpp index 1d65c3b2ec..0c435d5347 100644 --- a/Telegram/SourceFiles/data/data_peer_values.cpp +++ b/Telegram/SourceFiles/data/data_peer_values.cpp @@ -274,12 +274,6 @@ inline auto DefaultRestrictionValue( | Flag::Forbidden | Flag::Creator | Flag::Broadcast; - if (channel->isMonoforum()) { - rights &= ~ChatRestriction::SendPolls; - if (!rights) { - return rpl::single(false); - } - } return rpl::combine( PeerFlagsValue(channel, mask), AdminRightValue( diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 6eb211320a..312c830d1e 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -1464,11 +1464,7 @@ bool InnerWidget::isRowActive( } return false; } else if (const auto sublist = entry.key.sublist()) { - if (!sublist->parentChat()) { - // In case we're viewing a Saved Messages sublist, - // we want to highlight the Saved Messages row as active. - return key.history() && key.peer()->isSelf(); - } + return key.history() && key.history() == sublist->owningHistory(); } return false; } @@ -1909,9 +1905,14 @@ RowDescriptor InnerWidget::computeChatPreviewRow() const { auto result = computeChosenRow(); if (const auto peer = result.key.peer()) { const auto topicId = _pressedTopicJump - ? _pressedTopicJumpRootId // #TODO monoforums - : 0; - if (const auto topic = peer->forumTopicFor(topicId)) { + ? _pressedTopicJumpRootId + : MsgId(); + const auto sublistPeerId = _pressedTopicJump + ? _pressedSublistJumpPeerId + : PeerId(); + if (const auto sublist = peer->monoforumSublistFor(sublistPeerId)) { + return { sublist, FullMsgId() }; + } else if (const auto topic = peer->forumTopicFor(topicId)) { return { topic, FullMsgId() }; } } @@ -2422,6 +2423,7 @@ void InnerWidget::mousePressReleased( auto collapsedPressed = _collapsedPressed; setCollapsedPressed(-1); const auto pressedTopicRootId = _pressedTopicJumpRootId; + const auto pressedSublistPeerId = _pressedSublistJumpPeerId; const auto pressedTopicJump = _pressedTopicJump; const auto pressedRightButton = _pressedRightButton; auto pressed = _pressed; @@ -2505,7 +2507,10 @@ void InnerWidget::mousePressReleased( } else if (pressedRightButton && peerSearchPressed >= 0) { showSponsoredMenu(peerSearchPressed, globalPosition); } else { - chooseRow(modifiers, pressedTopicRootId); + chooseRow( + modifiers, + pressedTopicRootId, + pressedSublistPeerId); } } } @@ -2557,6 +2562,9 @@ void InnerWidget::setPressed( : nullptr; const auto item = history ? history->chatListMessage() : nullptr; _pressedTopicJumpRootId = item ? item->topicRootId() : MsgId(); + _pressedSublistJumpPeerId = item + ? item->sublistPeerId() + : PeerId(); } } } @@ -2603,6 +2611,9 @@ void InnerWidget::setFilteredPressed( : nullptr; const auto item = history ? history->chatListMessage() : nullptr; _pressedTopicJumpRootId = item ? item->topicRootId() : MsgId(); + _pressedSublistJumpPeerId = item + ? item->sublistPeerId() + : PeerId(); } } } @@ -4763,7 +4774,8 @@ bool InnerWidget::isUserpicPressOnWide() const { bool InnerWidget::chooseRow( Qt::KeyboardModifiers modifiers, - MsgId pressedTopicRootId) { + MsgId pressedTopicRootId, + PeerId pressedSublistPeerId) { if (chooseHashtag()) { return true; } else if (_selectedMorePosts) { @@ -4805,12 +4817,9 @@ bool InnerWidget::chooseRow( if (!chosen.message.fullId) { if (const auto history = chosen.key.history()) { if (history->peer->forum()) { - if (pressedTopicRootId) { - chosen.message.fullId = { - history->peer->id, - pressedTopicRootId, - }; - } + chosen.topicJumpRootId = pressedTopicRootId; + } else if (history->peer->amMonoforumAdmin()) { + chosen.sublistJumpPeerId = pressedSublistPeerId; } } } diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index d2a21405cb..c3c4a6b033 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -84,6 +84,8 @@ enum class ChatTypeFilter : uchar; struct ChosenRow { Key key; Data::MessagePosition message; + MsgId topicJumpRootId; + PeerId sublistJumpPeerId; QByteArray sponsoredRandomId; bool userpicClick : 1 = false; bool filteredRow : 1 = false; @@ -163,7 +165,8 @@ public: void chatPreviewShown(bool shown, RowDescriptor row = {}); bool chooseRow( Qt::KeyboardModifiers modifiers = {}, - MsgId pressedTopicRootId = {}); + MsgId pressedTopicRootId = {}, + PeerId pressedSublistPeerId = {}); void scrollToEntry(const RowDescriptor &entry); @@ -543,6 +546,7 @@ private: Row *_selected = nullptr; Row *_pressed = nullptr; MsgId _pressedTopicJumpRootId; + PeerId _pressedSublistJumpPeerId; bool _selectedTopicJump = false; bool _pressedTopicJump = false; diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 6b6227b9a3..ce0912c934 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -860,7 +860,10 @@ void Widget::chosenRow(const ChosenRow &row) { const auto history = row.key.history(); const auto topicJump = history - ? history->peer->forumTopicFor(row.message.fullId.msg) + ? history->peer->forumTopicFor(row.topicJumpRootId) + : nullptr; + const auto sublistJump = history + ? history->peer->monoforumSublistFor(row.sublistJumpPeerId) : nullptr; if (topicJump) { @@ -880,6 +883,16 @@ void Widget::chosenRow(const ChosenRow &row) { Window::SectionShow::Way::ClearStack); } return; + } else if (sublistJump) { + if (row.newWindow) { + controller()->showInNewWindow(Window::SeparateId(sublistJump)); + } else { + controller()->showThread( + sublistJump, + ShowAtUnreadMsgId, + Window::SectionShow::Way::ClearStack); + } + return; } else if (const auto topic = row.key.topic()) { auto params = Window::SectionShow( Window::SectionShow::Way::ClearStack); diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.cpp index 87fd7232cb..955377480f 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_message_view.cpp @@ -267,11 +267,18 @@ int MessageView::countWidth() const { auto result = 0; if (!_senderCache.isEmpty()) { result += _senderCache.maxWidth(); - if (!_imagesCache.empty()) { + if (!_imagesCache.empty() && !_leftIcon) { result += st::dialogsMiniPreviewSkip + st::dialogsMiniPreviewRight; } } + if (_leftIcon) { + const auto w = _leftIcon->icon.icon.width(); + result += w + + (_imagesCache.empty() + ? _leftIcon->skipText + : _leftIcon->skipMedia); + } if (!_imagesCache.empty()) { result += (_imagesCache.size() * (st::dialogsMiniPreview + st::dialogsMiniPreviewSkip)) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 7d41300c38..f7367cba1b 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2126,7 +2126,10 @@ void HistoryWidget::setupDirectMessageButton() { }, _directMessage->lifetime()); _directMessage->setClickedCallback([=] { if (const auto channel = _peer ? _peer->asChannel() : nullptr) { - if (const auto monoforum = channel->monoforumLink()) { + if (channel->invitePeekExpires()) { + controller()->showToast( + tr::lng_channel_invite_private(tr::now)); + } else if (const auto monoforum = channel->monoforumLink()) { controller()->showPeerHistory( monoforum, Window::SectionShow::Way::Forward); @@ -6038,7 +6041,7 @@ bool HistoryWidget::showSendingFilesError( return true; } -MsgId HistoryWidget::resolveReplyToTopicRootId() { // #TODO monoforums +MsgId HistoryWidget::resolveReplyToTopicRootId() { Expects(_peer != nullptr); const auto replyToInfo = replyTo(); diff --git a/Telegram/SourceFiles/history/view/history_view_subsection_tabs.cpp b/Telegram/SourceFiles/history/view/history_view_subsection_tabs.cpp index dec9438836..b69a8604b5 100644 --- a/Telegram/SourceFiles/history/view/history_view_subsection_tabs.cpp +++ b/Telegram/SourceFiles/history/view/history_view_subsection_tabs.cpp @@ -660,6 +660,7 @@ bool SubsectionTabs::switchTo( } _shadow->setParent(parent); _shadow->show(); + _refreshed.fire({}); return true; }