Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32281625
D8834.1765266527.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D8834.1765266527.diff
View Options
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,13 +2,14 @@
import { oldValidUsernameRegexString } from './account-utils.js';
import SearchIndex from './search-index.js';
-import { threadOtherMembers } from './thread-utils.js';
+import { threadOtherMembers, chatNameMaxLength } from './thread-utils.js';
import { stringForUserExplicit } from './user-utils.js';
import { threadTypes } from '../types/thread-types-enum.js';
import {
type ThreadInfo,
type RelativeMemberInfo,
} from '../types/thread-types.js';
+import { idSchemaRegex } from '../utils/validation-utils.js';
export type TypeaheadMatchedStrings = {
+textBeforeAtSymbol: string,
@@ -35,6 +36,13 @@
'g',
);
+const chatMentionRegexString = `^(?<!\\\\)(@\\[\\[(${idSchemaRegex}):(.{1,${chatNameMaxLength}}?)(?<!\\\\)\\]\\])`;
+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 +125,6 @@
getNewTextAndSelection,
getTypeaheadRegexMatches,
getMentionsCandidates,
+ chatMentionRegex,
+ decodeChatMentionText,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 9, 7:48 AM (8 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5853358
Default Alt Text
D8834.1765266527.diff (2 KB)
Attached To
Mode
D8834: [lib] Introduce chat mention match and parse utilities
Attached
Detach File
Event Timeline
Log In to Comment