Improve bot About section in info profile.

This commit is contained in:
John Preston 2017-11-07 11:21:48 +04:00
parent 8191ebfc49
commit 4295a823c6
4 changed files with 43 additions and 7 deletions

View File

@ -155,7 +155,14 @@ void activateBotCommand(const HistoryItem *msg, int row, int col) {
}
void searchByHashtag(const QString &tag, PeerData *inPeer) {
if (MainWidget *m = main()) m->searchMessages(tag + ' ', (inPeer && inPeer->isChannel() && !inPeer->isMegagroup()) ? inPeer : 0);
if (MainWidget *m = main()) {
Ui::hideSettingsAndLayer();
Messenger::Instance().hideMediaView();
if (inPeer && (!inPeer->isChannel() || inPeer->isMegagroup())) {
inPeer = nullptr;
}
m->searchMessages(tag + ' ', inPeer);
}
}
void openPeerByName(const QString &username, MsgId msgId, const QString &startToken) {

View File

@ -180,7 +180,11 @@ object_ptr<Ui::RpWidget> InnerWidget::setupInfo(
};
if (auto user = _peer->asUser()) {
addInfoOneLine(lng_info_mobile_label, PhoneValue(user));
addInfoLine(lng_info_bio_label, BioValue(user));
if (user->botInfo) {
addInfoLine(lng_info_about_label, AboutValue(user));
} else {
addInfoLine(lng_info_bio_label, BioValue(user));
}
addInfoOneLine(lng_info_username_label, UsernameValue(user));
} else {
addInfoOneLine(lng_info_link_label, LinkValue(_peer));

View File

@ -44,16 +44,22 @@ rpl::producer<TextWithEntities> PhoneValue(
| WithEmptyEntities();
}
rpl::producer<TextWithEntities> BioValue(
auto PlainBioValue(
not_null<UserData*> user) {
return Notify::PeerUpdateValue(
user,
Notify::PeerUpdate::Flag::AboutChanged)
| rpl::map([user] { return user->about(); })
| rpl::map([user] { return user->about(); });
}
rpl::producer<TextWithEntities> BioValue(
not_null<UserData*> user) {
return PlainBioValue(user)
| ToSingleLine()
| WithEmptyEntities();
}
rpl::producer<QString> PlainUsernameViewer(
auto PlainUsernameValue(
not_null<PeerData*> peer) {
return Notify::PeerUpdateValue(
peer,
@ -65,7 +71,7 @@ rpl::producer<QString> PlainUsernameViewer(
rpl::producer<TextWithEntities> UsernameValue(
not_null<UserData*> user) {
return PlainUsernameViewer(user)
return PlainUsernameValue(user)
| rpl::map([](QString &&username) {
return username.isEmpty()
? QString()
@ -82,13 +88,26 @@ rpl::producer<TextWithEntities> AboutValue(
Notify::PeerUpdate::Flag::AboutChanged)
| rpl::map([channel] { return channel->about(); })
| WithEmptyEntities();
} else if (auto user = peer->asUser()) {
if (user->botInfo) {
return PlainBioValue(user)
| WithEmptyEntities()
| rpl::map([](TextWithEntities &&text) {
auto flags = TextParseLinks
| TextParseMentions
| TextParseHashtags
| TextParseBotCommands;
TextUtilities::ParseEntities(text, flags);
return std::move(text);
});
}
}
return rpl::single(TextWithEntities{});
}
rpl::producer<TextWithEntities> LinkValue(
not_null<PeerData*> peer) {
return PlainUsernameViewer(peer)
return PlainUsernameValue(peer)
| rpl::map([](QString &&username) {
return username.isEmpty()
? QString()

View File

@ -33,6 +33,12 @@ class SlideWrap;
namespace Info {
namespace Profile {
inline auto ToSingleLine() {
return rpl::map([](const QString &text) {
return TextUtilities::SingleLine(text);
});
}
inline auto WithEmptyEntities() {
return rpl::map([](QString &&text) {
return TextWithEntities{ std::move(text), {} };