/* This file is part of Telegram Desktop, the official desktop version of Telegram messaging app, see https://telegram.org Telegram Desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. In addition, as a special exception, the copyright holders give permission to link the code of portions of this program with the OpenSSL library. Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #include "info/profile/info_profile_values.h" #include #include #include #include #include "observer_peer.h" #include "messenger.h" #include "ui/wrap/slide_wrap.h" #include "data/data_peer_values.h" #include "data/data_shared_media.h" namespace Info { namespace Profile { rpl::producer PhoneValue( not_null user) { return Notify::PeerUpdateValue( user, Notify::PeerUpdate::Flag::UserPhoneChanged) | rpl::map([user] { return App::formatPhone(user->phone()); }) | WithEmptyEntities(); } rpl::producer BioValue( not_null user) { return Notify::PeerUpdateValue( user, Notify::PeerUpdate::Flag::AboutChanged) | rpl::map([user] { return user->about(); }) | WithEmptyEntities(); } rpl::producer PlainUsernameViewer( not_null peer) { return Notify::PeerUpdateValue( peer, Notify::PeerUpdate::Flag::UsernameChanged) | rpl::map([peer] { return peer->userName(); }); } rpl::producer UsernameValue( not_null user) { return PlainUsernameViewer(user) | rpl::map([](QString &&username) { return username.isEmpty() ? QString() : ('@' + username); }) | WithEmptyEntities(); } rpl::producer AboutValue( not_null peer) { if (auto channel = peer->asChannel()) { return Notify::PeerUpdateValue( channel, Notify::PeerUpdate::Flag::AboutChanged) | rpl::map([channel] { return channel->about(); }) | WithEmptyEntities(); } return rpl::single(TextWithEntities{}); } rpl::producer LinkValue( not_null peer) { return PlainUsernameViewer(peer) | rpl::map([](QString &&username) { return username.isEmpty() ? QString() : Messenger::Instance().createInternalLink(username); }) | WithEmptyEntities(); } rpl::producer NotificationsEnabledValue( not_null peer) { return Notify::PeerUpdateValue( peer, Notify::PeerUpdate::Flag::NotificationsEnabled) | rpl::map([peer] { return !peer->isMuted(); }); } rpl::producer IsContactValue( not_null user) { return Notify::PeerUpdateValue( user, Notify::PeerUpdate::Flag::UserIsContact) | rpl::map([user] { return user->isContact(); }); } rpl::producer CanShareContactValue( not_null user) { return Notify::PeerUpdateValue( user, Notify::PeerUpdate::Flag::UserCanShareContact) | rpl::map([user] { return user->canShareThisContact(); }); } rpl::producer CanAddContactValue( not_null user) { using namespace rpl::mappers; return rpl::combine( IsContactValue(user), CanShareContactValue(user), !$1 && $2); } rpl::producer MembersCountValue( not_null peer) { if (auto chat = peer->asChat()) { return Notify::PeerUpdateValue( peer, Notify::PeerUpdate::Flag::MembersChanged) | rpl::map([chat] { return chat->amIn() ? qMax(chat->count, chat->participants.size()) : 0; }); } else if (auto channel = peer->asChannel()) { return rpl::combine( Notify::PeerUpdateValue( channel, Notify::PeerUpdate::Flag::MembersChanged), Data::PeerFullFlagValue( channel, MTPDchannelFull::Flag::f_can_view_participants)) | rpl::map([channel] { auto canViewCount = channel->canViewMembers() || !channel->isMegagroup(); return canViewCount ? qMax(channel->membersCount(), 1) : 0; }); } Unexpected("User in MembersCountViewer()."); } rpl::producer SharedMediaCountValue( not_null peer, PeerData *migrated, Storage::SharedMediaType type) { auto aroundId = 0; auto limit = 0; auto updated = SharedMediaMergedViewer( SharedMediaMergedKey( SparseIdsMergedSlice::Key( peer->id, migrated ? migrated->id : 0, aroundId), type), limit, limit) | rpl::map([](const SparseIdsMergedSlice &slice) { return slice.fullCount(); }) | rpl::filter_optional(); return rpl::single(0) | rpl::then(std::move(updated)); } rpl::producer CommonGroupsCountValue( not_null user) { return Notify::PeerUpdateValue( user, Notify::PeerUpdate::Flag::UserCommonChatsChanged) | rpl::map([user] { return user->commonChatsCount(); }); } rpl::producer CanAddMemberValue( not_null peer) { if (auto chat = peer->asChat()) { return Notify::PeerUpdateValue( chat, Notify::PeerUpdate::Flag::ChatCanEdit) | rpl::map([chat] { return chat->canEdit(); }); } else if (auto channel = peer->asChannel()) { return Notify::PeerUpdateValue( channel, Notify::PeerUpdate::Flag::ChannelRightsChanged) | rpl::map([channel] { return channel->canAddMembers(); }); } return rpl::single(false); } } // namespace Profile } // namespace Info