Merge pull request #4374 from urbit/mp/graph/tokenize-comments

links, publish: use tokenizeMessage for comments
This commit is contained in:
matildepark 2021-02-03 18:25:54 -05:00 committed by GitHub
commit 2353e302ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 27 deletions

View File

@ -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;
}

View File

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