Page MenuHomePhabricator

D8834.id30176.diff
No OneTemporary

D8834.id30176.diff

diff --git a/lib/shared/markdown.js b/lib/shared/markdown.js
--- a/lib/shared/markdown.js
+++ b/lib/shared/markdown.js
@@ -2,8 +2,15 @@
import invariant from 'invariant';
-import { markdownMentionRegex } from './mention-utils.js';
-import type { RelativeMemberInfo } from '../types/thread-types.js';
+import {
+ markdownMentionRegex,
+ decodeChatMentionText,
+} from './mention-utils.js';
+import type {
+ RelativeMemberInfo,
+ ResolvedThreadInfo,
+ ChatMentionCandidates,
+} from '../types/thread-types.js';
// simple-markdown types
export type State = {
@@ -218,6 +225,24 @@
return match;
}
+function parseChatMention(
+ chatMentionCandidates: ChatMentionCandidates,
+ capture: Capture,
+): {
+ threadInfo: ?ResolvedThreadInfo,
+ content: string,
+ hasAccessToChat: boolean,
+} {
+ const threadInfo = chatMentionCandidates[capture[2]];
+ const threadName = threadInfo?.uiName ?? decodeChatMentionText(capture[3]);
+ const content = `@${threadName}`;
+ return {
+ threadInfo,
+ content,
+ hasAccessToChat: !!threadInfo,
+ };
+}
+
const blockQuoteRegex: RegExp = /^( *>[^\n]+(?:\n[^\n]+)*)(?:\n|$)/;
const blockQuoteStripFollowingNewlineRegex: RegExp =
/^( *>[^\n]+(?:\n[^\n]+)*)(?:\n|$){2}/;
@@ -317,4 +342,5 @@
matchMentions,
stripSpoilersFromNotifications,
stripSpoilersFromMarkdownAST,
+ parseChatMention,
};
diff --git a/lib/shared/mention-utils.js b/lib/shared/mention-utils.js
--- a/lib/shared/mention-utils.js
+++ b/lib/shared/mention-utils.js
@@ -2,7 +2,10 @@
import { oldValidUsernameRegexString } from './account-utils.js';
import SearchIndex from './search-index.js';
-import { threadOtherMembers } from './thread-utils.js';
+import {
+ threadOtherMembers,
+ validChatNameRegexString,
+} from './thread-utils.js';
import { stringForUserExplicit } from './user-utils.js';
import { threadTypes } from '../types/thread-types-enum.js';
import {
@@ -35,6 +38,13 @@
'g',
);
+const chatMentionRegexString = `^(?<!\\\\)(@\\[\\[([0-9,|]+):(${validChatNameRegexString}?)(?<!\\\\)\\]\\])`;
+const chatMentionRegex: RegExp = new RegExp(chatMentionRegexString);
+
+function decodeChatMentionText(text: string): string {
+ return text.replace(/\\]/g, ']');
+}
+
function extractMentionsFromText(text: string): string[] {
const iterator = text.matchAll(mentionsExtractionRegex);
return [...iterator].map(matches => matches[2]);
@@ -117,4 +127,6 @@
getNewTextAndSelection,
getTypeaheadRegexMatches,
getMentionsCandidates,
+ chatMentionRegex,
+ decodeChatMentionText,
};
diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js
--- a/lib/shared/thread-utils.js
+++ b/lib/shared/thread-utils.js
@@ -111,8 +111,8 @@
const chatNameMaxLength = 191;
const chatNameMinLength = 0;
const secondCharRange = `{${chatNameMinLength},${chatNameMaxLength}}`;
-const validChatNameRegexString = `^.${secondCharRange}$`;
-const validChatNameRegex: RegExp = new RegExp(validChatNameRegexString);
+const validChatNameRegexString = `.${secondCharRange}`;
+const validChatNameRegex: RegExp = new RegExp(`^${validChatNameRegexString}$`);
function threadHasPermission(
threadInfo: ?(ThreadInfo | RawThreadInfo),
@@ -1820,6 +1820,7 @@
getAvailableThreadMemberActions,
threadMembersWithoutAddedAshoat,
validChatNameRegex,
+ validChatNameRegexString,
chatNameMaxLength,
patchThreadInfoToIncludeMentionedMembersOfParent,
threadInfoInsideCommunity,

File Metadata

Mime Type
text/plain
Expires
Tue, Oct 22, 9:32 PM (20 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2344682
Default Alt Text
D8834.id30176.diff (3 KB)

Event Timeline