Page MenuHomePhabricator

D8834.id30070.diff
No OneTemporary

D8834.id30070.diff

diff --git a/lib/shared/markdown.js b/lib/shared/markdown.js
--- a/lib/shared/markdown.js
+++ b/lib/shared/markdown.js
@@ -3,7 +3,12 @@
import invariant from 'invariant';
import { markdownMentionRegex } from './mention-utils.js';
-import type { RelativeMemberInfo } from '../types/thread-types.js';
+import { validChatNameRegexString } from './thread-utils.js';
+import type {
+ RelativeMemberInfo,
+ ResolvedThreadInfo,
+ ChatMentionCandidates,
+} from '../types/thread-types.js';
// simple-markdown types
export type State = {
@@ -218,6 +223,41 @@
return match;
}
+const chatMentionRegexString = `^(?<!\\\\)(@\\[\\[([0-9,|]+):(${validChatNameRegexString}?)(?<!\\\\)\\]\\])`;
+const chatMentionRegex: RegExp = new RegExp(chatMentionRegexString);
+
+function decodeChatMentionText(text: string): string {
+ return text.replace(/\\]/g, ']');
+}
+
+function matchChatMentions(): MatchFunction {
+ return (source: string, state: State) => {
+ if (!state.inline) {
+ return null;
+ }
+ const result = chatMentionRegex.exec(source);
+ return result;
+ };
+}
+
+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 +357,6 @@
matchMentions,
stripSpoilersFromNotifications,
stripSpoilersFromMarkdownAST,
+ matchChatMentions,
+ parseChatMention,
};
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),
@@ -1803,6 +1803,7 @@
getAvailableThreadMemberActions,
threadMembersWithoutAddedAshoat,
validChatNameRegex,
+ validChatNameRegexString,
chatNameMaxLength,
patchThreadInfoToIncludeMentionedMembersOfParent,
threadInfoInsideCommunity,

File Metadata

Mime Type
text/plain
Expires
Tue, Oct 22, 9:31 PM (19 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2344678
Default Alt Text
D8834.id30070.diff (2 KB)

Event Timeline