2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Move non-settings session data to Data::Session.

Rename AuthSessionData to AuthSessionSettings, move data away.
This commit is contained in:
John Preston
2018-01-04 13:22:53 +03:00
parent 724fe65d72
commit 6a9556d42c
51 changed files with 574 additions and 481 deletions

View File

@@ -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();