2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Allow reusing permissions edit controls.

This commit is contained in:
John Preston
2019-01-07 16:55:49 +04:00
parent 61419b57c8
commit f4d52b82b4
21 changed files with 1027 additions and 713 deletions

View File

@@ -26,8 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Info {
namespace Profile {
rpl::producer<TextWithEntities> NameValue(
not_null<PeerData*> peer) {
rpl::producer<TextWithEntities> NameValue(not_null<PeerData*> peer) {
return Notify::PeerUpdateValue(
peer,
Notify::PeerUpdate::Flag::NameChanged
@@ -36,8 +35,7 @@ rpl::producer<TextWithEntities> NameValue(
}) | WithEmptyEntities();
}
rpl::producer<TextWithEntities> PhoneValue(
not_null<UserData*> user) {
rpl::producer<TextWithEntities> PhoneValue(not_null<UserData*> user) {
return Notify::PeerUpdateValue(
user,
Notify::PeerUpdate::Flag::UserPhoneChanged
@@ -46,23 +44,20 @@ rpl::producer<TextWithEntities> PhoneValue(
}) | WithEmptyEntities();
}
auto PlainBioValue(
not_null<UserData*> user) {
auto PlainBioValue(not_null<UserData*> user) {
return Notify::PeerUpdateValue(
user,
Notify::PeerUpdate::Flag::AboutChanged
) | rpl::map([user] { return user->about(); });
}
rpl::producer<TextWithEntities> BioValue(
not_null<UserData*> user) {
rpl::producer<TextWithEntities> BioValue(not_null<UserData*> user) {
return PlainBioValue(user)
| ToSingleLine()
| WithEmptyEntities();
}
auto PlainUsernameValue(
not_null<PeerData*> peer) {
auto PlainUsernameValue(not_null<PeerData*> peer) {
return Notify::PeerUpdateValue(
peer,
Notify::PeerUpdate::Flag::UsernameChanged
@@ -71,8 +66,7 @@ auto PlainUsernameValue(
});
}
rpl::producer<TextWithEntities> UsernameValue(
not_null<UserData*> user) {
rpl::producer<TextWithEntities> UsernameValue(not_null<UserData*> user) {
return PlainUsernameValue(
user
) | rpl::map([](QString &&username) {
@@ -82,8 +76,7 @@ rpl::producer<TextWithEntities> UsernameValue(
}) | WithEmptyEntities();
}
rpl::producer<QString> PlainAboutValue(
not_null<PeerData*> peer) {
rpl::producer<QString> PlainAboutValue(not_null<PeerData*> peer) {
if (auto channel = peer->asChannel()) {
return Notify::PeerUpdateValue(
channel,
@@ -98,8 +91,7 @@ rpl::producer<QString> PlainAboutValue(
}
rpl::producer<TextWithEntities> AboutValue(
not_null<PeerData*> peer) {
rpl::producer<TextWithEntities> AboutValue(not_null<PeerData*> peer) {
auto flags = TextParseLinks
| TextParseMentions
| TextParseHashtags;
@@ -115,8 +107,7 @@ rpl::producer<TextWithEntities> AboutValue(
});
}
rpl::producer<QString> LinkValue(
not_null<PeerData*> peer) {
rpl::producer<QString> LinkValue(not_null<PeerData*> peer) {
return PlainUsernameValue(
peer
) | rpl::map([](QString &&username) {
@@ -126,8 +117,7 @@ rpl::producer<QString> LinkValue(
});
}
rpl::producer<bool> NotificationsEnabledValue(
not_null<PeerData*> peer) {
rpl::producer<bool> NotificationsEnabledValue(not_null<PeerData*> peer) {
return rpl::merge(
Notify::PeerUpdateValue(
peer,
@@ -139,16 +129,14 @@ rpl::producer<bool> NotificationsEnabledValue(
}) | rpl::distinct_until_changed();
}
rpl::producer<bool> IsContactValue(
not_null<UserData*> user) {
rpl::producer<bool> IsContactValue(not_null<UserData*> user) {
return Notify::PeerUpdateValue(
user,
Notify::PeerUpdate::Flag::UserIsContact
) | rpl::map([user] { return user->isContact(); });
}
rpl::producer<bool> CanInviteBotToGroupValue(
not_null<UserData*> user) {
rpl::producer<bool> CanInviteBotToGroupValue(not_null<UserData*> user) {
if (!user->botInfo) {
return rpl::single(false);
}
@@ -160,8 +148,7 @@ rpl::producer<bool> CanInviteBotToGroupValue(
});
}
rpl::producer<bool> CanShareContactValue(
not_null<UserData*> user) {
rpl::producer<bool> CanShareContactValue(not_null<UserData*> user) {
return Notify::PeerUpdateValue(
user,
Notify::PeerUpdate::Flag::UserCanShareContact
@@ -170,8 +157,7 @@ rpl::producer<bool> CanShareContactValue(
});
}
rpl::producer<bool> CanAddContactValue(
not_null<UserData*> user) {
rpl::producer<bool> CanAddContactValue(not_null<UserData*> user) {
using namespace rpl::mappers;
return rpl::combine(
IsContactValue(user),
@@ -179,17 +165,16 @@ rpl::producer<bool> CanAddContactValue(
!_1 && _2);
}
rpl::producer<bool> AmInChannelValue(
not_null<ChannelData*> channel) {
rpl::producer<bool> AmInChannelValue(not_null<ChannelData*> channel) {
return Notify::PeerUpdateValue(
channel,
Notify::PeerUpdate::Flag::ChannelAmIn
) | rpl::map([channel] { return channel->amIn(); });
}
rpl::producer<int> MembersCountValue(
not_null<PeerData*> peer) {
if (auto chat = peer->asChat()) {
rpl::producer<int> MembersCountValue(not_null<PeerData*> peer) {
using Flag = Notify::PeerUpdate::Flag;
if (const auto chat = peer->asChat()) {
return Notify::PeerUpdateValue(
peer,
Notify::PeerUpdate::Flag::MembersChanged
@@ -198,7 +183,7 @@ rpl::producer<int> MembersCountValue(
? std::max(chat->count, int(chat->participants.size()))
: 0;
});
} else if (auto channel = peer->asChannel()) {
} else if (const auto channel = peer->asChannel()) {
return Notify::PeerUpdateValue(
channel,
Notify::PeerUpdate::Flag::MembersChanged
@@ -209,21 +194,29 @@ rpl::producer<int> MembersCountValue(
Unexpected("User in MembersCountViewer().");
}
rpl::producer<int> AdminsCountValue(
not_null<ChannelData*> channel) {
rpl::producer<int> AdminsCountValue(not_null<PeerData*> peer) {
using Flag = Notify::PeerUpdate::Flag;
return Notify::PeerUpdateValue(
channel,
Flag::AdminsChanged | Flag::RightsChanged
) | rpl::map([=] {
return channel->canViewAdmins()
? channel->adminsCount()
: 0;
});
if (const auto chat = peer->asChat()) {
return Notify::PeerUpdateValue(
chat,
Flag::AdminsChanged | Flag::RightsChanged
) | rpl::map([=] {
return int(chat->admins.size());
});
} else if (const auto channel = peer->asChannel()) {
return Notify::PeerUpdateValue(
channel,
Flag::AdminsChanged | Flag::RightsChanged
) | rpl::map([=] {
return channel->canViewAdmins()
? channel->adminsCount()
: 0;
});
}
Unexpected("User in AdminsCountValue().");
}
rpl::producer<int> RestrictedCountValue(
not_null<ChannelData*> channel) {
rpl::producer<int> RestrictedCountValue(not_null<ChannelData*> channel) {
using Flag = Notify::PeerUpdate::Flag;
return Notify::PeerUpdateValue(
channel,
@@ -235,8 +228,7 @@ rpl::producer<int> RestrictedCountValue(
});
}
rpl::producer<int> KickedCountValue(
not_null<ChannelData*> channel) {
rpl::producer<int> KickedCountValue(not_null<ChannelData*> channel) {
using Flag = Notify::PeerUpdate::Flag;
return Notify::PeerUpdateValue(
channel,
@@ -269,8 +261,7 @@ rpl::producer<int> SharedMediaCountValue(
return rpl::single(0) | rpl::then(std::move(updated));
}
rpl::producer<int> CommonGroupsCountValue(
not_null<UserData*> user) {
rpl::producer<int> CommonGroupsCountValue(not_null<UserData*> user) {
return Notify::PeerUpdateValue(
user,
Notify::PeerUpdate::Flag::UserCommonChatsChanged
@@ -279,8 +270,7 @@ rpl::producer<int> CommonGroupsCountValue(
});
}
rpl::producer<bool> CanAddMemberValue(
not_null<PeerData*> peer) {
rpl::producer<bool> CanAddMemberValue(not_null<PeerData*> peer) {
if (auto chat = peer->asChat()) {
return Notify::PeerUpdateValue(
chat,
@@ -299,8 +289,7 @@ rpl::producer<bool> CanAddMemberValue(
return rpl::single(false);
}
rpl::producer<bool> VerifiedValue(
not_null<PeerData*> peer) {
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()) {
@@ -311,8 +300,7 @@ rpl::producer<bool> VerifiedValue(
return rpl::single(false);
}
rpl::producer<int> FeedChannelsCountValue(
not_null<Data::Feed*> feed) {
rpl::producer<int> FeedChannelsCountValue(not_null<Data::Feed*> feed) {
using Flag = Data::FeedUpdateFlag;
return rpl::single(
Data::FeedUpdate{ feed, Flag::Channels }
@@ -327,6 +315,5 @@ rpl::producer<int> FeedChannelsCountValue(
}) | rpl::distinct_until_changed();
}
} // namespace Profile
} // namespace Info