Skip to content

Commit

Permalink
fix: get display name from handle
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbinrui committed Feb 3, 2025
1 parent 76de270 commit e387df6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/helpers/formatBskyProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import type { AppBskyActorDefs } from '@atproto/api';

import { Source } from '@/constants/enum.js';
import { type Profile, ProfileStatus } from '@/providers/types/SocialMedia.js';
import { first } from 'lodash-es';

function getDisplayNameFromHandle(handle: string) {
const matched = handle.match(/^(?!-)[A-Za-z0-9-]{3,}(?<!-)/) ?? [];
return first(matched) ?? handle;
}

export function formatBskyProfile(profile: AppBskyActorDefs.ProfileViewDetailed): Profile {
return {
profileId: profile.did,
source: Source.Bsky,
profileSource: Source.Bsky,
displayName: profile.displayName ?? profile.handle ?? '',
displayName: profile.displayName ?? getDisplayNameFromHandle(profile.handle),
bio: profile.description ?? '',
handle: profile.handle,
fullHandle: profile.handle,
Expand Down

0 comments on commit e387df6

Please sign in to comment.