From 6a9556d42cd13b4f72f318c243153054fd432916 Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Thu, 4 Jan 2018 13:22:53 +0300
Subject: [PATCH] Move non-settings session data to Data::Session.

Rename AuthSessionData to AuthSessionSettings, move data away.
---
 Telegram/SourceFiles/apiwrap.cpp              |   1 +
 Telegram/SourceFiles/app.cpp                  |   1 +
 Telegram/SourceFiles/auth_session.cpp         | 206 ++----------------
 Telegram/SourceFiles/auth_session.h           | 191 ++--------------
 .../boxes/peer_list_controllers.cpp           |   1 +
 Telegram/SourceFiles/boxes/send_files_box.cpp |   8 +-
 .../SourceFiles/boxes/sticker_set_box.cpp     |   1 +
 Telegram/SourceFiles/boxes/stickers_box.cpp   |   1 +
 .../calls/calls_box_controller.cpp            |   1 +
 Telegram/SourceFiles/calls/calls_call.cpp     |   5 +-
 Telegram/SourceFiles/calls/calls_instance.cpp |   9 +-
 .../chat_helpers/gifs_list_widget.cpp         |   1 +
 .../SourceFiles/chat_helpers/stickers.cpp     |   1 +
 .../chat_helpers/stickers_list_widget.cpp     |   9 +-
 .../chat_helpers/stickers_list_widget.h       |   1 +
 .../chat_helpers/tabbed_selector.cpp          |   6 +-
 Telegram/SourceFiles/core/changelogs.cpp      |   1 +
 Telegram/SourceFiles/data/data_document.cpp   |   1 +
 Telegram/SourceFiles/data/data_peer.cpp       |   1 +
 Telegram/SourceFiles/data/data_photo.cpp      |   1 +
 .../data/data_search_controller.cpp           |   1 +
 Telegram/SourceFiles/data/data_session.cpp    | 182 ++++++++++++++++
 Telegram/SourceFiles/data/data_session.h      | 189 ++++++++++++++++
 .../dialogs/dialogs_inner_widget.cpp          |   1 +
 .../SourceFiles/dialogs/dialogs_widget.cpp    |   1 +
 Telegram/SourceFiles/facades.cpp              |   1 +
 Telegram/SourceFiles/history/history.cpp      |   1 +
 .../history/history_admin_log_inner.cpp       |   3 +-
 .../history/history_inner_widget.cpp          |   1 +
 Telegram/SourceFiles/history/history_item.cpp |   1 +
 .../history/history_media_types.cpp           |   1 +
 .../SourceFiles/history/history_message.cpp   |   1 +
 .../history/history_top_bar_widget.cpp        |  16 +-
 .../SourceFiles/history/history_widget.cpp    |  11 +-
 .../SourceFiles/info/info_layer_widget.cpp    |   6 +-
 .../info/media/info_media_list_widget.cpp     |   1 +
 .../inline_bot_layout_internal.cpp            |   1 +
 Telegram/SourceFiles/mainwidget.cpp           |  77 +++----
 .../media/player/media_player_float.cpp       |   1 +
 Telegram/SourceFiles/mediaview.cpp            |   2 +-
 Telegram/SourceFiles/messenger.cpp            |  14 +-
 Telegram/SourceFiles/messenger.h              |   7 +-
 .../SourceFiles/overview/overview_layout.cpp  |   1 +
 .../profile/profile_channel_controllers.cpp   |   1 +
 .../settings/settings_privacy_controllers.cpp |   4 +-
 .../SourceFiles/settings/settings_widget.cpp  |   4 +-
 Telegram/SourceFiles/storage/localstorage.cpp |  21 +-
 .../window/notifications_manager.cpp          |   3 +-
 .../SourceFiles/window/window_controller.cpp  |  48 ++--
 .../SourceFiles/window/window_peer_menu.cpp   |   5 +-
 Telegram/gyp/telegram_sources.txt             |   2 +
 51 files changed, 574 insertions(+), 481 deletions(-)
 create mode 100644 Telegram/SourceFiles/data/data_session.cpp
 create mode 100644 Telegram/SourceFiles/data/data_session.h

diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp
index 57ce4803a..f66dbaf2b 100644
--- a/Telegram/SourceFiles/apiwrap.cpp
+++ b/Telegram/SourceFiles/apiwrap.cpp
@@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "data/data_sparse_ids.h"
 #include "data/data_search_controller.h"
 #include "data/data_channel_admins.h"
+#include "data/data_session.h"
 
 namespace {
 
diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp
index 22c1f30f2..9edad4f99 100644
--- a/Telegram/SourceFiles/app.cpp
+++ b/Telegram/SourceFiles/app.cpp
@@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "styles/style_boxes.h"
 #include "lang/lang_keys.h"
 #include "data/data_abstract_structure.h"
+#include "data/data_session.h"
 #include "history/history_service_layout.h"
 #include "history/history_location_manager.h"
 #include "history/history_media_types.h"
diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp
index c778bed4b..4edca028a 100644
--- a/Telegram/SourceFiles/auth_session.cpp
+++ b/Telegram/SourceFiles/auth_session.cpp
@@ -15,8 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "storage/localstorage.h"
 #include "storage/storage_facade.h"
 #include "storage/serialize_common.h"
-#include "data/data_feed.h"
-#include "history/history_item_components.h"
+#include "data/data_session.h"
 #include "window/notifications_manager.h"
 #include "window/themes/window_theme.h"
 #include "platform/platform_specific.h"
@@ -24,7 +23,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "window/section_widget.h"
 #include "chat_helpers/tabbed_selector.h"
 #include "boxes/send_files_box.h"
-#include "observer_peer.h"
 
 namespace {
 
@@ -32,28 +30,14 @@ constexpr auto kAutoLockTimeoutLateMs = TimeMs(3000);
 
 } // namespace
 
-AuthSessionData::AuthSessionData() {
-	Notify::PeerUpdateViewer(
-		Notify::PeerUpdate::Flag::UserIsContact
-	) | rpl::map([](const Notify::PeerUpdate &update) {
-		return update.peer->asUser();
-	}) | rpl::filter([](UserData *user) {
-		return user != nullptr;
-	}) | rpl::start_with_next([=](not_null<UserData*> user) {
-		userIsContactUpdated(user);
-	}, _lifetime);
-}
-
-AuthSessionData::~AuthSessionData() = default;
-
-AuthSessionData::Variables::Variables()
+AuthSessionSettings::Variables::Variables()
 : sendFilesWay(SendFilesWay::Album)
 , selectorTab(ChatHelpers::SelectorTab::Emoji)
 , floatPlayerColumn(Window::Column::Second)
 , floatPlayerCorner(RectPart::TopRight) {
 }
 
-QByteArray AuthSessionData::serialize() const {
+QByteArray AuthSessionSettings::serialize() const {
 	auto size = sizeof(qint32) * 10;
 	for (auto i = _variables.soundOverrides.cbegin(), e = _variables.soundOverrides.cend(); i != e; ++i) {
 		size += Serialize::stringSize(i.key()) + Serialize::stringSize(i.value());
@@ -92,7 +76,7 @@ QByteArray AuthSessionData::serialize() const {
 	return result;
 }
 
-void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
+void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) {
 	if (serialized.isEmpty()) {
 		return;
 	}
@@ -162,7 +146,8 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
 		thirdSectionExtendedBy = value;
 	}
 	if (stream.status() != QDataStream::Ok) {
-		LOG(("App Error: Bad data for AuthSessionData::constructFromSerialized()"));
+		LOG(("App Error: "
+			"Bad data for AuthSessionSettings::constructFromSerialized()"));
 		return;
 	}
 
@@ -206,87 +191,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
 	}
 }
 
-void AuthSessionData::markItemLayoutChanged(not_null<const HistoryItem*> item) {
-	_itemLayoutChanged.fire_copy(item);
-}
-
-rpl::producer<not_null<const HistoryItem*>> AuthSessionData::itemLayoutChanged() const {
-	return _itemLayoutChanged.events();
-}
-
-void AuthSessionData::requestItemRepaint(not_null<const HistoryItem*> item) {
-	_itemRepaintRequest.fire_copy(item);
-}
-
-rpl::producer<not_null<const HistoryItem*>> AuthSessionData::itemRepaintRequest() const {
-	return _itemRepaintRequest.events();
-}
-
-void AuthSessionData::markItemRemoved(not_null<const HistoryItem*> item) {
-	_itemRemoved.fire_copy(item);
-}
-
-rpl::producer<not_null<const HistoryItem*>> AuthSessionData::itemRemoved() const {
-	return _itemRemoved.events();
-}
-
-void AuthSessionData::markHistoryUnloaded(not_null<const History*> history) {
-	_historyUnloaded.fire_copy(history);
-}
-
-rpl::producer<not_null<const History*>> AuthSessionData::historyUnloaded() const {
-	return _historyUnloaded.events();
-}
-
-void AuthSessionData::markHistoryCleared(not_null<const History*> history) {
-	_historyCleared.fire_copy(history);
-}
-
-rpl::producer<not_null<const History*>> AuthSessionData::historyCleared() const {
-	return _historyCleared.events();
-}
-
-void AuthSessionData::removeMegagroupParticipant(
-		not_null<ChannelData*> channel,
-		not_null<UserData*> user) {
-	_megagroupParticipantRemoved.fire({ channel, user });
-}
-
-auto AuthSessionData::megagroupParticipantRemoved() const -> rpl::producer<MegagroupParticipant> {
-	return _megagroupParticipantRemoved.events();
-}
-
-rpl::producer<not_null<UserData*>> AuthSessionData::megagroupParticipantRemoved(
-		not_null<ChannelData*> channel) const {
-	return megagroupParticipantRemoved(
-	) | rpl::filter([channel](auto updateChannel, auto user) {
-		return (updateChannel == channel);
-	}) | rpl::map([](auto updateChannel, auto user) {
-		return user;
-	});
-}
-
-void AuthSessionData::addNewMegagroupParticipant(
-		not_null<ChannelData*> channel,
-		not_null<UserData*> user) {
-	_megagroupParticipantAdded.fire({ channel, user });
-}
-
-auto AuthSessionData::megagroupParticipantAdded() const -> rpl::producer<MegagroupParticipant> {
-	return _megagroupParticipantAdded.events();
-}
-
-rpl::producer<not_null<UserData*>> AuthSessionData::megagroupParticipantAdded(
-		not_null<ChannelData*> channel) const {
-	return megagroupParticipantAdded(
-	) | rpl::filter([channel](auto updateChannel, auto user) {
-		return (updateChannel == channel);
-	}) | rpl::map([](auto updateChannel, auto user) {
-		return user;
-	});
-}
-
-void AuthSessionData::setTabbedSelectorSectionEnabled(bool enabled) {
+void AuthSessionSettings::setTabbedSelectorSectionEnabled(bool enabled) {
 	_variables.tabbedSelectorSectionEnabled = enabled;
 	if (enabled) {
 		setThirdSectionInfoEnabled(false);
@@ -294,12 +199,12 @@ void AuthSessionData::setTabbedSelectorSectionEnabled(bool enabled) {
 	setTabbedReplacedWithInfo(false);
 }
 
-rpl::producer<bool> AuthSessionData::tabbedReplacedWithInfoValue() const {
+rpl::producer<bool> AuthSessionSettings::tabbedReplacedWithInfoValue() const {
 	return _tabbedReplacedWithInfoValue.events_starting_with(
 		tabbedReplacedWithInfo());
 }
 
-void AuthSessionData::setThirdSectionInfoEnabled(bool enabled) {
+void AuthSessionSettings::setThirdSectionInfoEnabled(bool enabled) {
 	if (_variables.thirdSectionInfoEnabled != enabled) {
 		_variables.thirdSectionInfoEnabled = enabled;
 		if (enabled) {
@@ -310,19 +215,19 @@ void AuthSessionData::setThirdSectionInfoEnabled(bool enabled) {
 	}
 }
 
-rpl::producer<bool> AuthSessionData::thirdSectionInfoEnabledValue() const {
+rpl::producer<bool> AuthSessionSettings::thirdSectionInfoEnabledValue() const {
 	return _thirdSectionInfoEnabledValue.events_starting_with(
 		thirdSectionInfoEnabled());
 }
 
-void AuthSessionData::setTabbedReplacedWithInfo(bool enabled) {
+void AuthSessionSettings::setTabbedReplacedWithInfo(bool enabled) {
 	if (_tabbedReplacedWithInfo != enabled) {
 		_tabbedReplacedWithInfo = enabled;
 		_tabbedReplacedWithInfoValue.fire_copy(enabled);
 	}
 }
 
-QString AuthSessionData::getSoundPath(const QString &key) const {
+QString AuthSessionSettings::getSoundPath(const QString &key) const {
 	auto it = _variables.soundOverrides.constFind(key);
 	if (it != _variables.soundOverrides.end()) {
 		return it.value();
@@ -330,100 +235,30 @@ QString AuthSessionData::getSoundPath(const QString &key) const {
 	return qsl(":/sounds/") + key + qsl(".mp3");
 }
 
-void AuthSessionData::setDialogsWidthRatio(float64 ratio) {
+void AuthSessionSettings::setDialogsWidthRatio(float64 ratio) {
 	_variables.dialogsWidthRatio = ratio;
 }
 
-float64 AuthSessionData::dialogsWidthRatio() const {
+float64 AuthSessionSettings::dialogsWidthRatio() const {
 	return _variables.dialogsWidthRatio.current();
 }
 
-rpl::producer<float64> AuthSessionData::dialogsWidthRatioChanges() const {
+rpl::producer<float64> AuthSessionSettings::dialogsWidthRatioChanges() const {
 	return _variables.dialogsWidthRatio.changes();
 }
 
-void AuthSessionData::setThirdColumnWidth(int width) {
+void AuthSessionSettings::setThirdColumnWidth(int width) {
 	_variables.thirdColumnWidth = width;
 }
 
-int AuthSessionData::thirdColumnWidth() const {
+int AuthSessionSettings::thirdColumnWidth() const {
 	return _variables.thirdColumnWidth.current();
 }
 
-rpl::producer<int> AuthSessionData::thirdColumnWidthChanges() const {
+rpl::producer<int> AuthSessionSettings::thirdColumnWidthChanges() const {
 	return _variables.thirdColumnWidth.changes();
 }
 
-void AuthSessionData::markStickersUpdated() {
-	_stickersUpdated.fire({});
-}
-
-rpl::producer<> AuthSessionData::stickersUpdated() const {
-	return _stickersUpdated.events();
-}
-
-void AuthSessionData::markSavedGifsUpdated() {
-	_savedGifsUpdated.fire({});
-}
-
-rpl::producer<> AuthSessionData::savedGifsUpdated() const {
-	return _savedGifsUpdated.events();
-}
-
-void AuthSessionData::userIsContactUpdated(not_null<UserData*> user) {
-	const auto &items = App::sharedContactItems();
-	const auto i = items.constFind(peerToUser(user->id));
-	if (i != items.cend()) {
-		for (const auto item : std::as_const(i.value())) {
-			item->setPendingInitDimensions();
-		}
-	}
-}
-
-HistoryItemsList AuthSessionData::idsToItems(
-		const MessageIdsList &ids) const {
-	return ranges::view::all(
-		ids
-	) | ranges::view::transform([](const FullMsgId &fullId) {
-		return App::histItemById(fullId);
-	}) | ranges::view::filter([](HistoryItem *item) {
-		return item != nullptr;
-	}) | ranges::view::transform([](HistoryItem *item) {
-		return not_null<HistoryItem*>(item);
-	}) | ranges::to_vector;
-}
-
-MessageIdsList AuthSessionData::itemsToIds(
-		const HistoryItemsList &items) const {
-	return ranges::view::all(
-		items
-	) | ranges::view::transform([](not_null<HistoryItem*> item) {
-		return item->fullId();
-	}) | ranges::to_vector;
-}
-
-MessageIdsList AuthSessionData::groupToIds(
-		not_null<HistoryMessageGroup*> group) const {
-	auto result = itemsToIds(group->others);
-	result.push_back(group->leader->fullId());
-	return result;
-}
-
-not_null<Data::Feed*> AuthSessionData::feed(FeedId id) {
-	if (const auto result = feedLoaded(id)) {
-		return result;
-	}
-	const auto [it, ok] = _feeds.emplace(
-		id,
-		std::make_unique<Data::Feed>(id));
-	return it->second.get();
-}
-
-Data::Feed *AuthSessionData::feedLoaded(FeedId id) {
-	const auto it = _feeds.find(id);
-	return (it == _feeds.end()) ? nullptr : it->second.get();
-}
-
 AuthSession &Auth() {
 	auto result = Messenger::Instance().authSession();
 	Assert(result != nullptr);
@@ -433,6 +268,7 @@ AuthSession &Auth() {
 AuthSession::AuthSession(UserId userId)
 : _userId(userId)
 , _autoLockTimer([this] { checkAutoLock(); })
+, _data(std::make_unique<Data::Session>())
 , _api(std::make_unique<ApiWrap>(this))
 , _calls(std::make_unique<Calls::Instance>())
 , _downloader(std::make_unique<Storage::Downloader>())
@@ -476,7 +312,7 @@ bool AuthSession::validateSelf(const MTPUser &user) {
 	return true;
 }
 
-void AuthSession::saveDataDelayed(TimeMs delay) {
+void AuthSession::saveSettingsDelayed(TimeMs delay) {
 	Expects(this == &Auth());
 	_saveDataTimer.callOnce(delay);
 }
@@ -488,7 +324,7 @@ void AuthSession::checkAutoLock() {
 	auto now = getms(true);
 	auto shouldLockInMs = Global::AutoLock() * 1000LL;
 	auto idleForMs = psIdleTime();
-	auto notPlayingVideoForMs = now - data().lastTimeVideoPlayedAt();
+	auto notPlayingVideoForMs = now - settings().lastTimeVideoPlayedAt();
 	auto checkTimeMs = qMin(idleForMs, notPlayingVideoForMs);
 	if (checkTimeMs >= shouldLockInMs || (_shouldLockAt > 0 && now > _shouldLockAt + kAutoLockTimeoutLateMs)) {
 		Messenger::Instance().setupPasscode();
diff --git a/Telegram/SourceFiles/auth_session.h b/Telegram/SourceFiles/auth_session.h
index f472c1b63..6c14b451b 100644
--- a/Telegram/SourceFiles/auth_session.h
+++ b/Telegram/SourceFiles/auth_session.h
@@ -11,13 +11,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include <rpl/filter.h>
 #include <rpl/variable.h>
 #include "base/timer.h"
-#include "chat_helpers/stickers.h"
 
 class ApiWrap;
 enum class SendFilesWay;
 
 namespace Data {
-class Feed;
+class Session;
 } // namespace Data
 
 namespace Storage {
@@ -45,68 +44,20 @@ namespace Core {
 class Changelogs;
 } // namespace Core
 
-class AuthSessionData final {
+class AuthSessionSettings final {
 public:
-	AuthSessionData();
-	~AuthSessionData();
-
-	base::Variable<bool> &contactsLoaded() {
-		return _contactsLoaded;
-	}
-	base::Variable<bool> &allChatsLoaded() {
-		return _allChatsLoaded;
-	}
-	base::Observable<void> &moreChatsLoaded() {
-		return _moreChatsLoaded;
-	}
-	base::Observable<void> &pendingHistoryResize() {
-		return _pendingHistoryResize;
-	}
-	struct ItemVisibilityQuery {
-		not_null<HistoryItem*> item;
-		not_null<bool*> isVisible;
-	};
-	base::Observable<ItemVisibilityQuery> &queryItemVisibility() {
-		return _queryItemVisibility;
-	}
-	void markItemLayoutChanged(not_null<const HistoryItem*> item);
-	rpl::producer<not_null<const HistoryItem*>> itemLayoutChanged() const;
-	void requestItemRepaint(not_null<const HistoryItem*> item);
-	rpl::producer<not_null<const HistoryItem*>> itemRepaintRequest() const;
-	void markItemRemoved(not_null<const HistoryItem*> item);
-	rpl::producer<not_null<const HistoryItem*>> itemRemoved() const;
-	void markHistoryUnloaded(not_null<const History*> history);
-	rpl::producer<not_null<const History*>> historyUnloaded() const;
-	void markHistoryCleared(not_null<const History*> history);
-	rpl::producer<not_null<const History*>> historyCleared() const;
-	using MegagroupParticipant = std::tuple<
-		not_null<ChannelData*>,
-		not_null<UserData*>>;
-	void removeMegagroupParticipant(
-		not_null<ChannelData*> channel,
-		not_null<UserData*> user);
-	rpl::producer<MegagroupParticipant> megagroupParticipantRemoved() const;
-	rpl::producer<not_null<UserData*>> megagroupParticipantRemoved(
-		not_null<ChannelData*> channel) const;
-	void addNewMegagroupParticipant(
-		not_null<ChannelData*> channel,
-		not_null<UserData*> user);
-	rpl::producer<MegagroupParticipant> megagroupParticipantAdded() const;
-	rpl::producer<not_null<UserData*>> megagroupParticipantAdded(
-		not_null<ChannelData*> channel) const;
-
-	void moveFrom(AuthSessionData &&other) {
+	void moveFrom(AuthSessionSettings &&other) {
 		_variables = std::move(other._variables);
 	}
 	QByteArray serialize() const;
 	void constructFromSerialized(const QByteArray &serialized);
 
-	bool lastSeenWarningSeen() const {
-		return _variables.lastSeenWarningSeen;
-	}
 	void setLastSeenWarningSeen(bool lastSeenWarningSeen) {
 		_variables.lastSeenWarningSeen = lastSeenWarningSeen;
 	}
+	bool lastSeenWarningSeen() const {
+		return _variables.lastSeenWarningSeen;
+	}
 	void setSendFilesWay(SendFilesWay way) {
 		_variables.sendFilesWay = way;
 	}
@@ -183,10 +134,6 @@ public:
 	int thirdColumnWidth() const;
 	rpl::producer<int> thirdColumnWidthChanges() const;
 
-	void markStickersUpdated();
-	rpl::producer<> stickersUpdated() const;
-	void markSavedGifsUpdated();
-	rpl::producer<> savedGifsUpdated() const;
 	void setGroupStickersSectionHidden(PeerId peerId) {
 		_variables.groupStickersSectionHidden.insert(peerId);
 	}
@@ -196,82 +143,6 @@ public:
 	void removeGroupStickersSectionHidden(PeerId peerId) {
 		_variables.groupStickersSectionHidden.remove(peerId);
 	}
-	bool stickersUpdateNeeded(TimeMs now) const {
-		return stickersUpdateNeeded(_lastStickersUpdate, now);
-	}
-	void setLastStickersUpdate(TimeMs update) {
-		_lastStickersUpdate = update;
-	}
-	bool recentStickersUpdateNeeded(TimeMs now) const {
-		return stickersUpdateNeeded(_lastRecentStickersUpdate, now);
-	}
-	void setLastRecentStickersUpdate(TimeMs update) {
-		_lastRecentStickersUpdate = update;
-	}
-	bool favedStickersUpdateNeeded(TimeMs now) const {
-		return stickersUpdateNeeded(_lastFavedStickersUpdate, now);
-	}
-	void setLastFavedStickersUpdate(TimeMs update) {
-		_lastFavedStickersUpdate = update;
-	}
-	bool featuredStickersUpdateNeeded(TimeMs now) const {
-		return stickersUpdateNeeded(_lastFeaturedStickersUpdate, now);
-	}
-	void setLastFeaturedStickersUpdate(TimeMs update) {
-		_lastFeaturedStickersUpdate = update;
-	}
-	bool savedGifsUpdateNeeded(TimeMs now) const {
-		return stickersUpdateNeeded(_lastSavedGifsUpdate, now);
-	}
-	void setLastSavedGifsUpdate(TimeMs update) {
-		_lastSavedGifsUpdate = update;
-	}
-	int featuredStickerSetsUnreadCount() const {
-		return _featuredStickerSetsUnreadCount.current();
-	}
-	void setFeaturedStickerSetsUnreadCount(int count) {
-		_featuredStickerSetsUnreadCount = count;
-	}
-	rpl::producer<int> featuredStickerSetsUnreadCountValue() const {
-		return _featuredStickerSetsUnreadCount.value();
-	}
-	const Stickers::Sets &stickerSets() const {
-		return _stickerSets;
-	}
-	Stickers::Sets &stickerSetsRef() {
-		return _stickerSets;
-	}
-	const Stickers::Order &stickerSetsOrder() const {
-		return _stickerSetsOrder;
-	}
-	Stickers::Order &stickerSetsOrderRef() {
-		return _stickerSetsOrder;
-	}
-	const Stickers::Order &featuredStickerSetsOrder() const {
-		return _featuredStickerSetsOrder;
-	}
-	Stickers::Order &featuredStickerSetsOrderRef() {
-		return _featuredStickerSetsOrder;
-	}
-	const Stickers::Order &archivedStickerSetsOrder() const {
-		return _archivedStickerSetsOrder;
-	}
-	Stickers::Order &archivedStickerSetsOrderRef() {
-		return _archivedStickerSetsOrder;
-	}
-	const Stickers::SavedGifs &savedGifs() const {
-		return _savedGifs;
-	}
-	Stickers::SavedGifs &savedGifsRef() {
-		return _savedGifs;
-	}
-
-	HistoryItemsList idsToItems(const MessageIdsList &ids) const;
-	MessageIdsList itemsToIds(const HistoryItemsList &items) const;
-	MessageIdsList groupToIds(not_null<HistoryMessageGroup*> group) const;
-
-	not_null<Data::Feed*> feed(FeedId id);
-	Data::Feed *feedLoaded(FeedId id);
 
 private:
 	struct Variables {
@@ -298,42 +169,6 @@ private:
 			= kDefaultThirdColumnWidth; // per-window
 	};
 
-	bool stickersUpdateNeeded(TimeMs lastUpdate, TimeMs now) const {
-		constexpr auto kStickersUpdateTimeout = TimeMs(3600'000);
-		return (lastUpdate == 0)
-			|| (now >= lastUpdate + kStickersUpdateTimeout);
-	}
-	void userIsContactUpdated(not_null<UserData*> user);
-
-	base::Variable<bool> _contactsLoaded = { false };
-	base::Variable<bool> _allChatsLoaded = { false };
-	base::Observable<void> _moreChatsLoaded;
-	base::Observable<void> _pendingHistoryResize;
-	base::Observable<ItemVisibilityQuery> _queryItemVisibility;
-	rpl::event_stream<not_null<const HistoryItem*>> _itemLayoutChanged;
-	rpl::event_stream<not_null<const HistoryItem*>> _itemRepaintRequest;
-	rpl::event_stream<not_null<const HistoryItem*>> _itemRemoved;
-	rpl::event_stream<not_null<const History*>> _historyUnloaded;
-	rpl::event_stream<not_null<const History*>> _historyCleared;
-	rpl::event_stream<MegagroupParticipant> _megagroupParticipantRemoved;
-	rpl::event_stream<MegagroupParticipant> _megagroupParticipantAdded;
-
-	rpl::event_stream<> _stickersUpdated;
-	rpl::event_stream<> _savedGifsUpdated;
-	TimeMs _lastStickersUpdate = 0;
-	TimeMs _lastRecentStickersUpdate = 0;
-	TimeMs _lastFavedStickersUpdate = 0;
-	TimeMs _lastFeaturedStickersUpdate = 0;
-	TimeMs _lastSavedGifsUpdate = 0;
-	rpl::variable<int> _featuredStickerSetsUnreadCount = 0;
-	Stickers::Sets _stickerSets;
-	Stickers::Order _stickerSetsOrder;
-	Stickers::Order _featuredStickerSetsOrder;
-	Stickers::Order _archivedStickerSetsOrder;
-	Stickers::SavedGifs _savedGifs;
-
-	base::flat_map<FeedId, std::unique_ptr<Data::Feed>> _feeds;
-
 	rpl::event_stream<bool> _thirdSectionInfoEnabledValue;
 	bool _tabbedReplacedWithInfo = false;
 	rpl::event_stream<bool> _tabbedReplacedWithInfoValue;
@@ -341,8 +176,6 @@ private:
 	Variables _variables;
 	TimeMs _lastTimeVideoPlayedAt = 0;
 
-	rpl::lifetime _lifetime;
-
 };
 
 // One per Messenger.
@@ -383,10 +216,13 @@ public:
 		return *_notifications;
 	}
 
-	AuthSessionData &data() {
-		return _data;
+	Data::Session &data() {
+		return *_data;
 	}
-	void saveDataDelayed(TimeMs delay = kDefaultSaveDelay);
+	AuthSessionSettings &settings() {
+		return _settings;
+	}
+	void saveSettingsDelayed(TimeMs delay = kDefaultSaveDelay);
 
 	ApiWrap &api() {
 		return *_api;
@@ -408,12 +244,13 @@ private:
 	static constexpr auto kDefaultSaveDelay = TimeMs(1000);
 
 	const UserId _userId = 0;
-	AuthSessionData _data;
+	AuthSessionSettings _settings;
 	base::Timer _saveDataTimer;
 
 	TimeMs _shouldLockAt = 0;
 	base::Timer _autoLockTimer;
 
+	const std::unique_ptr<Data::Session> _data;
 	const std::unique_ptr<ApiWrap> _api;
 	const std::unique_ptr<Calls::Instance> _calls;
 	const std::unique_ptr<Storage::Downloader> _downloader;
diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp
index 1d02b43b5..a4ebe107f 100644
--- a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp
+++ b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp
@@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "observer_peer.h"
 #include "ui/widgets/checkbox.h"
 #include "auth_session.h"
+#include "data/data_session.h"
 #include "apiwrap.h"
 #include "mainwidget.h"
 #include "lang/lang_keys.h"
diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp
index 3888e60ce..9884a82f7 100644
--- a/Telegram/SourceFiles/boxes/send_files_box.cpp
+++ b/Telegram/SourceFiles/boxes/send_files_box.cpp
@@ -1433,7 +1433,7 @@ void SendFilesBox::initSendWay() {
 				? SendFilesWay::Album
 				: SendFilesWay::Photos;
 		}
-		const auto currentWay = Auth().data().sendFilesWay();
+		const auto currentWay = Auth().settings().sendFilesWay();
 		if (currentWay == SendFilesWay::Files) {
 			return currentWay;
 		} else if (currentWay == SendFilesWay::Album) {
@@ -1756,7 +1756,7 @@ void SendFilesBox::send(bool ctrlShiftEnter) {
 	const auto way = _sendWay ? _sendWay->value() : Way::Files;
 
 	if (_compressConfirm == CompressConfirm::Auto) {
-		const auto oldWay = Auth().data().sendFilesWay();
+		const auto oldWay = Auth().settings().sendFilesWay();
 		if (way != oldWay) {
 			// Check if the user _could_ use the old value, but didn't.
 			if ((oldWay == Way::Album && _sendAlbum)
@@ -1764,8 +1764,8 @@ void SendFilesBox::send(bool ctrlShiftEnter) {
 				|| (oldWay == Way::Files && _sendFiles)
 				|| (way == Way::Files && (_sendAlbum || _sendPhotos))) {
 				// And in that case save it to settings.
-				Auth().data().setSendFilesWay(way);
-				Auth().saveDataDelayed();
+				Auth().settings().setSendFilesWay(way);
+				Auth().saveSettingsDelayed();
 			}
 		}
 	}
diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp
index ffcb56145..bad87847f 100644
--- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp
+++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "boxes/sticker_set_box.h"
 
 #include "data/data_document.h"
+#include "data/data_session.h"
 #include "lang/lang_keys.h"
 #include "mainwidget.h"
 #include "mainwindow.h"
diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp
index e7b850df0..f7b765544 100644
--- a/Telegram/SourceFiles/boxes/stickers_box.cpp
+++ b/Telegram/SourceFiles/boxes/stickers_box.cpp
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "stickers_box.h"
 
 #include "data/data_document.h"
+#include "data/data_session.h"
 #include "lang/lang_keys.h"
 #include "mainwidget.h"
 #include "chat_helpers/stickers.h"
diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp
index a3dc123d3..2ade7bd33 100644
--- a/Telegram/SourceFiles/calls/calls_box_controller.cpp
+++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp
@@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "history/history_media_types.h"
 #include "mainwidget.h"
 #include "auth_session.h"
+#include "data/data_session.h"
 
 namespace Calls {
 namespace {
diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp
index 289a2122b..b298c8ce6 100644
--- a/Telegram/SourceFiles/calls/calls_call.cpp
+++ b/Telegram/SourceFiles/calls/calls_call.cpp
@@ -248,7 +248,10 @@ QString Call::getDebugLog() const {
 
 void Call::startWaitingTrack() {
 	_waitingTrack = Media::Audio::Current().createTrack();
-	auto trackFileName = Auth().data().getSoundPath((_type == Type::Outgoing) ? qsl("call_outgoing") : qsl("call_incoming"));
+	auto trackFileName = Auth().settings().getSoundPath(
+		(_type == Type::Outgoing)
+		? qsl("call_outgoing")
+		: qsl("call_incoming"));
 	_waitingTrack->samplePeakEach(kSoundSampleMs);
 	_waitingTrack->fillFromFile(trackFileName);
 	_waitingTrack->playInLoop();
diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp
index 15577b15d..3db61ec88 100644
--- a/Telegram/SourceFiles/calls/calls_instance.cpp
+++ b/Telegram/SourceFiles/calls/calls_instance.cpp
@@ -60,7 +60,8 @@ void Instance::playSound(Sound sound) {
 	case Sound::Busy: {
 		if (!_callBusyTrack) {
 			_callBusyTrack = Media::Audio::Current().createTrack();
-			_callBusyTrack->fillFromFile(Auth().data().getSoundPath(qsl("call_busy")));
+			_callBusyTrack->fillFromFile(
+				Auth().settings().getSoundPath(qsl("call_busy")));
 		}
 		_callBusyTrack->playOnce();
 	} break;
@@ -68,7 +69,8 @@ void Instance::playSound(Sound sound) {
 	case Sound::Ended: {
 		if (!_callEndedTrack) {
 			_callEndedTrack = Media::Audio::Current().createTrack();
-			_callEndedTrack->fillFromFile(Auth().data().getSoundPath(qsl("call_end")));
+			_callEndedTrack->fillFromFile(
+				Auth().settings().getSoundPath(qsl("call_end")));
 		}
 		_callEndedTrack->playOnce();
 	} break;
@@ -76,7 +78,8 @@ void Instance::playSound(Sound sound) {
 	case Sound::Connecting: {
 		if (!_callConnectingTrack) {
 			_callConnectingTrack = Media::Audio::Current().createTrack();
-			_callConnectingTrack->fillFromFile(Auth().data().getSoundPath(qsl("call_connect")));
+			_callConnectingTrack->fillFromFile(
+				Auth().settings().getSoundPath(qsl("call_connect")));
 		}
 		_callConnectingTrack->playOnce();
 	} break;
diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp
index 0b57e9629..2e04f81dc 100644
--- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp
+++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp
@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 
 #include "data/data_photo.h"
 #include "data/data_document.h"
+#include "data/data_session.h"
 #include "styles/style_chat_helpers.h"
 #include "ui/widgets/buttons.h"
 #include "ui/widgets/input_fields.h"
diff --git a/Telegram/SourceFiles/chat_helpers/stickers.cpp b/Telegram/SourceFiles/chat_helpers/stickers.cpp
index c49aef6f4..ae083da79 100644
--- a/Telegram/SourceFiles/chat_helpers/stickers.cpp
+++ b/Telegram/SourceFiles/chat_helpers/stickers.cpp
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "stickers.h"
 
 #include "data/data_document.h"
+#include "data/data_session.h"
 #include "boxes/stickers_box.h"
 #include "boxes/confirm_box.h"
 #include "lang/lang_keys.h"
diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp
index 913510201..ec912821c 100644
--- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp
+++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "chat_helpers/stickers_list_widget.h"
 
 #include "data/data_document.h"
+#include "data/data_session.h"
 #include "ui/widgets/buttons.h"
 #include "ui/effects/ripple_animation.h"
 #include "boxes/stickers_box.h"
@@ -1393,17 +1394,17 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) {
 	};
 	if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetEmpty) {
 		if (canEdit) {
-			auto hidden = Auth().data().isGroupStickersSectionHidden(_megagroupSet->id);
+			auto hidden = Auth().settings().isGroupStickersSectionHidden(_megagroupSet->id);
 			if (isShownHere(hidden)) {
 				_mySets.push_back(Set(Stickers::MegagroupSetId, MTPDstickerSet_ClientFlag::f_special | 0, lang(lng_group_stickers), 0));
 			}
 		}
 		return;
 	}
-	auto hidden = Auth().data().isGroupStickersSectionHidden(_megagroupSet->id);
+	auto hidden = Auth().settings().isGroupStickersSectionHidden(_megagroupSet->id);
 	auto removeHiddenForGroup = [this, &hidden] {
 		if (hidden) {
-			Auth().data().removeGroupStickersSectionHidden(_megagroupSet->id);
+			Auth().settings().removeGroupStickersSectionHidden(_megagroupSet->id);
 			Local::writeUserSettings();
 			hidden = false;
 		}
@@ -1753,7 +1754,7 @@ void StickersListWidget::installSet(uint64 setId) {
 
 void StickersListWidget::removeMegagroupSet(bool locally) {
 	if (locally) {
-		Auth().data().setGroupStickersSectionHidden(_megagroupSet->id);
+		Auth().settings().setGroupStickersSectionHidden(_megagroupSet->id);
 		Local::writeUserSettings();
 		refreshStickers();
 		return;
diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h
index a306458ef..090eeb96c 100644
--- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h
+++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #pragma once
 
 #include "chat_helpers/tabbed_selector.h"
+#include "chat_helpers/stickers.h"
 #include "base/variant.h"
 
 namespace Window {
diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp
index ef8e04a4f..efb1b14f9 100644
--- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp
+++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp
@@ -277,7 +277,7 @@ TabbedSelector::TabbedSelector(QWidget *parent, not_null<Window::Controller*> co
 	Tab { SelectorTab::Stickers, object_ptr<StickersListWidget>(this, controller) },
 	Tab { SelectorTab::Gifs, object_ptr<GifsListWidget>(this, controller) },
 } }
-, _currentTabType(Auth().data().selectorTab()) {
+, _currentTabType(Auth().settings().selectorTab()) {
 	resize(st::emojiPanWidth, st::emojiPanMaxHeight);
 
 	for (auto &tab : _tabs) {
@@ -685,8 +685,8 @@ void TabbedSelector::switchTab() {
 	_a_slide.start([this] { update(); }, 0., 1., st::emojiPanSlideDuration, anim::linear);
 	update();
 
-	Auth().data().setSelectorTab(_currentTabType);
-	Auth().saveDataDelayed();
+	Auth().settings().setSelectorTab(_currentTabType);
+	Auth().saveSettingsDelayed();
 }
 
 not_null<EmojiListWidget*> TabbedSelector::emoji() const {
diff --git a/Telegram/SourceFiles/core/changelogs.cpp b/Telegram/SourceFiles/core/changelogs.cpp
index 5698aa4b5..e42caa039 100644
--- a/Telegram/SourceFiles/core/changelogs.cpp
+++ b/Telegram/SourceFiles/core/changelogs.cpp
@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 
 #include "storage/localstorage.h"
 #include "lang/lang_keys.h"
+#include "data/data_session.h"
 #include "mainwindow.h"
 #include "apiwrap.h"
 
diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp
index 48fd09738..56a3df4c2 100644
--- a/Telegram/SourceFiles/data/data_document.cpp
+++ b/Telegram/SourceFiles/data/data_document.cpp
@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 */
 #include "data/data_document.h"
 
+#include "data/data_session.h"
 #include "lang/lang_keys.h"
 #include "inline_bots/inline_bot_layout_item.h"
 #include "mainwidget.h"
diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp
index 56a37d489..fbcc40d2c 100644
--- a/Telegram/SourceFiles/data/data_peer.cpp
+++ b/Telegram/SourceFiles/data/data_peer.cpp
@@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "data/data_channel_admins.h"
 #include "data/data_photo.h"
 #include "data/data_feed.h"
+#include "data/data_session.h"
 #include "lang/lang_keys.h"
 #include "observer_peer.h"
 #include "mainwidget.h"
diff --git a/Telegram/SourceFiles/data/data_photo.cpp b/Telegram/SourceFiles/data/data_photo.cpp
index c0629dcc8..1c645f91b 100644
--- a/Telegram/SourceFiles/data/data_photo.cpp
+++ b/Telegram/SourceFiles/data/data_photo.cpp
@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 */
 #include "data/data_photo.h"
 
+#include "data/data_session.h"
 #include "mainwidget.h"
 #include "history/history_media_types.h"
 #include "auth_session.h"
diff --git a/Telegram/SourceFiles/data/data_search_controller.cpp b/Telegram/SourceFiles/data/data_search_controller.cpp
index 6d7ae9947..7e88734cb 100644
--- a/Telegram/SourceFiles/data/data_search_controller.cpp
+++ b/Telegram/SourceFiles/data/data_search_controller.cpp
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "data/data_search_controller.h"
 
 #include "auth_session.h"
+#include "data/data_session.h"
 
 namespace Api {
 namespace {
diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp
new file mode 100644
index 000000000..cedeb541f
--- /dev/null
+++ b/Telegram/SourceFiles/data/data_session.cpp
@@ -0,0 +1,182 @@
+/*
+This file is part of Telegram Desktop,
+the official desktop application for the Telegram messaging service.
+
+For license and copyright information please follow this link:
+https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
+*/
+#include "data/data_session.h"
+
+#include "observer_peer.h"
+#include "history/history_item_components.h"
+#include "data/data_feed.h"
+
+namespace Data {
+
+Session::Session() {
+	Notify::PeerUpdateViewer(
+		Notify::PeerUpdate::Flag::UserIsContact
+	) | rpl::map([](const Notify::PeerUpdate &update) {
+		return update.peer->asUser();
+	}) | rpl::filter([](UserData *user) {
+		return user != nullptr;
+	}) | rpl::start_with_next([=](not_null<UserData*> user) {
+		userIsContactUpdated(user);
+	}, _lifetime);
+}
+
+Session::~Session() = default;
+
+void Session::markItemLayoutChanged(not_null<const HistoryItem*> item) {
+	_itemLayoutChanged.fire_copy(item);
+}
+
+rpl::producer<not_null<const HistoryItem*>> Session::itemLayoutChanged() const {
+	return _itemLayoutChanged.events();
+}
+
+void Session::requestItemRepaint(not_null<const HistoryItem*> item) {
+	_itemRepaintRequest.fire_copy(item);
+}
+
+rpl::producer<not_null<const HistoryItem*>> Session::itemRepaintRequest() const {
+	return _itemRepaintRequest.events();
+}
+
+void Session::markItemRemoved(not_null<const HistoryItem*> item) {
+	_itemRemoved.fire_copy(item);
+}
+
+rpl::producer<not_null<const HistoryItem*>> Session::itemRemoved() const {
+	return _itemRemoved.events();
+}
+
+void Session::markHistoryUnloaded(not_null<const History*> history) {
+	_historyUnloaded.fire_copy(history);
+}
+
+rpl::producer<not_null<const History*>> Session::historyUnloaded() const {
+	return _historyUnloaded.events();
+}
+
+void Session::markHistoryCleared(not_null<const History*> history) {
+	_historyCleared.fire_copy(history);
+}
+
+rpl::producer<not_null<const History*>> Session::historyCleared() const {
+	return _historyCleared.events();
+}
+
+void Session::removeMegagroupParticipant(
+		not_null<ChannelData*> channel,
+		not_null<UserData*> user) {
+	_megagroupParticipantRemoved.fire({ channel, user });
+}
+
+auto Session::megagroupParticipantRemoved() const
+-> rpl::producer<MegagroupParticipant> {
+	return _megagroupParticipantRemoved.events();
+}
+
+rpl::producer<not_null<UserData*>> Session::megagroupParticipantRemoved(
+		not_null<ChannelData*> channel) const {
+	return megagroupParticipantRemoved(
+	) | rpl::filter([channel](auto updateChannel, auto user) {
+		return (updateChannel == channel);
+	}) | rpl::map([](auto updateChannel, auto user) {
+		return user;
+	});
+}
+
+void Session::addNewMegagroupParticipant(
+		not_null<ChannelData*> channel,
+		not_null<UserData*> user) {
+	_megagroupParticipantAdded.fire({ channel, user });
+}
+
+auto Session::megagroupParticipantAdded() const
+-> rpl::producer<MegagroupParticipant> {
+	return _megagroupParticipantAdded.events();
+}
+
+rpl::producer<not_null<UserData*>> Session::megagroupParticipantAdded(
+		not_null<ChannelData*> channel) const {
+	return megagroupParticipantAdded(
+	) | rpl::filter([channel](auto updateChannel, auto user) {
+		return (updateChannel == channel);
+	}) | rpl::map([](auto updateChannel, auto user) {
+		return user;
+	});
+}
+
+void Session::markStickersUpdated() {
+	_stickersUpdated.fire({});
+}
+
+rpl::producer<> Session::stickersUpdated() const {
+	return _stickersUpdated.events();
+}
+
+void Session::markSavedGifsUpdated() {
+	_savedGifsUpdated.fire({});
+}
+
+rpl::producer<> Session::savedGifsUpdated() const {
+	return _savedGifsUpdated.events();
+}
+
+void Session::userIsContactUpdated(not_null<UserData*> user) {
+	const auto &items = App::sharedContactItems();
+	const auto i = items.constFind(peerToUser(user->id));
+	if (i != items.cend()) {
+		for (const auto item : std::as_const(i.value())) {
+			item->setPendingInitDimensions();
+		}
+	}
+}
+
+HistoryItemsList Session::idsToItems(
+		const MessageIdsList &ids) const {
+	return ranges::view::all(
+		ids
+	) | ranges::view::transform([](const FullMsgId &fullId) {
+		return App::histItemById(fullId);
+	}) | ranges::view::filter([](HistoryItem *item) {
+		return item != nullptr;
+	}) | ranges::view::transform([](HistoryItem *item) {
+		return not_null<HistoryItem*>(item);
+	}) | ranges::to_vector;
+}
+
+MessageIdsList Session::itemsToIds(
+		const HistoryItemsList &items) const {
+	return ranges::view::all(
+		items
+	) | ranges::view::transform([](not_null<HistoryItem*> item) {
+		return item->fullId();
+	}) | ranges::to_vector;
+}
+
+MessageIdsList Session::groupToIds(
+		not_null<HistoryMessageGroup*> group) const {
+	auto result = itemsToIds(group->others);
+	result.push_back(group->leader->fullId());
+	return result;
+}
+
+not_null<Data::Feed*> Session::feed(FeedId id) {
+	if (const auto result = feedLoaded(id)) {
+		return result;
+	}
+	const auto [it, ok] = _feeds.emplace(
+		id,
+		std::make_unique<Data::Feed>(id));
+	return it->second.get();
+}
+
+Data::Feed *Session::feedLoaded(FeedId id) {
+	const auto it = _feeds.find(id);
+	return (it == _feeds.end()) ? nullptr : it->second.get();
+}
+
+} // namespace Data
diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h
new file mode 100644
index 000000000..80ace497a
--- /dev/null
+++ b/Telegram/SourceFiles/data/data_session.h
@@ -0,0 +1,189 @@
+/*
+This file is part of Telegram Desktop,
+the official desktop application for the Telegram messaging service.
+
+For license and copyright information please follow this link:
+https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
+*/
+#pragma once
+
+#include "chat_helpers/stickers.h"
+
+namespace Data {
+
+class Feed;
+
+class Session final {
+public:
+	Session();
+	~Session();
+
+	base::Variable<bool> &contactsLoaded() {
+		return _contactsLoaded;
+	}
+	base::Variable<bool> &allChatsLoaded() {
+		return _allChatsLoaded;
+	}
+	base::Observable<void> &moreChatsLoaded() {
+		return _moreChatsLoaded;
+	}
+	base::Observable<void> &pendingHistoryResize() {
+		return _pendingHistoryResize;
+	}
+	struct ItemVisibilityQuery {
+		not_null<HistoryItem*> item;
+		not_null<bool*> isVisible;
+	};
+	base::Observable<ItemVisibilityQuery> &queryItemVisibility() {
+		return _queryItemVisibility;
+	}
+	void markItemLayoutChanged(not_null<const HistoryItem*> item);
+	rpl::producer<not_null<const HistoryItem*>> itemLayoutChanged() const;
+	void requestItemRepaint(not_null<const HistoryItem*> item);
+	rpl::producer<not_null<const HistoryItem*>> itemRepaintRequest() const;
+	void markItemRemoved(not_null<const HistoryItem*> item);
+	rpl::producer<not_null<const HistoryItem*>> itemRemoved() const;
+	void markHistoryUnloaded(not_null<const History*> history);
+	rpl::producer<not_null<const History*>> historyUnloaded() const;
+	void markHistoryCleared(not_null<const History*> history);
+	rpl::producer<not_null<const History*>> historyCleared() const;
+	using MegagroupParticipant = std::tuple<
+		not_null<ChannelData*>,
+		not_null<UserData*>>;
+	void removeMegagroupParticipant(
+		not_null<ChannelData*> channel,
+		not_null<UserData*> user);
+	rpl::producer<MegagroupParticipant> megagroupParticipantRemoved() const;
+	rpl::producer<not_null<UserData*>> megagroupParticipantRemoved(
+		not_null<ChannelData*> channel) const;
+	void addNewMegagroupParticipant(
+		not_null<ChannelData*> channel,
+		not_null<UserData*> user);
+	rpl::producer<MegagroupParticipant> megagroupParticipantAdded() const;
+	rpl::producer<not_null<UserData*>> megagroupParticipantAdded(
+		not_null<ChannelData*> channel) const;
+
+	void markStickersUpdated();
+	rpl::producer<> stickersUpdated() const;
+	void markSavedGifsUpdated();
+	rpl::producer<> savedGifsUpdated() const;
+
+	bool stickersUpdateNeeded(TimeMs now) const {
+		return stickersUpdateNeeded(_lastStickersUpdate, now);
+	}
+	void setLastStickersUpdate(TimeMs update) {
+		_lastStickersUpdate = update;
+	}
+	bool recentStickersUpdateNeeded(TimeMs now) const {
+		return stickersUpdateNeeded(_lastRecentStickersUpdate, now);
+	}
+	void setLastRecentStickersUpdate(TimeMs update) {
+		_lastRecentStickersUpdate = update;
+	}
+	bool favedStickersUpdateNeeded(TimeMs now) const {
+		return stickersUpdateNeeded(_lastFavedStickersUpdate, now);
+	}
+	void setLastFavedStickersUpdate(TimeMs update) {
+		_lastFavedStickersUpdate = update;
+	}
+	bool featuredStickersUpdateNeeded(TimeMs now) const {
+		return stickersUpdateNeeded(_lastFeaturedStickersUpdate, now);
+	}
+	void setLastFeaturedStickersUpdate(TimeMs update) {
+		_lastFeaturedStickersUpdate = update;
+	}
+	bool savedGifsUpdateNeeded(TimeMs now) const {
+		return stickersUpdateNeeded(_lastSavedGifsUpdate, now);
+	}
+	void setLastSavedGifsUpdate(TimeMs update) {
+		_lastSavedGifsUpdate = update;
+	}
+	int featuredStickerSetsUnreadCount() const {
+		return _featuredStickerSetsUnreadCount.current();
+	}
+	void setFeaturedStickerSetsUnreadCount(int count) {
+		_featuredStickerSetsUnreadCount = count;
+	}
+	rpl::producer<int> featuredStickerSetsUnreadCountValue() const {
+		return _featuredStickerSetsUnreadCount.value();
+	}
+	const Stickers::Sets &stickerSets() const {
+		return _stickerSets;
+	}
+	Stickers::Sets &stickerSetsRef() {
+		return _stickerSets;
+	}
+	const Stickers::Order &stickerSetsOrder() const {
+		return _stickerSetsOrder;
+	}
+	Stickers::Order &stickerSetsOrderRef() {
+		return _stickerSetsOrder;
+	}
+	const Stickers::Order &featuredStickerSetsOrder() const {
+		return _featuredStickerSetsOrder;
+	}
+	Stickers::Order &featuredStickerSetsOrderRef() {
+		return _featuredStickerSetsOrder;
+	}
+	const Stickers::Order &archivedStickerSetsOrder() const {
+		return _archivedStickerSetsOrder;
+	}
+	Stickers::Order &archivedStickerSetsOrderRef() {
+		return _archivedStickerSetsOrder;
+	}
+	const Stickers::SavedGifs &savedGifs() const {
+		return _savedGifs;
+	}
+	Stickers::SavedGifs &savedGifsRef() {
+		return _savedGifs;
+	}
+
+	HistoryItemsList idsToItems(const MessageIdsList &ids) const;
+	MessageIdsList itemsToIds(const HistoryItemsList &items) const;
+	MessageIdsList groupToIds(not_null<HistoryMessageGroup*> group) const;
+
+	not_null<Data::Feed*> feed(FeedId id);
+	Data::Feed *feedLoaded(FeedId id);
+
+private:
+	bool stickersUpdateNeeded(TimeMs lastUpdate, TimeMs now) const {
+		constexpr auto kStickersUpdateTimeout = TimeMs(3600'000);
+		return (lastUpdate == 0)
+			|| (now >= lastUpdate + kStickersUpdateTimeout);
+	}
+	void userIsContactUpdated(not_null<UserData*> user);
+
+	base::Variable<bool> _contactsLoaded = { false };
+	base::Variable<bool> _allChatsLoaded = { false };
+	base::Observable<void> _moreChatsLoaded;
+	base::Observable<void> _pendingHistoryResize;
+	base::Observable<ItemVisibilityQuery> _queryItemVisibility;
+	rpl::event_stream<not_null<const HistoryItem*>> _itemLayoutChanged;
+	rpl::event_stream<not_null<const HistoryItem*>> _itemRepaintRequest;
+	rpl::event_stream<not_null<const HistoryItem*>> _itemRemoved;
+	rpl::event_stream<not_null<const History*>> _historyUnloaded;
+	rpl::event_stream<not_null<const History*>> _historyCleared;
+	rpl::event_stream<MegagroupParticipant> _megagroupParticipantRemoved;
+	rpl::event_stream<MegagroupParticipant> _megagroupParticipantAdded;
+
+	rpl::event_stream<> _stickersUpdated;
+	rpl::event_stream<> _savedGifsUpdated;
+	TimeMs _lastStickersUpdate = 0;
+	TimeMs _lastRecentStickersUpdate = 0;
+	TimeMs _lastFavedStickersUpdate = 0;
+	TimeMs _lastFeaturedStickersUpdate = 0;
+	TimeMs _lastSavedGifsUpdate = 0;
+	rpl::variable<int> _featuredStickerSetsUnreadCount = 0;
+	Stickers::Sets _stickerSets;
+	Stickers::Order _stickerSetsOrder;
+	Stickers::Order _featuredStickerSetsOrder;
+	Stickers::Order _archivedStickerSetsOrder;
+	Stickers::SavedGifs _savedGifs;
+
+	base::flat_map<FeedId, std::unique_ptr<Data::Feed>> _feeds;
+
+	rpl::lifetime _lifetime;
+
+};
+
+} // namespace Data
diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp
index 8c5fec342..73efdbf0f 100644
--- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp
+++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp
@@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "ui/text_options.h"
 #include "data/data_drafts.h"
 #include "data/data_feed.h"
+#include "data/data_session.h"
 #include "lang/lang_keys.h"
 #include "mainwindow.h"
 #include "mainwidget.h"
diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp
index 2d5dd803a..27dc7ea54 100644
--- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp
+++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp
@@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "window/window_slide_animation.h"
 #include "profile/profile_channel_controllers.h"
 #include "storage/storage_media_prepare.h"
+#include "data/data_session.h"
 
 namespace {
 
diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp
index 98e8ee6bd..32acd562f 100644
--- a/Telegram/SourceFiles/facades.cpp
+++ b/Telegram/SourceFiles/facades.cpp
@@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "base/observer.h"
 #include "history/history_media.h"
 #include "styles/style_history.h"
+#include "data/data_session.h"
 
 Q_DECLARE_METATYPE(ClickHandlerPtr);
 Q_DECLARE_METATYPE(Qt::MouseButton);
diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp
index 48d7481a0..954c641fe 100644
--- a/Telegram/SourceFiles/history/history.cpp
+++ b/Telegram/SourceFiles/history/history.cpp
@@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "dialogs/dialogs_indexed_list.h"
 #include "styles/style_dialogs.h"
 #include "data/data_drafts.h"
+#include "data/data_session.h"
 #include "lang/lang_keys.h"
 #include "apiwrap.h"
 #include "mainwidget.h"
diff --git a/Telegram/SourceFiles/history/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/history_admin_log_inner.cpp
index 8901827ac..f44e8bc73 100644
--- a/Telegram/SourceFiles/history/history_admin_log_inner.cpp
+++ b/Telegram/SourceFiles/history/history_admin_log_inner.cpp
@@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "base/overload.h"
 #include "lang/lang_keys.h"
 #include "boxes/edit_participant_box.h"
+#include "data/data_session.h"
 
 namespace AdminLog {
 namespace {
@@ -214,7 +215,7 @@ InnerWidget::InnerWidget(
 		}
 	}, lifetime());
 	subscribe(Auth().data().pendingHistoryResize(), [this] { handlePendingHistoryResize(); });
-	subscribe(Auth().data().queryItemVisibility(), [this](const AuthSessionData::ItemVisibilityQuery &query) {
+	subscribe(Auth().data().queryItemVisibility(), [this](const Data::Session::ItemVisibilityQuery &query) {
 		if (_history != query.item->history() || !query.item->isLogEntry() || !isVisible()) {
 			return;
 		}
diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp
index 0f004101b..2297bdcd1 100644
--- a/Telegram/SourceFiles/history/history_inner_widget.cpp
+++ b/Telegram/SourceFiles/history/history_inner_widget.cpp
@@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "messenger.h"
 #include "apiwrap.h"
 #include "lang/lang_keys.h"
+#include "data/data_session.h"
 
 namespace {
 
diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp
index 65c120ffa..2db09e271 100644
--- a/Telegram/SourceFiles/history/history_item.cpp
+++ b/Telegram/SourceFiles/history/history_item.cpp
@@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "mainwindow.h"
 #include "window/window_controller.h"
 #include "core/crash_reports.h"
+#include "data/data_session.h"
 
 namespace {
 
diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp
index a4e4f2408..f1700d5bc 100644
--- a/Telegram/SourceFiles/history/history_media_types.cpp
+++ b/Telegram/SourceFiles/history/history_media_types.cpp
@@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "ui/empty_userpic.h"
 #include "ui/grouped_layout.h"
 #include "ui/text_options.h"
+#include "data/data_session.h"
 
 namespace {
 
diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp
index ea64928cc..b8e4eedb9 100644
--- a/Telegram/SourceFiles/history/history_message.cpp
+++ b/Telegram/SourceFiles/history/history_message.cpp
@@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "window/window_controller.h"
 #include "observer_peer.h"
 #include "storage/storage_shared_media.h"
+#include "data/data_session.h"
 
 namespace {
 
diff --git a/Telegram/SourceFiles/history/history_top_bar_widget.cpp b/Telegram/SourceFiles/history/history_top_bar_widget.cpp
index 24dfecf82..f67e1e37b 100644
--- a/Telegram/SourceFiles/history/history_top_bar_widget.cpp
+++ b/Telegram/SourceFiles/history/history_top_bar_widget.cpp
@@ -112,8 +112,8 @@ HistoryTopBarWidget::HistoryTopBarWidget(
 	});
 
 	rpl::combine(
-		Auth().data().thirdSectionInfoEnabledValue(),
-		Auth().data().tabbedReplacedWithInfoValue()
+		Auth().settings().thirdSectionInfoEnabledValue(),
+		Auth().settings().tabbedReplacedWithInfoValue()
 	) | rpl::start_with_next(
 		[this] { updateInfoToggleActive(); },
 		lifetime());
@@ -186,13 +186,13 @@ void HistoryTopBarWidget::showMenu() {
 
 void HistoryTopBarWidget::toggleInfoSection() {
 	if (Adaptive::ThreeColumn()
-		&& (Auth().data().thirdSectionInfoEnabled()
-			|| Auth().data().tabbedReplacedWithInfo())) {
+		&& (Auth().settings().thirdSectionInfoEnabled()
+			|| Auth().settings().tabbedReplacedWithInfo())) {
 		_controller->closeThirdSection();
 	} else if (_historyPeer) {
 		if (_controller->canShowThirdSection()) {
-			Auth().data().setThirdSectionInfoEnabled(true);
-			Auth().saveDataDelayed();
+			Auth().settings().setThirdSectionInfoEnabled(true);
+			Auth().saveSettingsDelayed();
 			if (Adaptive::ThreeColumn()) {
 				_controller->showSection(
 					Info::Memento::Default(_historyPeer),
@@ -598,8 +598,8 @@ void HistoryTopBarWidget::updateUnreadBadge() {
 
 void HistoryTopBarWidget::updateInfoToggleActive() {
 	auto infoThirdActive = Adaptive::ThreeColumn()
-		&& (Auth().data().thirdSectionInfoEnabled()
-			|| Auth().data().tabbedReplacedWithInfo());
+		&& (Auth().settings().thirdSectionInfoEnabled()
+			|| Auth().settings().tabbedReplacedWithInfo());
 	auto iconOverride = infoThirdActive
 		? &st::topBarInfoActive
 		: nullptr;
diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp
index 5b76aca2c..b8f26f1e3 100644
--- a/Telegram/SourceFiles/history/history_widget.cpp
+++ b/Telegram/SourceFiles/history/history_widget.cpp
@@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "ui/effects/ripple_animation.h"
 #include "inline_bots/inline_bot_result.h"
 #include "data/data_drafts.h"
+#include "data/data_session.h"
 #include "history/history_message.h"
 #include "history/history_service_layout.h"
 #include "history/history_media_types.h"
@@ -624,7 +625,7 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null<Window::Controller*> cont
 		}
 	}));
 	subscribe(Auth().data().pendingHistoryResize(), [this] { handlePendingHistoryUpdate(); });
-	subscribe(Auth().data().queryItemVisibility(), [this](const AuthSessionData::ItemVisibilityQuery &query) {
+	subscribe(Auth().data().queryItemVisibility(), [this](const Data::Session::ItemVisibilityQuery &query) {
 		if (_a_show.animating() || _history != query.item->history() || query.item->detached() || !isVisible()) {
 			return;
 		}
@@ -3736,11 +3737,11 @@ void HistoryWidget::pushTabbedSelectorToThirdSection(
 	if (!_history || !_tabbedPanel) {
 		return;
 	} else if (!_canSendMessages) {
-		Auth().data().setTabbedReplacedWithInfo(true);
+		Auth().settings().setTabbedReplacedWithInfo(true);
 		controller()->showPeerInfo(_peer, params.withThirdColumn());
 		return;
 	}
-	Auth().data().setTabbedReplacedWithInfo(false);
+	Auth().settings().setTabbedReplacedWithInfo(false);
 	_tabbedSelectorToggle->setColorOverrides(
 		&st::historyAttachEmojiActive,
 		&st::historyRecordVoiceFgActive,
@@ -3771,8 +3772,8 @@ void HistoryWidget::toggleTabbedSelectorMode() {
 	if (_tabbedPanel) {
 		if (controller()->canShowThirdSection()
 			&& !Adaptive::OneColumn()) {
-			Auth().data().setTabbedSelectorSectionEnabled(true);
-			Auth().saveDataDelayed();
+			Auth().settings().setTabbedSelectorSectionEnabled(true);
+			Auth().saveSettingsDelayed();
 			pushTabbedSelectorToThirdSection(
 				Window::SectionShow::Way::ClearStack);
 		} else {
diff --git a/Telegram/SourceFiles/info/info_layer_widget.cpp b/Telegram/SourceFiles/info/info_layer_widget.cpp
index a0bdcb4d6..bafc5215d 100644
--- a/Telegram/SourceFiles/info/info_layer_widget.cpp
+++ b/Telegram/SourceFiles/info/info_layer_widget.cpp
@@ -108,10 +108,10 @@ bool LayerWidget::takeToThirdSection() {
 	//// shrink the window size.
 	////
 	//// See https://github.com/telegramdesktop/tdesktop/issues/4091
-	//Auth().data().setThirdSectionExtendedBy(0);
+	//Auth().settings().setThirdSectionExtendedBy(0);
 
-	//Auth().data().setThirdSectionInfoEnabled(true);
-	//Auth().saveDataDelayed();
+	//Auth().settings().setThirdSectionInfoEnabled(true);
+	//Auth().saveSettingsDelayed();
 	//localCopy->showSection(
 	//	std::move(memento),
 	//	Window::SectionShow(
diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp
index be253ee8d..94cc362b2 100644
--- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp
+++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp
@@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "boxes/peer_list_controllers.h"
 #include "boxes/confirm_box.h"
 #include "core/file_utilities.h"
+#include "data/data_session.h"
 
 namespace Layout = Overview::Layout;
 
diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp
index bc24159b2..05d382baa 100644
--- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp
+++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp
@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 
 #include "data/data_photo.h"
 #include "data/data_document.h"
+#include "data/data_session.h"
 #include "styles/style_overview.h"
 #include "styles/style_history.h"
 #include "styles/style_chat_helpers.h"
diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp
index b35abe7c9..195f665e5 100644
--- a/Telegram/SourceFiles/mainwidget.cpp
+++ b/Telegram/SourceFiles/mainwidget.cpp
@@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "window/section_memento.h"
 #include "window/section_widget.h"
 #include "data/data_drafts.h"
+#include "data/data_session.h"
 #include "ui/widgets/dropdown_menu.h"
 #include "ui/focus_persister.h"
 #include "ui/resize_area.h"
@@ -222,9 +223,9 @@ MainWidget::MainWidget(
 		updateDialogsWidthAnimated();
 	});
 	rpl::merge(
-		Auth().data().dialogsWidthRatioChanges()
+		Auth().settings().dialogsWidthRatioChanges()
 			| rpl::map([] { return rpl::empty_value(); }),
-		Auth().data().thirdColumnWidthChanges()
+		Auth().settings().thirdColumnWidthChanges()
 			| rpl::map([] { return rpl::empty_value(); })
 	) | rpl::start_with_next(
 		[this] { updateControlsGeometry(); },
@@ -331,8 +332,8 @@ void MainWidget::checkCurrentFloatPlayer() {
 						}, [this](not_null<Float*> instance, bool closed) {
 							finishFloatPlayerDrag(instance, closed);
 						}));
-						currentFloatPlayer()->column = Auth().data().floatPlayerColumn();
-						currentFloatPlayer()->corner = Auth().data().floatPlayerCorner();
+						currentFloatPlayer()->column = Auth().settings().floatPlayerColumn();
+						currentFloatPlayer()->corner = Auth().settings().floatPlayerCorner();
 						checkFloatPlayerVisibility();
 					}
 				}
@@ -498,8 +499,8 @@ void MainWidget::updateFloatPlayerColumnCorner(QPoint center) {
 	Expects(!_playerFloats.empty());
 	auto size = _playerFloats.back()->widget->size();
 	auto min = INT_MAX;
-	auto column = Auth().data().floatPlayerColumn();
-	auto corner = Auth().data().floatPlayerCorner();
+	auto column = Auth().settings().floatPlayerColumn();
+	auto corner = Auth().settings().floatPlayerCorner();
 	auto checkSection = [this, center, size, &min, &column, &corner](
 			Window::AbstractSectionWidget *widget,
 			Window::Column widgetColumn) {
@@ -550,13 +551,13 @@ void MainWidget::updateFloatPlayerColumnCorner(QPoint center) {
 			checkSection(_dialogs, Window::Column::First);
 		}
 	}
-	if (Auth().data().floatPlayerColumn() != column) {
-		Auth().data().setFloatPlayerColumn(column);
-		Auth().saveDataDelayed();
+	if (Auth().settings().floatPlayerColumn() != column) {
+		Auth().settings().setFloatPlayerColumn(column);
+		Auth().saveSettingsDelayed();
 	}
-	if (Auth().data().floatPlayerCorner() != corner) {
-		Auth().data().setFloatPlayerCorner(corner);
-		Auth().saveDataDelayed();
+	if (Auth().settings().floatPlayerCorner() != corner) {
+		Auth().settings().setFloatPlayerCorner(corner);
+		Auth().saveSettingsDelayed();
 	}
 }
 
@@ -568,8 +569,8 @@ void MainWidget::finishFloatPlayerDrag(not_null<Float*> instance, bool closed) {
 		instance->animationSide = getFloatPlayerSide(center);
 	}
 	updateFloatPlayerColumnCorner(center);
-	instance->column = Auth().data().floatPlayerColumn();
-	instance->corner = Auth().data().floatPlayerCorner();
+	instance->column = Auth().settings().floatPlayerColumn();
+	instance->corner = Auth().settings().floatPlayerCorner();
 
 	instance->draggedAnimation.finish();
 	instance->draggedAnimation.start([this, instance] { updateFloatPlayerPosition(instance); }, 0., 1., st::slideDuration, anim::sineInOut);
@@ -3129,7 +3130,7 @@ void MainWidget::resizeEvent(QResizeEvent *e) {
 
 void MainWidget::updateControlsGeometry() {
 	updateWindowAdaptiveLayout();
-	if (Auth().data().dialogsWidthRatio() > 0) {
+	if (Auth().settings().dialogsWidthRatio() > 0) {
 		_a_dialogsWidth.finish();
 	}
 	if (!_a_dialogsWidth.animating()) {
@@ -3142,9 +3143,9 @@ void MainWidget::updateControlsGeometry() {
 				Window::SectionShow::Way::ClearStack,
 				anim::type::instant,
 				anim::activation::background);
-			if (Auth().data().tabbedSelectorSectionEnabled()) {
+			if (Auth().settings().tabbedSelectorSectionEnabled()) {
 				_history->pushTabbedSelectorToThirdSection(params);
-			} else if (Auth().data().thirdSectionInfoEnabled()) {
+			} else if (Auth().settings().thirdSectionInfoEnabled()) {
 				_history->pushInfoToThirdSection(params);
 			}
 		}
@@ -3266,14 +3267,14 @@ void MainWidget::ensureFirstColumnResizeAreaCreated() {
 		auto newRatio = (newWidth < st::columnMinimalWidthLeft / 2)
 			? 0.
 			: float64(newWidth) / width();
-		Auth().data().setDialogsWidthRatio(newRatio);
+		Auth().settings().setDialogsWidthRatio(newRatio);
 	};
 	auto moveFinishedCallback = [=] {
 		if (Adaptive::OneColumn()) {
 			return;
 		}
-		if (Auth().data().dialogsWidthRatio() > 0) {
-			Auth().data().setDialogsWidthRatio(
+		if (Auth().settings().dialogsWidthRatio() > 0) {
+			Auth().settings().setDialogsWidthRatio(
 				float64(_dialogsWidth) / width());
 		}
 		Local::writeUserSettings();
@@ -3290,14 +3291,14 @@ void MainWidget::ensureThirdColumnResizeAreaCreated() {
 	}
 	auto moveLeftCallback = [=](int globalLeft) {
 		auto newWidth = mapToGlobal(QPoint(width(), 0)).x() - globalLeft;
-		Auth().data().setThirdColumnWidth(newWidth);
+		Auth().settings().setThirdColumnWidth(newWidth);
 	};
 	auto moveFinishedCallback = [=] {
 		if (!Adaptive::ThreeColumn() || !_thirdSection) {
 			return;
 		}
-		Auth().data().setThirdColumnWidth(snap(
-			Auth().data().thirdColumnWidth(),
+		Auth().settings().setThirdColumnWidth(snap(
+			Auth().settings().thirdColumnWidth(),
 			st::columnMinimalWidthThird,
 			st::columnMaximalWidthThird));
 		Local::writeUserSettings();
@@ -3309,12 +3310,12 @@ void MainWidget::ensureThirdColumnResizeAreaCreated() {
 }
 
 void MainWidget::updateDialogsWidthAnimated() {
-	if (Auth().data().dialogsWidthRatio() > 0) {
+	if (Auth().settings().dialogsWidthRatio() > 0) {
 		return;
 	}
 	auto dialogsWidth = _dialogsWidth;
 	updateWindowAdaptiveLayout();
-	if (!Auth().data().dialogsWidthRatio()
+	if (!Auth().settings().dialogsWidthRatio()
 		&& (_dialogsWidth != dialogsWidth
 			|| _a_dialogsWidth.animating())) {
 		_dialogs->startWidthAnimation();
@@ -3366,9 +3367,9 @@ void MainWidget::updateThirdColumnToCurrentPeer(
 		// Like in _controller->showPeerInfo()
 		//
 		if (Adaptive::ThreeColumn()
-			&& !Auth().data().thirdSectionInfoEnabled()) {
-			Auth().data().setThirdSectionInfoEnabled(true);
-			Auth().saveDataDelayed();
+			&& !Auth().settings().thirdSectionInfoEnabled()) {
+			Auth().settings().setThirdSectionInfoEnabled(true);
+			Auth().saveSettingsDelayed();
 		}
 
 		_controller->showSection(
@@ -3380,18 +3381,18 @@ void MainWidget::updateThirdColumnToCurrentPeer(
 		_history->pushTabbedSelectorToThirdSection(params);
 	};
 	if (Adaptive::ThreeColumn()
-		&& Auth().data().tabbedSelectorSectionEnabled()
+		&& Auth().settings().tabbedSelectorSectionEnabled()
 		&& peer) {
 		if (!canWrite) {
 			switchInfoFast();
-			Auth().data().setTabbedSelectorSectionEnabled(true);
-			Auth().data().setTabbedReplacedWithInfo(true);
-		} else if (Auth().data().tabbedReplacedWithInfo()) {
-			Auth().data().setTabbedReplacedWithInfo(false);
+			Auth().settings().setTabbedSelectorSectionEnabled(true);
+			Auth().settings().setTabbedReplacedWithInfo(true);
+		} else if (Auth().settings().tabbedReplacedWithInfo()) {
+			Auth().settings().setTabbedReplacedWithInfo(false);
 			switchTabbedFast();
 		}
 	} else {
-		Auth().data().setTabbedReplacedWithInfo(false);
+		Auth().settings().setTabbedReplacedWithInfo(false);
 		if (!peer) {
 			if (_thirdSection) {
 				_thirdSection.destroy();
@@ -3399,7 +3400,7 @@ void MainWidget::updateThirdColumnToCurrentPeer(
 				updateControlsGeometry();
 			}
 		} else if (Adaptive::ThreeColumn()
-			&& Auth().data().thirdSectionInfoEnabled()) {
+			&& Auth().settings().thirdSectionInfoEnabled()) {
 			switchInfoFast();
 		}
 	}
@@ -3474,13 +3475,13 @@ void MainWidget::handleAdaptiveLayoutUpdate() {
 
 void MainWidget::updateWindowAdaptiveLayout() {
 	auto layout = _controller->computeColumnLayout();
-	auto dialogsWidthRatio = Auth().data().dialogsWidthRatio();
+	auto dialogsWidthRatio = Auth().settings().dialogsWidthRatio();
 
 	// Check if we are in a single-column layout in a wide enough window
 	// for the normal layout. If so, switch to the normal layout.
 	if (layout.windowLayout == Adaptive::WindowLayout::OneColumn) {
 		auto chatWidth = layout.chatWidth;
-		//if (Auth().data().tabbedSelectorSectionEnabled()
+		//if (Auth().settings().tabbedSelectorSectionEnabled()
 		//	&& chatWidth >= _history->minimalWidthForTabbedSelectorSection()) {
 		//	chatWidth -= _history->tabbedSelectorSectionWidth();
 		//}
@@ -3517,7 +3518,7 @@ void MainWidget::updateWindowAdaptiveLayout() {
 		//}
 	}
 
-	Auth().data().setDialogsWidthRatio(dialogsWidthRatio);
+	Auth().settings().setDialogsWidthRatio(dialogsWidthRatio);
 
 	auto useSmallColumnWidth = !Adaptive::OneColumn()
 		&& !dialogsWidthRatio
diff --git a/Telegram/SourceFiles/media/player/media_player_float.cpp b/Telegram/SourceFiles/media/player/media_player_float.cpp
index 5ef26a6d6..9184013e2 100644
--- a/Telegram/SourceFiles/media/player/media_player_float.cpp
+++ b/Telegram/SourceFiles/media/player/media_player_float.cpp
@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 
 #include <rpl/merge.h>
 #include "data/data_document.h"
+#include "data/data_session.h"
 #include "history/history_media.h"
 #include "media/media_clip_reader.h"
 #include "media/view/media_clip_playback.h"
diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp
index 276f7f395..4a974ab0d 100644
--- a/Telegram/SourceFiles/mediaview.cpp
+++ b/Telegram/SourceFiles/mediaview.cpp
@@ -1870,7 +1870,7 @@ void MediaView::onVideoPlayProgress(const AudioMsgId &audioId) {
 		if (state.length) {
 			updateVideoPlaybackState(state);
 		}
-		Auth().data().setLastTimeVideoPlayedAt(getms(true));
+		Auth().settings().setLastTimeVideoPlayedAt(getms(true));
 	}
 }
 
diff --git a/Telegram/SourceFiles/messenger.cpp b/Telegram/SourceFiles/messenger.cpp
index 9b490d99b..98ea9e02b 100644
--- a/Telegram/SourceFiles/messenger.cpp
+++ b/Telegram/SourceFiles/messenger.cpp
@@ -57,7 +57,7 @@ Messenger *Messenger::InstancePointer() {
 
 struct Messenger::Private {
 	UserId authSessionUserId = 0;
-	std::unique_ptr<AuthSessionData> storedAuthSession;
+	std::unique_ptr<AuthSessionSettings> storedAuthSession;
 	MTP::Instance::Config mtpConfig;
 	MTP::AuthKeysList mtpKeysToDestroy;
 	base::Timer quitTimer;
@@ -332,16 +332,18 @@ void Messenger::setAuthSessionUserId(UserId userId) {
 	_private->authSessionUserId = userId;
 }
 
-void Messenger::setAuthSessionFromStorage(std::unique_ptr<AuthSessionData> data) {
+void Messenger::setAuthSessionFromStorage(std::unique_ptr<AuthSessionSettings> data) {
 	Expects(!authSession());
 	_private->storedAuthSession = std::move(data);
 }
 
-AuthSessionData *Messenger::getAuthSessionData() {
+AuthSessionSettings *Messenger::getAuthSessionSettings() {
 	if (_private->authSessionUserId) {
-		return _private->storedAuthSession ? _private->storedAuthSession.get() : nullptr;
+		return _private->storedAuthSession
+			? _private->storedAuthSession.get()
+			: nullptr;
 	} else if (_authSession) {
-		return &_authSession->data();
+		return &_authSession->settings();
 	}
 	return nullptr;
 }
@@ -409,7 +411,7 @@ void Messenger::startMtp() {
 	}
 	if (_private->storedAuthSession) {
 		if (_authSession) {
-			_authSession->data().moveFrom(
+			_authSession->settings().moveFrom(
 				std::move(*_private->storedAuthSession));
 		}
 		_private->storedAuthSession.reset();
diff --git a/Telegram/SourceFiles/messenger.h b/Telegram/SourceFiles/messenger.h
index 65deee7ab..c9cf92b3b 100644
--- a/Telegram/SourceFiles/messenger.h
+++ b/Telegram/SourceFiles/messenger.h
@@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "base/timer.h"
 
 class AuthSession;
-class AuthSessionData;
+class AuthSessionSettings;
 class MainWidget;
 class FileUploader;
 class Translator;
@@ -103,8 +103,9 @@ public:
 	void setMtpMainDcId(MTP::DcId mainDcId);
 	void setMtpKey(MTP::DcId dcId, const MTP::AuthKey::Data &keyData);
 	void setAuthSessionUserId(UserId userId);
-	void setAuthSessionFromStorage(std::unique_ptr<AuthSessionData> data);
-	AuthSessionData *getAuthSessionData();
+	void setAuthSessionFromStorage(
+		std::unique_ptr<AuthSessionSettings> data);
+	AuthSessionSettings *getAuthSessionSettings();
 
 	// Serialization.
 	QByteArray serializeMtpAuthorization() const;
diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp
index 57a18368d..4602b488b 100644
--- a/Telegram/SourceFiles/overview/overview_layout.cpp
+++ b/Telegram/SourceFiles/overview/overview_layout.cpp
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "overview/overview_layout.h"
 
 #include "data/data_document.h"
+#include "data/data_session.h"
 #include "styles/style_overview.h"
 #include "styles/style_history.h"
 #include "core/file_utilities.h"
diff --git a/Telegram/SourceFiles/profile/profile_channel_controllers.cpp b/Telegram/SourceFiles/profile/profile_channel_controllers.cpp
index 258025891..354e7ed24 100644
--- a/Telegram/SourceFiles/profile/profile_channel_controllers.cpp
+++ b/Telegram/SourceFiles/profile/profile_channel_controllers.cpp
@@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "observer_peer.h"
 #include "dialogs/dialogs_indexed_list.h"
 #include "data/data_peer_values.h"
+#include "data/data_session.h"
 #include "ui/widgets/popup_menu.h"
 #include "window/window_controller.h"
 
diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp
index 291626333..7c879a258 100644
--- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp
+++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp
@@ -256,14 +256,14 @@ QString LastSeenPrivacyController::exceptionsDescription() {
 }
 
 void LastSeenPrivacyController::confirmSave(bool someAreDisallowed, base::lambda_once<void()> saveCallback) {
-	if (someAreDisallowed && !Auth().data().lastSeenWarningSeen()) {
+	if (someAreDisallowed && !Auth().settings().lastSeenWarningSeen()) {
 		auto weakBox = std::make_shared<QPointer<ConfirmBox>>();
 		auto callback = [weakBox, saveCallback = std::move(saveCallback)]() mutable {
 			if (auto box = *weakBox) {
 				box->closeBox();
 			}
 			saveCallback();
-			Auth().data().setLastSeenWarningSeen(true);
+			Auth().settings().setLastSeenWarningSeen(true);
 			Local::writeUserSettings();
 		};
 		auto box = Box<ConfirmBox>(lang(lng_edit_privacy_lastseen_warning), lang(lng_continue), lang(lng_cancel), std::move(callback));
diff --git a/Telegram/SourceFiles/settings/settings_widget.cpp b/Telegram/SourceFiles/settings/settings_widget.cpp
index 61fa70065..f17d3a866 100644
--- a/Telegram/SourceFiles/settings/settings_widget.cpp
+++ b/Telegram/SourceFiles/settings/settings_widget.cpp
@@ -131,7 +131,7 @@ void fillCodes() {
 					if (track->failed()) {
 						Ui::show(Box<InformBox>("Could not audio :( Errors in 'log.txt'."));
 					} else {
-						Auth().data().setSoundOverride(key, result.paths.front());
+						Auth().settings().setSoundOverride(key, result.paths.front());
 						Local::writeUserSettings();
 					}
 				}
@@ -140,7 +140,7 @@ void fillCodes() {
 	}
 	Codes.insert(qsl("sounds_reset"), [] {
 		if (AuthSession::Exists()) {
-			Auth().data().clearSoundOverrides();
+			Auth().settings().clearSoundOverrides();
 			Local::writeUserSettings();
 			Ui::show(Box<InformBox>("All sound overrides were reset."));
 		}
diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp
index 06e9796f0..285d838fe 100644
--- a/Telegram/SourceFiles/storage/localstorage.cpp
+++ b/Telegram/SourceFiles/storage/localstorage.cpp
@@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "auth_session.h"
 #include "window/window_controller.h"
 #include "base/flags.h"
+#include "data/data_session.h"
 
 #include <openssl/evp.h>
 
@@ -564,7 +565,7 @@ enum {
 	dbiDcOptions = 0x4a,
 	dbiMtpAuthorization = 0x4b,
 	dbiLastSeenWarningSeenOld = 0x4c,
-	dbiAuthSessionData = 0x4d,
+	dbiAuthSessionSettings = 0x4d,
 	dbiLangPackKey = 0x4e,
 	dbiConnectionType = 0x4f,
 	dbiStickersFavedLimit = 0x50,
@@ -634,10 +635,10 @@ enum class WriteMapWhen {
 	Soon,
 };
 
-std::unique_ptr<AuthSessionData> StoredAuthSessionCache;
-AuthSessionData &GetStoredAuthSessionCache() {
+std::unique_ptr<AuthSessionSettings> StoredAuthSessionCache;
+AuthSessionSettings &GetStoredAuthSessionCache() {
 	if (!StoredAuthSessionCache) {
-		StoredAuthSessionCache = std::make_unique<AuthSessionData>();
+		StoredAuthSessionCache = std::make_unique<AuthSessionSettings>();
 	}
 	return *StoredAuthSessionCache;
 }
@@ -1106,7 +1107,7 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
 		GetStoredAuthSessionCache().setLastSeenWarningSeen(v == 1);
 	} break;
 
-	case dbiAuthSessionData: {
+	case dbiAuthSessionSettings: {
 		QByteArray v;
 		stream >> v;
 		if (!_checkStreamStatus(stream)) return false;
@@ -1756,8 +1757,12 @@ void _writeUserSettings() {
 			recentEmojiPreloadData.push_back(qMakePair(item.first->id(), item.second));
 		}
 	}
-	auto userDataInstance = StoredAuthSessionCache ? StoredAuthSessionCache.get() : Messenger::Instance().getAuthSessionData();
-	auto userData = userDataInstance ? userDataInstance->serialize() : QByteArray();
+	auto userDataInstance = StoredAuthSessionCache
+		? StoredAuthSessionCache.get()
+		: Messenger::Instance().getAuthSessionSettings();
+	auto userData = userDataInstance
+		? userDataInstance->serialize()
+		: QByteArray();
 
 	uint32 size = 21 * (sizeof(quint32) + sizeof(qint32));
 	size += sizeof(quint32) + Serialize::stringSize(Global::AskDownloadPath() ? QString() : Global::DownloadPath()) + Serialize::bytearraySize(Global::AskDownloadPath() ? QByteArray() : Global::DownloadPathBookmark());
@@ -1803,7 +1808,7 @@ void _writeUserSettings() {
 	data.stream << quint32(dbiAutoPlay) << qint32(cAutoPlayGif() ? 1 : 0);
 	data.stream << quint32(dbiUseExternalVideoPlayer) << qint32(cUseExternalVideoPlayer());
 	if (!userData.isEmpty()) {
-		data.stream << quint32(dbiAuthSessionData) << userData;
+		data.stream << quint32(dbiAuthSessionSettings) << userData;
 	}
 
 	{
diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp
index 665154083..d8d44f6a6 100644
--- a/Telegram/SourceFiles/window/notifications_manager.cpp
+++ b/Telegram/SourceFiles/window/notifications_manager.cpp
@@ -364,7 +364,8 @@ void System::ensureSoundCreated() {
 	}
 
 	_soundTrack = Media::Audio::Current().createTrack();
-	_soundTrack->fillFromFile(Auth().data().getSoundPath(qsl("msg_incoming")));
+	_soundTrack->fillFromFile(
+		Auth().settings().getSoundPath(qsl("msg_incoming")));
 }
 
 void System::updateAll() {
diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp
index f34a11c27..e7e8f934d 100644
--- a/Telegram/SourceFiles/window/window_controller.cpp
+++ b/Telegram/SourceFiles/window/window_controller.cpp
@@ -84,8 +84,8 @@ Controller::ColumnLayout Controller::computeColumnLayout() const {
 		if (bodyWidth < minimalThreeColumnWidth()) {
 			return true;
 		}
-		if (!Auth().data().tabbedSelectorSectionEnabled()
-			&& !Auth().data().thirdSectionInfoEnabled()) {
+		if (!Auth().settings().tabbedSelectorSectionEnabled()
+			&& !Auth().settings().thirdSectionInfoEnabled()) {
 			return true;
 		}
 		return false;
@@ -115,14 +115,14 @@ Controller::ColumnLayout Controller::computeColumnLayout() const {
 }
 
 int Controller::countDialogsWidthFromRatio(int bodyWidth) const {
-	auto result = qRound(bodyWidth * Auth().data().dialogsWidthRatio());
+	auto result = qRound(bodyWidth * Auth().settings().dialogsWidthRatio());
 	accumulate_max(result, st::columnMinimalWidthLeft);
 //	accumulate_min(result, st::columnMaximalWidthLeft);
 	return result;
 }
 
 int Controller::countThirdColumnWidthFromRatio(int bodyWidth) const {
-	auto result = Auth().data().thirdColumnWidth();
+	auto result = Auth().settings().thirdColumnWidth();
 	accumulate_max(result, st::columnMinimalWidthThird);
 	accumulate_min(result, st::columnMaximalWidthThird);
 	return result;
@@ -175,11 +175,11 @@ void Controller::resizeForThirdSection() {
 
 	auto layout = computeColumnLayout();
 	auto tabbedSelectorSectionEnabled =
-		Auth().data().tabbedSelectorSectionEnabled();
+		Auth().settings().tabbedSelectorSectionEnabled();
 	auto thirdSectionInfoEnabled =
-		Auth().data().thirdSectionInfoEnabled();
-	Auth().data().setTabbedSelectorSectionEnabled(false);
-	Auth().data().setThirdSectionInfoEnabled(false);
+		Auth().settings().thirdSectionInfoEnabled();
+	Auth().settings().setTabbedSelectorSectionEnabled(false);
+	Auth().settings().setThirdSectionInfoEnabled(false);
 
 	auto wanted = countThirdColumnWidthFromRatio(layout.bodyWidth);
 	auto minimal = st::columnMinimalWidthThird;
@@ -200,20 +200,20 @@ void Controller::resizeForThirdSection() {
 		return window()->tryToExtendWidthBy(minimal);
 	}();
 	if (extendedBy) {
-		if (extendBy != Auth().data().thirdColumnWidth()) {
-			Auth().data().setThirdColumnWidth(extendBy);
+		if (extendBy != Auth().settings().thirdColumnWidth()) {
+			Auth().settings().setThirdColumnWidth(extendBy);
 		}
 		auto newBodyWidth = layout.bodyWidth + extendedBy;
-		auto currentRatio = Auth().data().dialogsWidthRatio();
-		Auth().data().setDialogsWidthRatio(
+		auto currentRatio = Auth().settings().dialogsWidthRatio();
+		Auth().settings().setDialogsWidthRatio(
 			(currentRatio * layout.bodyWidth) / newBodyWidth);
 	}
 	auto savedValue = (extendedBy == extendBy) ? -1 : extendedBy;
-	Auth().data().setThirdSectionExtendedBy(savedValue);
+	Auth().settings().setThirdSectionExtendedBy(savedValue);
 
-	Auth().data().setTabbedSelectorSectionEnabled(
+	Auth().settings().setTabbedSelectorSectionEnabled(
 		tabbedSelectorSectionEnabled);
-	Auth().data().setThirdSectionInfoEnabled(
+	Auth().settings().setThirdSectionInfoEnabled(
 		thirdSectionInfoEnabled);
 }
 
@@ -223,23 +223,23 @@ void Controller::closeThirdSection() {
 	if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn) {
 		auto noResize = window()->isFullScreen()
 			|| window()->isMaximized();
-		auto savedValue = Auth().data().thirdSectionExtendedBy();
+		auto savedValue = Auth().settings().thirdSectionExtendedBy();
 		auto extendedBy = (savedValue == -1)
 			? layout.thirdWidth
 			: savedValue;
 		auto newBodyWidth = noResize
 			? layout.bodyWidth
 			: (layout.bodyWidth - extendedBy);
-		auto currentRatio = Auth().data().dialogsWidthRatio();
-		Auth().data().setDialogsWidthRatio(
+		auto currentRatio = Auth().settings().dialogsWidthRatio();
+		Auth().settings().setDialogsWidthRatio(
 			(currentRatio * layout.bodyWidth) / newBodyWidth);
 		newWindowSize = QSize(
 			window()->width() + (newBodyWidth - layout.bodyWidth),
 			window()->height());
 	}
-	Auth().data().setTabbedSelectorSectionEnabled(false);
-	Auth().data().setThirdSectionInfoEnabled(false);
-	Auth().saveDataDelayed();
+	Auth().settings().setTabbedSelectorSectionEnabled(false);
+	Auth().settings().setThirdSectionInfoEnabled(false);
+	Auth().saveSettingsDelayed();
 	if (window()->size() != newWindowSize) {
 		window()->resize(newWindowSize);
 	} else {
@@ -358,9 +358,9 @@ void Navigation::showPeerInfo(
 		PeerId peerId,
 		const SectionShow &params) {
 	//if (Adaptive::ThreeColumn()
-	//	&& !Auth().data().thirdSectionInfoEnabled()) {
-	//	Auth().data().setThirdSectionInfoEnabled(true);
-	//	Auth().saveDataDelayed();
+	//	&& !Auth().settings().thirdSectionInfoEnabled()) {
+	//	Auth().settings().setThirdSectionInfoEnabled(true);
+	//	Auth().saveSettingsDelayed();
 	//}
 	showSection(Info::Memento(peerId), params);
 }
diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp
index ae80f62ac..c78cede73 100644
--- a/Telegram/SourceFiles/window/window_peer_menu.cpp
+++ b/Telegram/SourceFiles/window/window_peer_menu.cpp
@@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "observer_peer.h"
 #include "styles/style_boxes.h"
 #include "window/window_controller.h"
+#include "data/data_session.h"
 
 namespace Window {
 namespace {
@@ -94,8 +95,8 @@ bool Filler::showInfo() {
 	} else if (!Adaptive::ThreeColumn()) {
 		return true;
 	} else if (
-		!Auth().data().thirdSectionInfoEnabled() &&
-		!Auth().data().tabbedReplacedWithInfo()) {
+		!Auth().settings().thirdSectionInfoEnabled() &&
+		!Auth().settings().tabbedReplacedWithInfo()) {
 		return true;
 	}
 	return false;
diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt
index 6ea1aa201..ff87a9e78 100644
--- a/Telegram/gyp/telegram_sources.txt
+++ b/Telegram/gyp/telegram_sources.txt
@@ -181,6 +181,8 @@
 <(src_loc)/data/data_photo.h
 <(src_loc)/data/data_search_controller.cpp
 <(src_loc)/data/data_search_controller.h
+<(src_loc)/data/data_session.cpp
+<(src_loc)/data/data_session.h
 <(src_loc)/data/data_shared_media.cpp
 <(src_loc)/data/data_shared_media.h
 <(src_loc)/data/data_sparse_ids.cpp