From 4eb8bc1249ccf6afaa0c77695057a13379cf1aa1 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Wed, 23 Nov 2022 14:53:33 -0600 Subject: [PATCH] Detect links in profile bios --- src/lib/strings.ts | 2 ++ src/state/models/profile-view.ts | 6 ++++++ src/view/com/profile/ProfileHeader.tsx | 10 +++++++--- src/view/com/util/RichText.tsx | 8 +++++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/lib/strings.ts b/src/lib/strings.ts index f884cc86..480dfdcc 100644 --- a/src/lib/strings.ts +++ b/src/lib/strings.ts @@ -69,6 +69,8 @@ export function extractEntities( while ((match = re.exec(text))) { if (knownHandles && !knownHandles.has(match[3])) { continue // not a known handle + } else if (!match[3].includes('.')) { + continue // probably not a handle } ents.push({ type: 'mention', diff --git a/src/state/models/profile-view.ts b/src/state/models/profile-view.ts index 8386fbbc..927374cc 100644 --- a/src/state/models/profile-view.ts +++ b/src/state/models/profile-view.ts @@ -1,6 +1,8 @@ import {makeAutoObservable, runInAction} from 'mobx' import * as GetProfile from '../../third-party/api/src/client/types/app/bsky/actor/getProfile' import * as Profile from '../../third-party/api/src/client/types/app/bsky/actor/profile' +import {Entity} from '../../third-party/api/src/client/types/app/bsky/feed/post' +import {extractEntities} from '../../lib/strings' import {Declaration} from './_common' import {RootStoreModel} from './root-store' import * as apilib from '../lib/api' @@ -41,6 +43,9 @@ export class ProfileViewModel { postsCount: number = 0 myState = new ProfileViewMyStateModel() + // added data + descriptionEntities?: Entity[] + constructor( public rootStore: RootStoreModel, params: GetProfile.QueryParams, @@ -163,5 +168,6 @@ export class ProfileViewModel { if (res.data.myState) { Object.assign(this.myState, res.data.myState) } + this.descriptionEntities = extractEntities(this.description || '') } } diff --git a/src/view/com/profile/ProfileHeader.tsx b/src/view/com/profile/ProfileHeader.tsx index 5a31d5c5..9325a88a 100644 --- a/src/view/com/profile/ProfileHeader.tsx +++ b/src/view/com/profile/ProfileHeader.tsx @@ -24,6 +24,7 @@ import {MagnifyingGlassIcon} from '../../lib/icons' import {DropdownBtn, DropdownItem} from '../util/DropdownBtn' import Toast from '../util/Toast' import {LoadingPlaceholder} from '../util/LoadingPlaceholder' +import {RichText} from '../util/RichText' import {UserAvatar} from '../util/UserAvatar' import {UserBanner} from '../util/UserBanner' import {UserInfoText} from '../util/UserInfoText' @@ -293,9 +294,12 @@ export const ProfileHeader = observer(function ProfileHeader({ {view.description ? ( - - {view.description} - + ) : undefined} {view.isScene && view.creator ? ( diff --git a/src/view/com/util/RichText.tsx b/src/view/com/util/RichText.tsx index a67f90a6..8b4e6a50 100644 --- a/src/view/com/util/RichText.tsx +++ b/src/view/com/util/RichText.tsx @@ -15,10 +15,12 @@ export function RichText({ text, entities, style, + numberOfLines, }: { text: string entities?: Entity[] style?: StyleProp + numberOfLines?: number }) { if (!entities?.length) { return {text} @@ -55,7 +57,11 @@ export function RichText({ } key++ } - return {els} + return ( + + {els} + + ) } function sortByIndex(a: Entity, b: Entity) {