Changeset View
Changeset View
Standalone View
Standalone View
lib/shared/mention-utils.js
// @flow | // @flow | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import { oldValidUsernameRegexString } from './account-utils.js'; | import { markdownUserMentionRegexString } from './account-utils.js'; | ||||
import SentencePrefixSearchIndex from './sentence-prefix-search-index.js'; | import SentencePrefixSearchIndex from './sentence-prefix-search-index.js'; | ||||
import { threadOtherMembers } from './thread-utils.js'; | import { threadOtherMembers } from './thread-utils.js'; | ||||
import { stringForUserExplicit } from './user-utils.js'; | import { stringForUserExplicit } from './user-utils.js'; | ||||
import { useENSNames } from '../hooks/ens-cache.js'; | import { useENSNames } from '../hooks/ens-cache.js'; | ||||
import { useUserSearchIndex } from '../selectors/nav-selectors.js'; | import { useUserSearchIndex } from '../selectors/nav-selectors.js'; | ||||
import { threadTypes } from '../types/thread-types-enum.js'; | import { threadTypes } from '../types/thread-types-enum.js'; | ||||
import type { | import type { | ||||
ChatMentionCandidates, | ChatMentionCandidates, | ||||
Show All 31 Lines | export type TypeaheadTooltipActionItem<SuggestionItemType> = { | ||||
+key: string, | +key: string, | ||||
+execute: () => mixed, | +execute: () => mixed, | ||||
+actionButtonContent: SuggestionItemType, | +actionButtonContent: SuggestionItemType, | ||||
}; | }; | ||||
// The simple-markdown package already breaks words out for us, and we are | // The simple-markdown package already breaks words out for us, and we are | ||||
// supposed to only match when the first word of the input matches | // supposed to only match when the first word of the input matches | ||||
const markdownUserMentionRegex: RegExp = new RegExp( | const markdownUserMentionRegex: RegExp = new RegExp( | ||||
`^(@(${oldValidUsernameRegexString}))\\b`, | `^(@(${markdownUserMentionRegexString}))\\b`, | ||||
); | ); | ||||
function isUserMentioned(username: string, text: string): boolean { | function isUserMentioned(username: string, text: string): boolean { | ||||
return new RegExp(`\\B@${username}\\b`, 'i').test(text); | return new RegExp(`\\B@${username}\\b`, 'i').test(text); | ||||
} | } | ||||
const userMentionsExtractionRegex = new RegExp( | const userMentionsExtractionRegex = new RegExp( | ||||
`\\B(@(${oldValidUsernameRegexString}))\\b`, | `\\B(@(${markdownUserMentionRegexString}))\\b`, | ||||
'g', | 'g', | ||||
); | ); | ||||
const chatMentionRegexString = `([^\\\\]|^)(@\\[\\[(${idSchemaRegex}):((.{0,${chatNameMaxLength}}?)(?!\\\\).|^)\\]\\])`; | const chatMentionRegexString = `([^\\\\]|^)(@\\[\\[(${idSchemaRegex}):((.{0,${chatNameMaxLength}}?)(?!\\\\).|^)\\]\\])`; | ||||
const chatMentionRegex: RegExp = new RegExp(`^${chatMentionRegexString}`); | const chatMentionRegex: RegExp = new RegExp(`^${chatMentionRegexString}`); | ||||
const globalChatMentionRegex: RegExp = new RegExp(chatMentionRegexString, 'g'); | const globalChatMentionRegex: RegExp = new RegExp(chatMentionRegexString, 'g'); | ||||
function encodeChatMentionText(text: string): string { | function encodeChatMentionText(text: string): string { | ||||
▲ Show 20 Lines • Show All 140 Lines • Show Last 20 Lines |