Skip to content

Commit f76d2ec

Browse files
Merge pull request #738 from redjex/show-peer-ids
Add an option to show peer IDs in profiles
2 parents 6011b97 + ed33499 commit f76d2ec

8 files changed

Lines changed: 88 additions & 2 deletions

File tree

‎src/components/peerProfile.tsx‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {useChat, usePeer} from '@stores/peers';
88
import {BusinessWorkHours, Chat, ChatFull, GeoPoint, GroupCall, HelpTimezonesList, InputGroupCall, Photo, StoryItem, Document, MessageMedia, Timezone, User, UserFull, UserStatus} from '@layer';
99
import getAudioTitles from '@appManagers/utils/docs/getAudioTitles';
1010
import {useFullPeer} from '@stores/fullPeers';
11+
import {appSettings} from '@stores/appSettings';
12+
import getPeerPhoto from '@appManagers/utils/peers/getPeerPhoto';
1113
import {useHotReloadGuard} from '@lib/solidjs/hotReloadGuard';
1214
import {bindManagersToSession} from '@lib/accounts/bindManagersToAccount';
1315
import createMiddleware from '@helpers/solid/createMiddleware';
@@ -18,7 +20,7 @@ import classNames from '@helpers/string/classNames';
1820
import Row from '@components/rowTsx';
1921
import formatUserPhone from '@components/wrappers/formatUserPhone';
2022
import {copyTextToClipboard} from '@helpers/clipboard';
21-
import {copyPhoneNumber, copyUsername} from '@helpers/copyContact';
23+
import {copyPeerId, copyPhoneNumber, copyUsername} from '@helpers/copyContact';
2224
import safeWindowOpen from '@helpers/dom/safeWindowOpen';
2325
import anchorCopy from '@helpers/dom/anchorCopy';
2426
import getServerMessageId from '@appManagers/utils/messageId/getServerMessageId';
@@ -965,6 +967,50 @@ PeerProfile.ContactNote = () => {
965967
);
966968
};
967969

970+
PeerProfile.PeerId = () => {
971+
const context = useContext(PeerProfileContext);
972+
const {i18n} = useHotReloadGuard();
973+
const peerId = createMemo(() => {
974+
if(!appSettings.showPeerIds || !context.canBeDetailed() || context.isTopic) {
975+
return;
976+
}
977+
978+
return '' + Math.abs(context.peerId);
979+
});
980+
981+
const dcId = createMemo(() => {
982+
const photo = getPeerPhoto(context.peer as User | Chat);
983+
if(photo?._ === 'userProfilePhoto' && photo.pFlags.personal) {
984+
return ((context.fullPeer as UserFull.userFull)?.profile_photo as Photo.photo)?.dc_id;
985+
}
986+
987+
return photo?.dc_id;
988+
});
989+
990+
const onClick = () => copyPeerId(peerId());
991+
992+
return (
993+
<Show when={peerId()}>
994+
<Row
995+
clickable={onClick}
996+
contextMenu={{
997+
buttons: [{
998+
icon: 'copy',
999+
text: 'Text.CopyLabel_Id',
1000+
onClick
1001+
}]
1002+
}}
1003+
>
1004+
<Row.Icon icon="tag_alt_filled" text="ID" />
1005+
<Row.Title><span dir="ltr">{peerId()}</span></Row.Title>
1006+
<Row.Subtitle subtitleRight={dcId() && i18n('PeerInfo.DataCenter', [dcId()])}>
1007+
{i18n('PeerInfo.Id')}
1008+
</Row.Subtitle>
1009+
</Row>
1010+
</Show>
1011+
);
1012+
};
1013+
9681014
PeerProfile.Location = () => {
9691015
const context = useContext(PeerProfileContext);
9701016
const {i18n} = useHotReloadGuard();
@@ -2018,6 +2064,7 @@ PeerProfile.MainSection = () => {
20182064
<PeerProfile.Username />
20192065
<PeerProfile.Location />
20202066
<PeerProfile.Bio />
2067+
<PeerProfile.PeerId />
20212068
<PeerProfile.Link />
20222069
<PeerProfile.Birthday />
20232070
<PeerProfile.ContactNote />

‎src/components/rowTsx.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ Row.Subtitle = (props: {
418418

419419
Row.Icon = (props: {
420420
icon: Icon,
421+
text?: string,
421422
class?: string,
422423
noBackground?: boolean
423424
}) => {
@@ -433,7 +434,9 @@ Row.Icon = (props: {
433434
'background-image': getRowIconBackgroundImage(props.icon)
434435
}}
435436
>
436-
<IconTsx icon={props.icon} class="row-icon-icon" />
437+
{props.text ?
438+
<span class="row-icon-text">{props.text}</span> :
439+
<IconTsx icon={props.icon} class="row-icon-icon" />}
437440
</span>
438441
));
439442
};

‎src/components/sidebarLeft/tabs/generalSettings.tsx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,28 @@ const TimeFormatSection = () => {
348348
// Tab root
349349
// ─────────────────────────────────────────────────────────────────────────────
350350

351+
const PeerIdsSection = () => {
352+
return (
353+
<Section>
354+
<Row>
355+
<Row.CheckboxFieldToggle>
356+
<CheckboxFieldTsx stateKey={joinDeepPath('settings', 'showPeerIds')} toggle />
357+
</Row.CheckboxFieldToggle>
358+
<Row.Title>{i18n('GeneralSettings.ShowPeerIds')}</Row.Title>
359+
<Row.Subtitle>{i18n('GeneralSettings.ShowPeerIdsInfo')}</Row.Subtitle>
360+
</Row>
361+
</Section>
362+
);
363+
};
364+
351365
const GeneralSettings = () => {
352366
return (
353367
<>
354368
<SettingsSection />
355369
<ThemeSection />
356370
{IS_GEOLOCATION_SUPPORTED && <DistanceUnitsSection />}
357371
<TimeFormatSection />
372+
<PeerIdsSection />
358373
</>
359374
);
360375
};

‎src/config/state.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export type StateSettings = {
128128
savedAsForum: boolean,
129129
notifyAllAccounts: boolean,
130130
tabsInSidebar: boolean,
131+
showPeerIds: boolean,
131132
/** Ids of the settings-search results picked last, most recent first. */
132133
settingsSearchRecent: string[],
133134
seenTooltips: {
@@ -558,6 +559,7 @@ export const SETTINGS_INIT: StateSettings = {
558559
savedAsForum: false,
559560
notifyAllAccounts: true,
560561
tabsInSidebar: false,
562+
showPeerIds: false,
561563
settingsSearchRecent: [],
562564
playbackParams: {
563565
volume: 1,

‎src/helpers/copyContact.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ export function copyPhoneNumber(phone: string) {
2525
copyTextToClipboard(phone.replace(/\s/g, ''));
2626
toastNew({langPackKey: 'PhoneCopied'});
2727
}
28+
29+
export function copyPeerId(id: string) {
30+
copyTextToClipboard(id);
31+
toastNew({langPackKey: 'IdCopied'});
32+
}

‎src/lang.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,7 @@ const lang = {
19241924
'ContactDetails.Organization': 'Organization',
19251925
'ContactDetails.Name': 'Name',
19261926
'UsernameCopied': 'Username copied to clipboard.',
1927+
'IdCopied': 'ID copied to clipboard.',
19271928
// "HashtagCopied": "Hashtag copied to clipboard.",
19281929
'BioCopied': 'Bio copied to clipboard.',
19291930
'UserBio': 'Bio',
@@ -4951,11 +4952,17 @@ const lang = {
49514952
'Text.CopyLabel_Username': 'Copy Username',
49524953
'Text.CopyLabel_ShareLink': 'Copy Share Link',
49534954
'Text.CopyLabel_Note': 'Copy Note',
4955+
'Text.CopyLabel_Id': 'Copy ID',
49544956
'GeneralSettings.BigEmoji': 'Large Emoji',
49554957
'GeneralSettings.EmojiPrediction': 'Suggest Emoji',
49564958
'GeneralSettings.IncreaseContrast': 'Increase Contrast',
49574959
'GeneralSettings.IncreaseContrastInfo': 'Make text and buttons easier to see.',
49584960
'GeneralSettings.IncreaseContrast.SearchKeywords': 'accessibility, a11y, high contrast, readability, colors',
4961+
'GeneralSettings.ShowPeerIds': 'Show Peer IDs',
4962+
'GeneralSettings.ShowPeerIdsInfo': 'Show the ID and data center of users, bots, groups and channels in their profiles.',
4963+
'GeneralSettings.ShowPeerIds.SearchKeywords': 'id, user id, chat id, channel id, dc, data center, developer',
4964+
'PeerInfo.Id': 'ID',
4965+
'PeerInfo.DataCenter': 'DC %d',
49594966
'GroupPermission.Delete': 'Delete Exception',
49604967
'Search.Confirm.ClearHistory': 'Are you sure you want to clear your search history?',
49614968
'SecureId.Identity.Placeholder.ExpiryDate': 'Expiry Date',

‎src/lib/settingsSearch/generated.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ const generated: GeneratedSettingsSearchData = {
202202
{id: 'AppGeneralSettingsTab:General.TimeFormat.h12', sectionId: 'AppGeneralSettingsTab', kind: 'option', titleLangKey: 'General.TimeFormat.h12'},
203203
{id: 'AppGeneralSettingsTab:General.TimeFormat.h23', sectionId: 'AppGeneralSettingsTab', kind: 'option', titleLangKey: 'General.TimeFormat.h23'},
204204
{id: 'AppGeneralSettingsTab:GeneralSettings.IncreaseContrast', sectionId: 'AppGeneralSettingsTab', kind: 'toggle', titleLangKey: 'GeneralSettings.IncreaseContrast'},
205+
{id: 'AppGeneralSettingsTab:GeneralSettings.ShowPeerIds', sectionId: 'AppGeneralSettingsTab', kind: 'toggle', titleLangKey: 'GeneralSettings.ShowPeerIds'},
205206
{id: 'AppGeneralSettingsTab:LiteMode.EnableText', sectionId: 'AppGeneralSettingsTab', kind: 'row', titleLangKey: 'LiteMode.EnableText'},
206207
{id: 'AppGeneralSettingsTab:Settings', sectionId: 'AppGeneralSettingsTab', kind: 'subsection', titleLangKey: 'Settings'},
207208
{id: 'AppGeneralSettingsTab:TextSize', sectionId: 'AppGeneralSettingsTab', kind: 'row', titleLangKey: 'TextSize'},

‎src/scss/partials/_row.scss‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ $row-border-radius: $border-radius-medium;
267267
color: #fff;
268268
}
269269

270+
&-text {
271+
font-size: .875rem;
272+
font-weight: var(--font-weight-bold);
273+
letter-spacing: .02em;
274+
}
275+
270276
&-premium-color {
271277
color: var(--primary-color);
272278
}

0 commit comments

Comments
 (0)