MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / clear

Method clear

Telegram/SourceFiles/data/data_session.cpp:404–473  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

402}
403
404void 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();

Callers 5

SessionMethod · 0.45
clearPinnedChatsMethod · 0.45
setWallpapersMethod · 0.45
clearLocalStorageMethod · 0.45

Calls 13

AppClass · 0.85
asBotMethod · 0.80
emplaceMethod · 0.80
asChannelMethod · 0.80
unloadAllMethod · 0.80
clearChatsListMethod · 0.80
fireMethod · 0.45
clearFromSessionMethod · 0.45
isForumMethod · 0.45
amMonoforumAdminMethod · 0.45
setFlagsMethod · 0.45
flagsMethod · 0.45

Tested by

no test coverage detected