| 402 | } |
| 403 | |
| 404 | void Session::clear() { |
| 405 | _sessionDataAboutToBeCleared.fire({}); |
| 406 | |
| 407 | // Optimization: clear notifications before destroying items. |
| 408 | Core::App().notifications().clearFromSession(_session); |
| 409 | |
| 410 | // We must clear all [mono]forums before clearing customEmojiManager. |
| 411 | // Because in Data::ForumTopic an Ui::Text::CustomEmoji is cached. |
| 412 | auto botForums = base::flat_set<not_null<UserData*>>(); |
| 413 | auto channelForums = base::flat_set<not_null<ChannelData*>>(); |
| 414 | for (const auto &[peerId, peer] : _peers) { |
| 415 | if (const auto bot = peer->asBot()) { |
| 416 | if (bot->isForum()) { |
| 417 | botForums.emplace(bot); |
| 418 | } |
| 419 | } |
| 420 | if (const auto channel = peer->asChannel()) { |
| 421 | if (channel->isForum() || channel->amMonoforumAdmin()) { |
| 422 | channelForums.emplace(channel); |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | for (const auto &bot : botForums) { |
| 427 | bot->setFlags(bot->flags() & ~UserDataFlag::Forum); |
| 428 | } |
| 429 | for (const auto &channel : channelForums) { |
| 430 | channel->setFlags(channel->flags() |
| 431 | & ~(ChannelDataFlag::Forum | ChannelDataFlag::MonoforumAdmin)); |
| 432 | } |
| 433 | _savedMusic->clear(); |
| 434 | _savedMessages->clear(); |
| 435 | |
| 436 | _sendActionManager->clear(); |
| 437 | |
| 438 | _histories->unloadAll(); |
| 439 | _shortcutMessages = nullptr; |
| 440 | _session->scheduledMessages().clear(); |
| 441 | _session->sponsoredMessages().clear(); |
| 442 | |
| 443 | // Items are gone now, so HistoryMessageReply::resolvedStory raw |
| 444 | // pointers no longer linger. Tear stories down here so their |
| 445 | // shared_ptr<GroupCall> drops while Main::Session::_data still |
| 446 | // holds a live pointer to us; otherwise the GroupCall destructor |
| 447 | // would run inside ~Data::Session and find data() returning a |
| 448 | // null reference (the parent unique_ptr resets its stored pointer |
| 449 | // before invoking the deleter). |
| 450 | _stories->clear(); |
| 451 | |
| 452 | _dependentMessages.clear(); |
| 453 | base::take(_messages); |
| 454 | base::take(_nonChannelMessages); |
| 455 | _messageByRandomId.clear(); |
| 456 | _sentMessagesData.clear(); |
| 457 | cSetRecentStickers(RecentStickerPack()); |
| 458 | HistoryView::Element::ClearGlobal(); |
| 459 | _contactsNoChatsList.clear(); |
| 460 | _contactsList.clear(); |
| 461 | _chatsList.clear(); |
no test coverage detected