diff --git a/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp index a3bff741f1..bd33dd53aa 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp @@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/emoji_fly_animation.h" #include "ui/abstract_button.h" #include "ui/vertical_list.h" -#include "data/data_channel.h" #include "data/data_document.h" #include "data/data_forum.h" #include "data/data_forum_icons.h" @@ -515,8 +514,7 @@ void EditForumTopicBox( } const auto create = [=] { - const auto channel = forum->peer->asChannel(); - if (!channel || !channel->isForum()) { + if (!forum->peer->isForum()) { box->closeBox(); return; } else if (title->getLastText().trimmed().isEmpty()) { @@ -527,7 +525,7 @@ void EditForumTopicBox( controller->showSection( std::make_shared(ChatViewId{ .history = forum, - .repliesRootId = channel->forum()->reserveCreatingId( + .repliesRootId = forum->peer->forum()->reserveCreatingId( title->getLastText().trimmed(), state->defaultIcon.current().colorId, state->iconId.current()), diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 201705a6f6..6deadc6de9 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -1135,7 +1135,7 @@ void Controller::fillForumButton() { _forumSavedValue = _peer->isForum(); _forumTabsSavedValue = !_peer->isChannel() || !_peer->isForum() - || _peer->asChannel()->useSubsectionTabs(); + || _peer->useSubsectionTabs(); const auto changes = std::make_shared>(); const auto label = [=] { diff --git a/Telegram/SourceFiles/data/data_thread.cpp b/Telegram/SourceFiles/data/data_thread.cpp index 47a8f22232..cf35b979e4 100644 --- a/Telegram/SourceFiles/data/data_thread.cpp +++ b/Telegram/SourceFiles/data/data_thread.cpp @@ -206,11 +206,11 @@ void Thread::setHasPinnedMessages(bool has) { } void Thread::saveMeAsActiveSubsectionThread() { - if (const auto channel = owningHistory()->peer->asChannel()) { - if (channel->useSubsectionTabs()) { - if (const auto forum = channel->forum()) { - forum->saveActiveSubsectionThread(this); - } else if (const auto monoforum = channel->monoforum()) { + if (const auto peer = owningHistory()->peer; peer->useSubsectionTabs()) { + if (const auto forum = peer->forum()) { + forum->saveActiveSubsectionThread(this); + } else if (const auto channel = peer->asChannel()) { + if (const auto monoforum = channel->monoforum()) { monoforum->saveActiveSubsectionThread(this); } } diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp index f0cac38de6..1c7ddbe4d1 100644 --- a/Telegram/SourceFiles/data/data_user.cpp +++ b/Telegram/SourceFiles/data/data_user.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_sensitive_content.h" #include "api/api_statistics.h" #include "base/timer_rpl.h" +#include "core/application.h" #include "storage/localstorage.h" #include "storage/storage_account.h" #include "storage/storage_user_photos.h" @@ -34,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_peer_photo.h" #include "apiwrap.h" #include "lang/lang_keys.h" +#include "window/notifications_manager.h" #include "styles/style_chat.h" namespace { @@ -496,10 +498,10 @@ void UserData::setAccessHash(uint64 accessHash) { void UserData::setFlags(UserDataFlags which) { if (!isBot()) { - which &= ~UserDataFlag::Forum; + which &= ~Flag::Forum; } const auto diff = flags() ^ which; - if (diff & UserDataFlag::Deleted) { + if (diff & Flag::Deleted) { invalidateEmptyUserpic(); } // Let Data::Forum live till the end of _flags.set. @@ -515,8 +517,20 @@ void UserData::setFlags(UserDataFlags which) { info->ensureForum(this); } } - _flags.set((flags() & UserDataFlag::Self) - | (which & ~UserDataFlag::Self)); + _flags.set((flags() & Flag::Self) | (which & ~Flag::Self)); + if (diff & Flag::Forum) { + if (const auto history = this->owner().historyLoaded(this)) { + if (diff & Flag::Forum) { + Core::App().notifications().clearFromHistory(history); + history->updateChatListEntryHeight(); + if (history->inChatList()) { + if (const auto forum = this->forum()) { + forum->preloadTopics(); + } + } + } + } + } if (const auto raw = takenForum.get()) { owner().forumIcons().clearUserpicsReset(raw); } diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index eb6ca5f2c3..23c46e2c6c 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -3171,7 +3171,7 @@ void History::tryMarkForumIntervalRead( MsgId wasInboxReadBefore, MsgId nowInboxReadBefore) { if (!isForum() - || !peer->asChannel()->useSubsectionTabs() + || !peer->useSubsectionTabs() || (nowInboxReadBefore <= wasInboxReadBefore)) { return; } else if (loadedAtBottom() && nowInboxReadBefore >= minMsgId()) { @@ -3477,10 +3477,8 @@ bool History::suggestDraftAllowed() const { bool History::hasForumThreadBars() const { if (amMonoforumAdmin()) { return true; - } else if (const auto channel = peer->asChannel()) { - return channel->forum() && channel->useSubsectionTabs(); } - return false; + return peer->useSubsectionTabs(); } void History::forumTabsChanged(bool forumTabs) { diff --git a/Telegram/SourceFiles/history/view/history_view_chat_section.cpp b/Telegram/SourceFiles/history/view/history_view_chat_section.cpp index 5fecbc4a56..5a97027d62 100644 --- a/Telegram/SourceFiles/history/view/history_view_chat_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_chat_section.cpp @@ -1600,7 +1600,7 @@ void ChatWidget::validateSubsectionTabs() { } void ChatWidget::refreshJoinGroupButton() { - if (!_repliesRootId) { + if (!_repliesRootId || !_peer->isChannel()) { return; } const auto set = [&](std::unique_ptr button) { diff --git a/Telegram/SourceFiles/history/view/history_view_requests_bar.cpp b/Telegram/SourceFiles/history/view/history_view_requests_bar.cpp index d0ddb48baf..91f098453e 100644 --- a/Telegram/SourceFiles/history/view/history_view_requests_bar.cpp +++ b/Telegram/SourceFiles/history/view/history_view_requests_bar.cpp @@ -111,7 +111,7 @@ rpl::producer RequestsBarContentByPeer( const auto pushNext = [=](bool now = false) { if ((!showInForum && peer->isForum() - && !peer->asChannel()->useSubsectionTabs()) + && !peer->useSubsectionTabs()) || (std::min(state->current.count, kRecentRequestsLimit) != state->users.size())) { return; diff --git a/Telegram/SourceFiles/history/view/history_view_subsection_tabs.cpp b/Telegram/SourceFiles/history/view/history_view_subsection_tabs.cpp index c6fa04eb01..836b677779 100644 --- a/Telegram/SourceFiles/history/view/history_view_subsection_tabs.cpp +++ b/Telegram/SourceFiles/history/view/history_view_subsection_tabs.cpp @@ -840,11 +840,8 @@ bool SubsectionTabs::switchTo( bool SubsectionTabs::UsedFor(not_null thread) { const auto history = thread->owningHistory(); - if (history->amMonoforumAdmin()) { - return true; - } - const auto channel = history->peer->asChannel(); - return channel && channel->useSubsectionTabs(); + return history->amMonoforumAdmin() + || history->peer->useSubsectionTabs(); } } // namespace HistoryView diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index 8bc82dd253..e69cb49b03 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -1281,7 +1281,7 @@ Window::SessionController *Manager::openNotificationMessage( const auto separateId = !topic ? Window::SeparateId(history->peer) - : history->peer->asChannel()->useSubsectionTabs() + : history->peer->useSubsectionTabs() ? Window::SeparateId(Window::SeparateType::Chat, topic) : Window::SeparateId(Window::SeparateType::Forum, history); const auto separate = Core::App().separateWindowFor(separateId); diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index a15376135d..a573481e00 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -699,7 +699,7 @@ void Filler::addNewWindow() { if (const auto strong = weak.get()) { const auto forum = !strong->asTopic() && peer->isForum() - && !peer->asChannel()->useSubsectionTabs(); + && !peer->useSubsectionTabs(); controller->showInNewWindow(SeparateId( forum ? SeparateType::Forum : SeparateType::Chat, strong)); @@ -1429,6 +1429,7 @@ void Filler::addViewAsMessages() { void Filler::addViewAsTopics() { if (!_peer || !_peer->isForum() + || !_peer->isChannel() || (_peer->asChannel()->flags() & ChannelDataFlag::ForumTabs) || !_controller->adaptive().isOneColumn()) { return; @@ -2815,7 +2816,7 @@ base::weak_qptr ShowForwardMessagesBox( return true; } const auto id = SeparateId( - ((peer->isForum() && !peer->asChannel()->useSubsectionTabs()) + ((peer->isForum() && !peer->useSubsectionTabs()) ? SeparateType::Forum : SeparateType::Chat), thread);