/* 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 user) { userIsContactUpdated(user); }, _lifetime); } Session::~Session() = default; void Session::markItemLayoutChanged(not_null item) { _itemLayoutChanged.fire_copy(item); } rpl::producer> Session::itemLayoutChanged() const { return _itemLayoutChanged.events(); } void Session::requestItemRepaint(not_null item) { _itemRepaintRequest.fire_copy(item); } rpl::producer> Session::itemRepaintRequest() const { return _itemRepaintRequest.events(); } void Session::markItemRemoved(not_null item) { _itemRemoved.fire_copy(item); } rpl::producer> Session::itemRemoved() const { return _itemRemoved.events(); } void Session::markHistoryUnloaded(not_null history) { _historyUnloaded.fire_copy(history); } rpl::producer> Session::historyUnloaded() const { return _historyUnloaded.events(); } void Session::markHistoryCleared(not_null history) { _historyCleared.fire_copy(history); } rpl::producer> Session::historyCleared() const { return _historyCleared.events(); } void Session::removeMegagroupParticipant( not_null channel, not_null user) { _megagroupParticipantRemoved.fire({ channel, user }); } auto Session::megagroupParticipantRemoved() const -> rpl::producer { return _megagroupParticipantRemoved.events(); } rpl::producer> Session::megagroupParticipantRemoved( not_null 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 channel, not_null user) { _megagroupParticipantAdded.fire({ channel, user }); } auto Session::megagroupParticipantAdded() const -> rpl::producer { return _megagroupParticipantAdded.events(); } rpl::producer> Session::megagroupParticipantAdded( not_null 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 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(item); }) | ranges::to_vector; } MessageIdsList Session::itemsToIds( const HistoryItemsList &items) const { return ranges::view::all( items ) | ranges::view::transform([](not_null item) { return item->fullId(); }) | ranges::to_vector; } MessageIdsList Session::groupToIds( not_null group) const { auto result = itemsToIds(group->others); result.push_back(group->leader->fullId()); return result; } not_null Session::feed(FeedId id) { if (const auto result = feedLoaded(id)) { return result; } const auto [it, ok] = _feeds.emplace( id, std::make_unique(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