Detect links in profile bios

zio/stable
Paul Frazee 2022-11-23 14:53:33 -06:00
parent 2b37b6549b
commit 4eb8bc1249
4 changed files with 22 additions and 4 deletions

View File

@ -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',

View File

@ -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 || '')
}
}

View File

@ -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>
</View>
{view.description ? (
<Text style={styles.description} numberOfLines={3}>
{view.description}
</Text>
<RichText
style={styles.description}
numberOfLines={3}
text={view.description}
entities={view.descriptionEntities}
/>
) : undefined}
{view.isScene && view.creator ? (
<View style={styles.relationshipsLine}>

View File

@ -15,10 +15,12 @@ export function RichText({
text,
entities,
style,
numberOfLines,
}: {
text: string
entities?: Entity[]
style?: StyleProp<TextStyle>
numberOfLines?: number
}) {
if (!entities?.length) {
return <Text style={style}>{text}</Text>
@ -55,7 +57,11 @@ export function RichText({
}
key++
}
return <Text style={style}>{els}</Text>
return (
<Text style={style} numberOfLines={numberOfLines}>
{els}
</Text>
)
}
function sortByIndex(a: Entity, b: Entity) {