Detect links in profile bios
parent
2b37b6549b
commit
4eb8bc1249
|
@ -69,6 +69,8 @@ export function extractEntities(
|
||||||
while ((match = re.exec(text))) {
|
while ((match = re.exec(text))) {
|
||||||
if (knownHandles && !knownHandles.has(match[3])) {
|
if (knownHandles && !knownHandles.has(match[3])) {
|
||||||
continue // not a known handle
|
continue // not a known handle
|
||||||
|
} else if (!match[3].includes('.')) {
|
||||||
|
continue // probably not a handle
|
||||||
}
|
}
|
||||||
ents.push({
|
ents.push({
|
||||||
type: 'mention',
|
type: 'mention',
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import {makeAutoObservable, runInAction} from 'mobx'
|
import {makeAutoObservable, runInAction} from 'mobx'
|
||||||
import * as GetProfile from '../../third-party/api/src/client/types/app/bsky/actor/getProfile'
|
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 * 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 {Declaration} from './_common'
|
||||||
import {RootStoreModel} from './root-store'
|
import {RootStoreModel} from './root-store'
|
||||||
import * as apilib from '../lib/api'
|
import * as apilib from '../lib/api'
|
||||||
|
@ -41,6 +43,9 @@ export class ProfileViewModel {
|
||||||
postsCount: number = 0
|
postsCount: number = 0
|
||||||
myState = new ProfileViewMyStateModel()
|
myState = new ProfileViewMyStateModel()
|
||||||
|
|
||||||
|
// added data
|
||||||
|
descriptionEntities?: Entity[]
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public rootStore: RootStoreModel,
|
public rootStore: RootStoreModel,
|
||||||
params: GetProfile.QueryParams,
|
params: GetProfile.QueryParams,
|
||||||
|
@ -163,5 +168,6 @@ export class ProfileViewModel {
|
||||||
if (res.data.myState) {
|
if (res.data.myState) {
|
||||||
Object.assign(this.myState, res.data.myState)
|
Object.assign(this.myState, res.data.myState)
|
||||||
}
|
}
|
||||||
|
this.descriptionEntities = extractEntities(this.description || '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import {MagnifyingGlassIcon} from '../../lib/icons'
|
||||||
import {DropdownBtn, DropdownItem} from '../util/DropdownBtn'
|
import {DropdownBtn, DropdownItem} from '../util/DropdownBtn'
|
||||||
import Toast from '../util/Toast'
|
import Toast from '../util/Toast'
|
||||||
import {LoadingPlaceholder} from '../util/LoadingPlaceholder'
|
import {LoadingPlaceholder} from '../util/LoadingPlaceholder'
|
||||||
|
import {RichText} from '../util/RichText'
|
||||||
import {UserAvatar} from '../util/UserAvatar'
|
import {UserAvatar} from '../util/UserAvatar'
|
||||||
import {UserBanner} from '../util/UserBanner'
|
import {UserBanner} from '../util/UserBanner'
|
||||||
import {UserInfoText} from '../util/UserInfoText'
|
import {UserInfoText} from '../util/UserInfoText'
|
||||||
|
@ -293,9 +294,12 @@ export const ProfileHeader = observer(function ProfileHeader({
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{view.description ? (
|
{view.description ? (
|
||||||
<Text style={styles.description} numberOfLines={3}>
|
<RichText
|
||||||
{view.description}
|
style={styles.description}
|
||||||
</Text>
|
numberOfLines={3}
|
||||||
|
text={view.description}
|
||||||
|
entities={view.descriptionEntities}
|
||||||
|
/>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
{view.isScene && view.creator ? (
|
{view.isScene && view.creator ? (
|
||||||
<View style={styles.relationshipsLine}>
|
<View style={styles.relationshipsLine}>
|
||||||
|
|
|
@ -15,10 +15,12 @@ export function RichText({
|
||||||
text,
|
text,
|
||||||
entities,
|
entities,
|
||||||
style,
|
style,
|
||||||
|
numberOfLines,
|
||||||
}: {
|
}: {
|
||||||
text: string
|
text: string
|
||||||
entities?: Entity[]
|
entities?: Entity[]
|
||||||
style?: StyleProp<TextStyle>
|
style?: StyleProp<TextStyle>
|
||||||
|
numberOfLines?: number
|
||||||
}) {
|
}) {
|
||||||
if (!entities?.length) {
|
if (!entities?.length) {
|
||||||
return <Text style={style}>{text}</Text>
|
return <Text style={style}>{text}</Text>
|
||||||
|
@ -55,7 +57,11 @@ export function RichText({
|
||||||
}
|
}
|
||||||
key++
|
key++
|
||||||
}
|
}
|
||||||
return <Text style={style}>{els}</Text>
|
return (
|
||||||
|
<Text style={style} numberOfLines={numberOfLines}>
|
||||||
|
{els}
|
||||||
|
</Text>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortByIndex(a: Entity, b: Entity) {
|
function sortByIndex(a: Entity, b: Entity) {
|
||||||
|
|
Loading…
Reference in New Issue