diff --git a/Telegram/SourceFiles/boxes/pin_messages_box.cpp b/Telegram/SourceFiles/boxes/pin_messages_box.cpp index 07d041a7d1..9ba027e20c 100644 --- a/Telegram/SourceFiles/boxes/pin_messages_box.cpp +++ b/Telegram/SourceFiles/boxes/pin_messages_box.cpp @@ -83,7 +83,9 @@ void PinMessageBox( object->setAllowTextLines(); state->pinForPeer = Ui::MakeWeak(object.data()); return object; - } else if (!pinningOld && (peer->isChat() || peer->isMegagroup())) { + } else if (!pinningOld + && (peer->isChat() || peer->isMegagroup()) + && !peer->isMonoforum()) { auto object = object_ptr( box, tr::lng_pinned_notify(tr::now), diff --git a/Telegram/SourceFiles/history/view/history_view_chat_section.cpp b/Telegram/SourceFiles/history/view/history_view_chat_section.cpp index 39afe08693..9d2b01041f 100644 --- a/Telegram/SourceFiles/history/view/history_view_chat_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_chat_section.cpp @@ -151,12 +151,16 @@ void ChatMemento::setFromTopic(not_null topic) { } -Data::ForumTopic *ChatMemento::topicForRemoveRequests() const {// #TODO monoforums +Data::ForumTopic *ChatMemento::topicForRemoveRequests() const { return _id.repliesRootId ? _id.history->peer->forumTopicFor(_id.repliesRootId) : nullptr; } +Data::SavedSublist *ChatMemento::sublistForRemoveRequests() const { + return _id.sublist; +} + void ChatMemento::setReadInformation( MsgId inboxReadTillId, int unreadCount, @@ -656,7 +660,8 @@ void ChatWidget::subscribeToPinnedMessages() { ) | rpl::start_with_next([=](const Data::EntryUpdate &update) { if (_pinnedTracker && (update.flags & EntryUpdateFlag::HasPinnedMessages) - && (_topic == update.entry.get())) { + && (_topic == update.entry.get() + || _sublist == update.entry.get())) { checkPinnedBarState(); } }, lifetime()); @@ -1833,7 +1838,7 @@ void ChatWidget::refreshUnreadCountBadge(std::optional count) { } void ChatWidget::updatePinnedViewer() { - if (_scroll->isHidden() || !_topic || !_pinnedTracker) { + if (_scroll->isHidden() || (!_topic && !_sublist) || !_pinnedTracker) { return; } const auto visibleBottom = _scroll->scrollTop() + _scroll->height(); @@ -1866,7 +1871,7 @@ void ChatWidget::updatePinnedViewer() { void ChatWidget::checkLastPinnedClickedIdReset( int wasScrollTop, int nowScrollTop) { - if (_scroll->isHidden() || !_topic) { + if (_scroll->isHidden() || (!_topic && !_sublist)) { return; } if (wasScrollTop < nowScrollTop && _pinnedClickedId) { @@ -1948,15 +1953,16 @@ void ChatWidget::setupTranslateBar() { } void ChatWidget::setupPinnedTracker() { - Expects(_topic != nullptr); + Expects(_topic || _sublist); - _pinnedTracker = std::make_unique(_topic); + const auto thread = _topic ? (Data::Thread*)_topic : _sublist; + _pinnedTracker = std::make_unique(thread); _pinnedBar = nullptr; SharedMediaViewer( - &_topic->session(), + &session(), Storage::SharedMediaKey( - _topic->channel()->id, + _peer->id, _repliesRootId, _monoforumPeerId, Storage::SharedMediaType::Pinned, @@ -1966,7 +1972,7 @@ void ChatWidget::setupPinnedTracker() { ) | rpl::filter([=](const SparseIdsSlice &result) { return result.fullCount().has_value(); }) | rpl::start_with_next([=](const SparseIdsSlice &result) { - _topic->setHasPinnedMessages(*result.fullCount() != 0); + thread->setHasPinnedMessages(*result.fullCount() != 0); if (result.skippedAfter() == 0) { auto &settings = _history->session().settings(); const auto peerId = _peer->id; @@ -1985,7 +1991,7 @@ void ChatWidget::setupPinnedTracker() { } } checkPinnedBarState(); - }, _topicLifetime); + }, lifetime()); } void ChatWidget::checkPinnedBarState() { @@ -2138,8 +2144,9 @@ void ChatWidget::refreshPinnedBarButton(bool many, HistoryItem *item) { if (!id.message) { return; } + const auto thread = _topic ? (Data::Thread*)_topic : _sublist; controller()->showSection( - std::make_shared(_topic, id.message.msg)); + std::make_shared(thread, id.message.msg)); }; const auto context = [copy = _inner](FullMsgId itemId) { if (const auto raw = copy.data()) { @@ -2591,6 +2598,7 @@ void ChatWidget::subscribeToSublist() { }, lifetime()); unreadCountUpdated(); + subscribeToPinnedMessages(); } void ChatWidget::unreadCountUpdated() { @@ -2782,7 +2790,10 @@ void ChatWidget::updateInnerVisibleArea() { } void ChatWidget::updatePinnedVisibility() { - if (!_loaded || !_repliesRootId) { + if (_sublist) { + setPinnedVisibility(true); + return; + } else if (!_loaded || !_repliesRootId) { return; } else if (!_topic && (!_repliesRoot || _repliesRoot->isEmpty())) { setPinnedVisibility(!_repliesRoot); @@ -2803,7 +2814,10 @@ void ChatWidget::updatePinnedVisibility() { } void ChatWidget::setPinnedVisibility(bool shown) { - if (animatingShow() || !_repliesRootId) { + if (animatingShow()) { + } else if (_sublist) { + _repliesRootVisible = shown; + } else if (!_repliesRootId) { return; } else if (!_topic) { if (!_repliesRootViewInitScheduled) { diff --git a/Telegram/SourceFiles/history/view/history_view_chat_section.h b/Telegram/SourceFiles/history/view/history_view_chat_section.h index 593553ce25..a92c17ab3a 100644 --- a/Telegram/SourceFiles/history/view/history_view_chat_section.h +++ b/Telegram/SourceFiles/history/view/history_view_chat_section.h @@ -503,6 +503,7 @@ public: } Data::ForumTopic *topicForRemoveRequests() const override; + Data::SavedSublist *sublistForRemoveRequests() const override; [[nodiscard]] not_null list() { return &_list; diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index b28099fe58..d156b8fc73 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -756,8 +756,12 @@ bool AddPinMessageAction( return false; } const auto topic = item->topic(); + const auto sublist = item->savedSublist(); if (context != Context::History && context != Context::Pinned) { - if (context != Context::Replies || !topic) { + if ((context != Context::Replies || !topic) + && (context != Context::Monoforum + || !sublist + || !item->history()->amMonoforumAdmin())) { return false; } } diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp index cf82e31e2b..446d957617 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp @@ -90,6 +90,10 @@ Data::ForumTopic *PinnedMemento::topicForRemoveRequests() const { return _thread->asTopic(); } +Data::SavedSublist *PinnedMemento::sublistForRemoveRequests() const { + return _thread->asSublist(); +} + PinnedWidget::PinnedWidget( QWidget *parent, not_null controller, diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.h b/Telegram/SourceFiles/history/view/history_view_pinned_section.h index 75956e403d..be7a515d72 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.h +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.h @@ -225,6 +225,7 @@ public: } Data::ForumTopic *topicForRemoveRequests() const override; + Data::SavedSublist *sublistForRemoveRequests() const override; private: const not_null _thread; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 587172d8f6..65001c5cdb 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -223,6 +223,8 @@ StackItemSection::StackItemSection( rpl::producer<> StackItemSection::sectionRemoveRequests() const { if (const auto topic = _memento->topicForRemoveRequests()) { return rpl::merge(_memento->removeRequests(), topic->destroyed()); + } else if (const auto sublist = _memento->sublistForRemoveRequests()) { + return rpl::merge(_memento->removeRequests(), sublist->destroyed()); } return _memento->removeRequests(); } diff --git a/Telegram/SourceFiles/window/section_memento.h b/Telegram/SourceFiles/window/section_memento.h index e794d024eb..d139928a99 100644 --- a/Telegram/SourceFiles/window/section_memento.h +++ b/Telegram/SourceFiles/window/section_memento.h @@ -13,6 +13,7 @@ class LayerWidget; namespace Data { class ForumTopic; +class SavedSublist; } // namespace Data namespace Window { @@ -41,6 +42,10 @@ public: [[nodiscard]] virtual Data::ForumTopic *topicForRemoveRequests() const { return nullptr; } + [[nodiscard]] virtual auto sublistForRemoveRequests() const + -> Data::SavedSublist* { + return nullptr; + } [[nodiscard]] virtual rpl::producer<> removeRequests() const { return rpl::never<>(); }