links, publish: use tokenizeMessage for comments

Fixes urbit/landscape#271.
This commit is contained in:
Matilde Park 2021-02-03 18:13:03 -05:00
parent e86a64359e
commit 67f7ebbf8a
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,