2017-09-25 09:02:55 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-09-25 09:02:55 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-09-25 09:02:55 +00:00
|
|
|
*/
|
|
|
|
#include "info/profile/info_profile_values.h"
|
|
|
|
|
|
|
|
#include <rpl/filter.h>
|
|
|
|
#include <rpl/range.h>
|
|
|
|
#include <rpl/then.h>
|
|
|
|
#include <rpl/combine.h>
|
|
|
|
#include "observer_peer.h"
|
|
|
|
#include "messenger.h"
|
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2017-10-22 17:06:57 +00:00
|
|
|
#include "data/data_peer_values.h"
|
2017-11-06 07:31:18 +00:00
|
|
|
#include "data/data_shared_media.h"
|
2017-09-25 09:02:55 +00:00
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
namespace Profile {
|
|
|
|
|
|
|
|
rpl::producer<TextWithEntities> PhoneValue(
|
|
|
|
not_null<UserData*> user) {
|
2017-10-24 17:11:35 +00:00
|
|
|
return Notify::PeerUpdateValue(
|
2017-09-25 09:02:55 +00:00
|
|
|
user,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::UserPhoneChanged
|
|
|
|
) | rpl::map([user] {
|
|
|
|
return App::formatPhone(user->phone());
|
|
|
|
}) | WithEmptyEntities();
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 07:21:48 +00:00
|
|
|
auto PlainBioValue(
|
2017-09-25 09:02:55 +00:00
|
|
|
not_null<UserData*> user) {
|
2017-10-24 17:11:35 +00:00
|
|
|
return Notify::PeerUpdateValue(
|
2017-09-25 09:02:55 +00:00
|
|
|
user,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::AboutChanged
|
|
|
|
) | rpl::map([user] { return user->about(); });
|
2017-11-07 07:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<TextWithEntities> BioValue(
|
|
|
|
not_null<UserData*> user) {
|
|
|
|
return PlainBioValue(user)
|
|
|
|
| ToSingleLine()
|
2017-09-25 09:02:55 +00:00
|
|
|
| WithEmptyEntities();
|
|
|
|
}
|
|
|
|
|
2017-11-07 07:21:48 +00:00
|
|
|
auto PlainUsernameValue(
|
2017-09-25 09:02:55 +00:00
|
|
|
not_null<PeerData*> peer) {
|
2017-10-24 17:11:35 +00:00
|
|
|
return Notify::PeerUpdateValue(
|
2017-09-25 09:02:55 +00:00
|
|
|
peer,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::UsernameChanged
|
|
|
|
) | rpl::map([peer] {
|
|
|
|
return peer->userName();
|
|
|
|
});
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<TextWithEntities> UsernameValue(
|
|
|
|
not_null<UserData*> user) {
|
2017-12-22 07:05:20 +00:00
|
|
|
return PlainUsernameValue(
|
|
|
|
user
|
|
|
|
) | rpl::map([](QString &&username) {
|
|
|
|
return username.isEmpty()
|
|
|
|
? QString()
|
|
|
|
: ('@' + username);
|
|
|
|
}) | WithEmptyEntities();
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 07:42:53 +00:00
|
|
|
rpl::producer<QString> PlainAboutValue(
|
2017-09-25 09:02:55 +00:00
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
if (auto channel = peer->asChannel()) {
|
2017-10-24 17:11:35 +00:00
|
|
|
return Notify::PeerUpdateValue(
|
2017-09-25 09:02:55 +00:00
|
|
|
channel,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::AboutChanged
|
|
|
|
) | rpl::map([channel] { return channel->about(); });
|
2017-11-07 07:21:48 +00:00
|
|
|
} else if (auto user = peer->asUser()) {
|
|
|
|
if (user->botInfo) {
|
2017-11-17 07:42:53 +00:00
|
|
|
return PlainBioValue(user);
|
2017-11-07 07:21:48 +00:00
|
|
|
}
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
2017-11-17 07:42:53 +00:00
|
|
|
return rpl::single(QString());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rpl::producer<TextWithEntities> AboutValue(
|
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
auto flags = TextParseLinks
|
|
|
|
| TextParseMentions
|
|
|
|
| TextParseHashtags;
|
|
|
|
if (peer->isUser()) {
|
|
|
|
flags |= TextParseBotCommands;
|
|
|
|
}
|
2017-12-22 07:05:20 +00:00
|
|
|
return PlainAboutValue(
|
|
|
|
peer
|
|
|
|
) | WithEmptyEntities(
|
|
|
|
) | rpl::map([=](TextWithEntities &&text) {
|
|
|
|
TextUtilities::ParseEntities(text, flags);
|
|
|
|
return std::move(text);
|
|
|
|
});
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-10 17:51:59 +00:00
|
|
|
rpl::producer<QString> LinkValue(
|
2017-09-25 09:02:55 +00:00
|
|
|
not_null<PeerData*> peer) {
|
2017-12-22 07:05:20 +00:00
|
|
|
return PlainUsernameValue(
|
|
|
|
peer
|
|
|
|
) | rpl::map([](QString &&username) {
|
|
|
|
return username.isEmpty()
|
|
|
|
? QString()
|
|
|
|
: Messenger::Instance().createInternalLinkFull(username);
|
|
|
|
});
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> NotificationsEnabledValue(
|
|
|
|
not_null<PeerData*> peer) {
|
2017-10-24 17:11:35 +00:00
|
|
|
return Notify::PeerUpdateValue(
|
2017-09-25 09:02:55 +00:00
|
|
|
peer,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::NotificationsEnabled
|
|
|
|
) | rpl::map([peer] {
|
|
|
|
return !peer->isMuted();
|
|
|
|
}) | rpl::distinct_until_changed();
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> IsContactValue(
|
|
|
|
not_null<UserData*> user) {
|
2017-10-24 17:11:35 +00:00
|
|
|
return Notify::PeerUpdateValue(
|
2017-09-25 09:02:55 +00:00
|
|
|
user,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::UserIsContact
|
|
|
|
) | rpl::map([user] { return user->isContact(); });
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 11:53:05 +00:00
|
|
|
rpl::producer<bool> CanInviteBotToGroupValue(
|
|
|
|
not_null<UserData*> user) {
|
|
|
|
if (!user->botInfo) {
|
|
|
|
return rpl::single(false);
|
|
|
|
}
|
|
|
|
return Notify::PeerUpdateValue(
|
|
|
|
user,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::BotCanAddToGroups
|
|
|
|
) | rpl::map([user] {
|
|
|
|
return !user->botInfo->cantJoinGroups;
|
|
|
|
});
|
2017-11-07 11:53:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 09:02:55 +00:00
|
|
|
rpl::producer<bool> CanShareContactValue(
|
|
|
|
not_null<UserData*> user) {
|
2017-10-24 17:11:35 +00:00
|
|
|
return Notify::PeerUpdateValue(
|
2017-09-25 09:02:55 +00:00
|
|
|
user,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::UserCanShareContact
|
|
|
|
) | rpl::map([user] {
|
|
|
|
return user->canShareThisContact();
|
|
|
|
});
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> CanAddContactValue(
|
|
|
|
not_null<UserData*> user) {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
return rpl::combine(
|
|
|
|
IsContactValue(user),
|
|
|
|
CanShareContactValue(user),
|
2017-11-20 12:32:55 +00:00
|
|
|
!_1 && _2);
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-07 11:53:05 +00:00
|
|
|
rpl::producer<bool> AmInChannelValue(
|
|
|
|
not_null<ChannelData*> channel) {
|
|
|
|
return Notify::PeerUpdateValue(
|
|
|
|
channel,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::ChannelAmIn
|
|
|
|
) | rpl::map([channel] { return channel->amIn(); });
|
2017-11-07 11:53:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 09:02:55 +00:00
|
|
|
rpl::producer<int> MembersCountValue(
|
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
if (auto chat = peer->asChat()) {
|
2017-10-24 17:11:35 +00:00
|
|
|
return Notify::PeerUpdateValue(
|
2017-11-07 11:53:05 +00:00
|
|
|
peer,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::MembersChanged
|
|
|
|
) | rpl::map([chat] {
|
|
|
|
return chat->amIn()
|
|
|
|
? std::max(chat->count, int(chat->participants.size()))
|
|
|
|
: 0;
|
|
|
|
});
|
2017-09-25 09:02:55 +00:00
|
|
|
} else if (auto channel = peer->asChannel()) {
|
2017-11-10 19:19:43 +00:00
|
|
|
return Notify::PeerUpdateValue(
|
2017-10-24 17:11:35 +00:00
|
|
|
channel,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::MembersChanged
|
|
|
|
) | rpl::map([channel] {
|
|
|
|
return channel->membersCount();
|
|
|
|
});
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
Unexpected("User in MembersCountViewer().");
|
|
|
|
}
|
|
|
|
|
2017-11-08 16:45:30 +00:00
|
|
|
rpl::producer<int> AdminsCountValue(
|
|
|
|
not_null<ChannelData*> channel) {
|
|
|
|
using Flag = Notify::PeerUpdate::Flag;
|
|
|
|
return Notify::PeerUpdateValue(
|
|
|
|
channel,
|
2017-12-22 07:05:20 +00:00
|
|
|
Flag::AdminsChanged | Flag::ChannelRightsChanged
|
|
|
|
) | rpl::map([channel] {
|
|
|
|
return channel->canViewAdmins()
|
|
|
|
? channel->adminsCount()
|
|
|
|
: 0;
|
|
|
|
});
|
2017-11-08 16:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<int> RestrictedCountValue(
|
|
|
|
not_null<ChannelData*> channel) {
|
|
|
|
using Flag = Notify::PeerUpdate::Flag;
|
|
|
|
return Notify::PeerUpdateValue(
|
|
|
|
channel,
|
2017-12-22 07:05:20 +00:00
|
|
|
Flag::BannedUsersChanged | Flag::ChannelRightsChanged
|
|
|
|
) | rpl::map([channel] {
|
|
|
|
return channel->canViewBanned()
|
|
|
|
? channel->restrictedCount()
|
|
|
|
: 0;
|
|
|
|
});
|
2017-11-08 16:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<int> KickedCountValue(
|
|
|
|
not_null<ChannelData*> channel) {
|
|
|
|
using Flag = Notify::PeerUpdate::Flag;
|
|
|
|
return Notify::PeerUpdateValue(
|
|
|
|
channel,
|
2017-12-22 07:05:20 +00:00
|
|
|
Flag::BannedUsersChanged | Flag::ChannelRightsChanged
|
|
|
|
) | rpl::map([channel] {
|
|
|
|
return channel->canViewBanned()
|
|
|
|
? channel->kickedCount()
|
|
|
|
: 0;
|
|
|
|
});
|
2017-11-08 16:45:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 09:02:55 +00:00
|
|
|
rpl::producer<int> SharedMediaCountValue(
|
|
|
|
not_null<PeerData*> peer,
|
2017-10-31 18:25:22 +00:00
|
|
|
PeerData *migrated,
|
2017-09-25 09:02:55 +00:00
|
|
|
Storage::SharedMediaType type) {
|
|
|
|
auto aroundId = 0;
|
|
|
|
auto limit = 0;
|
|
|
|
auto updated = SharedMediaMergedViewer(
|
2017-10-29 15:32:01 +00:00
|
|
|
SharedMediaMergedKey(
|
|
|
|
SparseIdsMergedSlice::Key(
|
2017-10-31 18:25:22 +00:00
|
|
|
peer->id,
|
2017-10-29 15:32:01 +00:00
|
|
|
migrated ? migrated->id : 0,
|
|
|
|
aroundId),
|
|
|
|
type),
|
2017-09-25 09:02:55 +00:00
|
|
|
limit,
|
2017-12-22 07:05:20 +00:00
|
|
|
limit
|
|
|
|
) | rpl::map([](const SparseIdsMergedSlice &slice) {
|
|
|
|
return slice.fullCount();
|
|
|
|
}) | rpl::filter_optional();
|
2017-09-25 09:02:55 +00:00
|
|
|
return rpl::single(0) | rpl::then(std::move(updated));
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<int> CommonGroupsCountValue(
|
|
|
|
not_null<UserData*> user) {
|
2017-10-24 17:11:35 +00:00
|
|
|
return Notify::PeerUpdateValue(
|
2017-09-25 09:02:55 +00:00
|
|
|
user,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::UserCommonChatsChanged
|
|
|
|
) | rpl::map([user] {
|
|
|
|
return user->commonChatsCount();
|
|
|
|
});
|
2017-09-25 09:02:55 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 16:06:53 +00:00
|
|
|
rpl::producer<bool> CanAddMemberValue(
|
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
if (auto chat = peer->asChat()) {
|
2017-10-24 17:11:35 +00:00
|
|
|
return Notify::PeerUpdateValue(
|
2017-09-25 16:06:53 +00:00
|
|
|
chat,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::ChatCanEdit
|
|
|
|
) | rpl::map([chat] {
|
|
|
|
return chat->canEdit();
|
|
|
|
});
|
2017-09-25 16:06:53 +00:00
|
|
|
} else if (auto channel = peer->asChannel()) {
|
2017-10-24 17:11:35 +00:00
|
|
|
return Notify::PeerUpdateValue(
|
2017-09-25 16:06:53 +00:00
|
|
|
channel,
|
2017-12-22 07:05:20 +00:00
|
|
|
Notify::PeerUpdate::Flag::ChannelRightsChanged
|
|
|
|
) | rpl::map([channel] {
|
|
|
|
return channel->canAddMembers();
|
|
|
|
});
|
2017-09-25 16:06:53 +00:00
|
|
|
}
|
|
|
|
return rpl::single(false);
|
|
|
|
}
|
|
|
|
|
2017-11-06 14:13:56 +00:00
|
|
|
rpl::producer<bool> VerifiedValue(
|
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
if (auto user = peer->asUser()) {
|
|
|
|
return Data::PeerFlagValue(user, MTPDuser::Flag::f_verified);
|
|
|
|
} else if (auto channel = peer->asChannel()) {
|
|
|
|
return Data::PeerFlagValue(
|
|
|
|
channel,
|
|
|
|
MTPDchannel::Flag::f_verified);
|
|
|
|
}
|
|
|
|
return rpl::single(false);
|
|
|
|
}
|
|
|
|
|
2017-09-25 09:02:55 +00:00
|
|
|
} // namespace Profile
|
|
|
|
} // namespace Info
|