tokenizeMessage: expand group links

This commit is contained in:
Liam Fitzgerald 2021-05-06 11:30:30 +10:00
parent 6c653e7ab9
commit be34223a6e
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB

View File

@ -3,6 +3,8 @@ import { parsePermalink, permalinkToReference } from '~/logic/lib/permalinks';
const URL_REGEX = new RegExp(String(/^(([\w\-\+]+:\/\/)[-a-zA-Z0-9:@;?&=\/%\+\.\*!'\(\),\$_\{\}\^~\[\]`#|]+\w)/.source));
const GROUP_REGEX = new RegExp(String(/^~[-a-z_]+\/[-a-z]+/.source));
const isUrl = (string) => {
try {
return URL_REGEX.test(string);
@ -15,6 +17,16 @@ const isRef = (str) => {
return isUrl(str) && str.startsWith('web+urbitgraph://');
};
const isGroup = str => {
try {
return GROUP_REGEX.test(str);
} catch (e) {
return false;
}
}
const convertToGroupRef = (group) => `web+urbitgraph://group/${group}`;
const tokenizeMessage = (text) => {
let messages = [];
// by line
@ -37,7 +49,9 @@ const tokenizeMessage = (text) => {
currTextLine = [line];
} else {
const words = line.split(/\s/);
words.forEach((str, idx) => {
words.forEach((word, idx) => {
const str = isGroup(word) ? convertToGroupRef(word) : word;
const last = words.length - 1 === idx;
if (
(str.startsWith('`') && str !== '`')