Add id-s only when displayed in profile.

This commit is contained in:
John Preston 2023-10-30 10:46:10 +04:00
parent 745ad45d47
commit f306b11676
5 changed files with 35 additions and 24 deletions

View File

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "info/profile/info_profile_actions.h"
#include "base/options.h"
#include "data/data_peer_values.h"
#include "data/data_session.h"
#include "data/data_folder.h"
@ -71,6 +72,12 @@ namespace Info {
namespace Profile {
namespace {
base::options::toggle ShowPeerIdBelowAbout({
.id = kOptionShowPeerIdBelowAbout,
.name = "Show Peer IDs in Profile",
.description = "Show peer IDs from API below their Bio / Description.",
});
[[nodiscard]] rpl::producer<TextWithEntities> UsernamesSubtext(
not_null<PeerData*> peer,
rpl::producer<QString> fallback) {
@ -131,6 +138,27 @@ namespace {
return result;
}
[[nodiscard]] rpl::producer<TextWithEntities> AboutWithIdValue(
not_null<PeerData*> peer) {
return AboutValue(
peer
) | rpl::map([=](TextWithEntities &&value) {
if (!ShowPeerIdBelowAbout.value()) {
return std::move(value);
}
using namespace Ui::Text;
if (!value.empty()) {
value.append("\n");
}
value.append(Italic(u"id: "_q));
const auto raw = peer->id.value & PeerId::kChatTypeMask;
const auto id = QString::number(raw);
value.append(Link(Italic(id), "internal:copy:" + id));
return std::move(value);
});
}
template <typename Text, typename ToggleOn, typename Callback>
auto AddActionButton(
not_null<Ui::VerticalLayout*> parent,
@ -406,8 +434,8 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
? tr::lng_info_about_label()
: tr::lng_info_bio_label();
addTranslateToMenu(
addInfoLine(std::move(label), AboutValue(user)).text,
AboutValue(user));
addInfoLine(std::move(label), AboutWithIdValue(user)).text,
AboutWithIdValue(user));
const auto usernameLine = addInfoOneLine(
UsernamesSubtext(_peer, tr::lng_info_username_label()),
@ -1028,6 +1056,8 @@ object_ptr<Ui::RpWidget> ActionsFiller::fill() {
} // namespace
const char kOptionShowPeerIdBelowAbout[] = "show-peer-id-below-about";
object_ptr<Ui::RpWidget> SetupDetails(
not_null<Controller*> controller,
not_null<Ui::RpWidget*> parent,

View File

@ -23,6 +23,8 @@ class Controller;
namespace Info::Profile {
extern const char kOptionShowPeerIdBelowAbout[];
object_ptr<Ui::RpWidget> SetupDetails(
not_null<Controller*> controller,
not_null<Ui::RpWidget*> parent,

View File

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "info/profile/info_profile_values.h"
#include "base/options.h"
#include "info/profile/info_profile_badge.h"
#include "core/application.h"
#include "core/click_handler_types.h"
@ -38,12 +37,6 @@ namespace {
using UpdateFlag = Data::PeerUpdate::Flag;
base::options::toggle ShowPeerIdBelowAbout({
.id = kOptionShowPeerIdBelowAbout,
.name = "Show Peer IDs in Profile",
.description = "Show peer IDs from API below their Bio / Description.",
});
auto PlainAboutValue(not_null<PeerData*> peer) {
return peer->session().changes().peerFlagsValue(
peer,
@ -94,8 +87,6 @@ void StripExternalLinks(TextWithEntities &text) {
} // namespace
const char kOptionShowPeerIdBelowAbout[] = "show-peer-id-below-about";
rpl::producer<QString> NameValue(not_null<PeerData*> peer) {
return peer->session().changes().peerFlagsValue(
peer,
@ -218,16 +209,6 @@ TextWithEntities AboutWithEntities(
if (stripExternal) {
StripExternalLinks(result);
}
if (ShowPeerIdBelowAbout.value()) {
using namespace Ui::Text;
if (!result.empty()) {
result.append("\n");
}
result.append(Italic(u"id: "_q));
const auto raw = peer->id.value & PeerId::kChatTypeMask;
const auto id = QString::number(raw);
result.append(Link(Italic(id), "internal:copy:" + id));
}
return result;
}

View File

@ -35,8 +35,6 @@ enum class SharedMediaType : signed char;
namespace Info::Profile {
extern const char kOptionShowPeerIdBelowAbout[];
inline auto ToSingleLine() {
return rpl::map([](const QString &text) {
return TextUtilities::SingleLine(text);

View File

@ -19,7 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/launcher.h"
#include "chat_helpers/tabbed_panel.h"
#include "dialogs/dialogs_widget.h"
#include "info/profile/info_profile_values.h"
#include "info/profile/info_profile_actions.h"
#include "lang/lang_keys.h"
#include "mainwindow.h"
#include "media/player/media_player_instance.h"