mirror of
https://github.com/urbit/shrub.git
synced 2024-12-20 09:21:42 +03:00
Merge pull request #4374 from urbit/mp/graph/tokenize-comments
links, publish: use tokenizeMessage for comments
This commit is contained in:
commit
2353e302ae
@ -1,24 +0,0 @@
|
||||
import { Content } from "~/types";
|
||||
import urbitOb from "urbit-ob";
|
||||
|
||||
export function scanForMentions(text: string) {
|
||||
const regex = /~([a-z]|-)+/g;
|
||||
let result: Content[] = [];
|
||||
let match: RegExpExecArray | null;
|
||||
let lastPos = 0;
|
||||
while ((match = regex.exec(text)) !== null) {
|
||||
const newPos = match.index + match[0].length;
|
||||
if (urbitOb.isValidPatp(match[0])) {
|
||||
if (match.index !== lastPos) {
|
||||
result.push({ text: text.slice(lastPos, match.index) });
|
||||
}
|
||||
result.push({ mention: match[0] });
|
||||
}
|
||||
lastPos = newPos;
|
||||
}
|
||||
const remainder = text.slice(lastPos, text.length);
|
||||
if (remainder) {
|
||||
result.push({ text: remainder });
|
||||
}
|
||||
return result;
|
||||
}
|
@ -9,7 +9,7 @@ import { FormikHelpers } from 'formik';
|
||||
import { Group, GraphNode, Association } from '~/types';
|
||||
import { createPost, createBlankNodeWithChildPost } from '~/logic/api/graph';
|
||||
import { getLatestCommentRevision } from '~/logic/lib/publish';
|
||||
import { scanForMentions } from '~/logic/lib/graph';
|
||||
import tokenizeMessage from '~/logic/lib/tokenizeMessage';
|
||||
import { getUnreadCount } from '~/logic/lib/hark';
|
||||
|
||||
interface CommentsProps {
|
||||
@ -32,7 +32,7 @@ export function Comments(props: CommentsProps) {
|
||||
actions: FormikHelpers<{ comment: string }>
|
||||
) => {
|
||||
try {
|
||||
const content = scanForMentions(comment);
|
||||
const content = tokenizeMessage(comment);
|
||||
const node = createBlankNodeWithChildPost(
|
||||
comments?.post?.index,
|
||||
'1',
|
||||
@ -55,7 +55,7 @@ export function Comments(props: CommentsProps) {
|
||||
const commentNode = comments.children.get(bigInt(props.editCommentId))!;
|
||||
const [idx, _] = getLatestCommentRevision(commentNode);
|
||||
|
||||
const content = scanForMentions(comment);
|
||||
const content = tokenizeMessage(comment);
|
||||
const post = createPost(
|
||||
content,
|
||||
commentNode.post.index,
|
||||
|
Loading…
Reference in New Issue
Block a user