feat(profile): show real telegram avatars in messenger chips

This commit is contained in:
Ruslan Bakiev
2026-04-03 18:36:25 +07:00
parent f2fb64a0b7
commit f941ba7192
9 changed files with 267 additions and 51 deletions

View File

@@ -152,11 +152,14 @@ export enum LoginChannel {
export type MessengerConnection = {
__typename?: 'MessengerConnection';
avatarAvailable: Scalars['Boolean']['output'];
channelId: Scalars['String']['output'];
displayName?: Maybe<Scalars['String']['output']>;
id: Scalars['ID']['output'];
isActive: Scalars['Boolean']['output'];
type: MessengerType;
userId: Scalars['ID']['output'];
username?: Maybe<Scalars['String']['output']>;
};
export type MessengerDispatchResult = {
@@ -619,7 +622,7 @@ export type ConsumeLoginTokenMutation = { __typename?: 'Mutation', consumeLoginT
export type MeQueryVariables = Exact<{ [key: string]: never; }>;
export type MeQuery = { __typename?: 'Query', me?: { __typename?: 'User', id: string, email: string } | null };
export type MeQuery = { __typename?: 'Query', me?: { __typename?: 'User', id: string, email: string, fullName: string } | null };
export type RegisterSelfMutationVariables = Exact<{
input: RegisterSelfInput;
@@ -650,7 +653,7 @@ export type ClientProductsQuery = { __typename?: 'Query', clientProducts: Array<
export type MyMessengerConnectionsQueryVariables = Exact<{ [key: string]: never; }>;
export type MyMessengerConnectionsQuery = { __typename?: 'Query', myMessengerConnections: Array<{ __typename?: 'MessengerConnection', id: string, type: MessengerType, channelId: string, isActive: boolean }> };
export type MyMessengerConnectionsQuery = { __typename?: 'Query', myMessengerConnections: Array<{ __typename?: 'MessengerConnection', id: string, type: MessengerType, channelId: string, displayName?: string | null, username?: string | null, avatarAvailable: boolean, isActive: boolean }> };
export type MyNotificationHistoryQueryVariables = Exact<{
channel: MessengerType;
@@ -791,6 +794,7 @@ export const MeDocument = gql`
me {
id
email
fullName
}
}
`;
@@ -970,6 +974,9 @@ export const MyMessengerConnectionsDocument = gql`
id
type
channelId
displayName
username
avatarAvailable
isActive
}
}

View File

@@ -0,0 +1,51 @@
type MessengerConnectionView = {
id: string;
type: 'TELEGRAM' | 'MAX';
channelId: string;
displayName?: string | null;
username?: string | null;
avatarAvailable?: boolean | null;
};
export function messengerConnectionName(connection: MessengerConnectionView | null | undefined) {
const displayName = String(connection?.displayName || '').trim();
if (displayName) {
return displayName;
}
const username = String(connection?.username || '').trim();
if (username) {
return `@${username.replace(/^@+/, '')}`;
}
return connection?.channelId || 'Не подключен';
}
export function messengerConnectionHandle(connection: MessengerConnectionView | null | undefined) {
const username = String(connection?.username || '').trim().replace(/^@+/, '');
if (username) {
return `@${username}`;
}
return connection?.channelId || '';
}
export function messengerConnectionInitials(connection: MessengerConnectionView | null | undefined, fallback: string) {
const base = messengerConnectionName(connection);
const initials = base
.split(' ')
.filter(Boolean)
.slice(0, 2)
.map((part) => part.charAt(0).toUpperCase())
.join('');
return initials || fallback;
}
export function messengerConnectionAvatarSrc(connection: MessengerConnectionView | null | undefined) {
if (!connection?.avatarAvailable || connection.type !== 'TELEGRAM') {
return '';
}
return `/api/messenger-avatar/${encodeURIComponent(connection.id)}`;
}