From 67f7ebbf8ae8b3d30be82690191529afa4b3c367 Mon Sep 17 00:00:00 2001 From: Matilde Park Date: Wed, 3 Feb 2021 18:13:03 -0500 Subject: [PATCH] links, publish: use tokenizeMessage for comments Fixes urbit/landscape#271. --- pkg/interface/src/logic/lib/graph.ts | 24 ------------------- .../src/views/components/Comments.tsx | 6 ++--- 2 files changed, 3 insertions(+), 27 deletions(-) delete mode 100644 pkg/interface/src/logic/lib/graph.ts diff --git a/pkg/interface/src/logic/lib/graph.ts b/pkg/interface/src/logic/lib/graph.ts deleted file mode 100644 index b17848ded6..0000000000 --- a/pkg/interface/src/logic/lib/graph.ts +++ /dev/null @@ -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; -} diff --git a/pkg/interface/src/views/components/Comments.tsx b/pkg/interface/src/views/components/Comments.tsx index 1f35e99f51..56c08fe17c 100644 --- a/pkg/interface/src/views/components/Comments.tsx +++ b/pkg/interface/src/views/components/Comments.tsx @@ -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,