diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-10-03 16:02:03 -0500 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-10-03 16:02:03 -0500 |
commit | 195d2f7d2bd193108938901c3f757a9e89080b63 (patch) | |
tree | 1a2084951cd29362bf4c91109551a5869b863f66 /src/state/lib/api.ts | |
parent | 2058505bf12c0ddf145bd00182da96d0cf5e8f53 (diff) | |
download | voidsky-195d2f7d2bd193108938901c3f757a9e89080b63.tar.zst |
Implement mentions rendering
Diffstat (limited to 'src/state/lib/api.ts')
-rw-r--r-- | src/state/lib/api.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/state/lib/api.ts b/src/state/lib/api.ts index feed41c41..db7e2ab21 100644 --- a/src/state/lib/api.ts +++ b/src/state/lib/api.ts @@ -6,9 +6,15 @@ // import {ReactNativeStore} from './auth' import AdxApi from '../../third-party/api' import {ServiceClient} from '../../third-party/api/src/index' +import { + TextSlice, + Entity as Entities, +} from '../../third-party/api/src/types/todo/social/post' import {AdxUri} from '../../third-party/uri' import {RootStoreModel} from '../models/root-store' +type Entity = Entities[0] + export function doPolyfill() { AdxApi.xrpc.fetch = fetchHandler } @@ -32,11 +38,13 @@ export async function post( } } } + const entities = extractEntities(text) return await store.api.todo.social.post.create( {did: store.me.did || ''}, { text, reply, + entities, createdAt: new Date().toISOString(), }, ) @@ -196,3 +204,20 @@ async function iterateAll( } } while (res.records.length === 100) }*/ + +function extractEntities(text: string): Entity[] | undefined { + let match + let ents: Entity[] = [] + const re = /(^|\s)@([a-zA-Z0-9\.-]+)(\b)/g + while ((match = re.exec(text))) { + ents.push({ + type: 'mention', + value: match[2], + index: [ + match.index + 1, // skip the (^|\s) but include the '@' + match.index + 2 + match[2].length, + ], + }) + } + return ents.length > 0 ? ents : undefined +} |