diff --git a/keyserver/src/updaters/thread-updaters.js b/keyserver/src/updaters/thread-updaters.js --- a/keyserver/src/updaters/thread-updaters.js +++ b/keyserver/src/updaters/thread-updaters.js @@ -8,7 +8,6 @@ roleIsAdminRole, viewerIsMember, getThreadTypeParentRequirement, - validChatNameRegex, } from 'lib/shared/thread-utils.js'; import type { Shape } from 'lib/types/core.js'; import { messageTypes } from 'lib/types/message-types-enum.js'; @@ -30,6 +29,7 @@ import { ServerError } from 'lib/utils/errors.js'; import { promiseAll } from 'lib/utils/promises.js'; import { firstLine } from 'lib/utils/string-utils.js'; +import { validChatNameRegex } from 'lib/utils/validation-utils.js'; import { reportLinkUsage } from './link-updaters.js'; import { updateRoles } from './role-updaters.js'; 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,11 +2,7 @@ import { oldValidUsernameRegexString } from './account-utils.js'; import SentencePrefixSearchIndex from './sentence-prefix-search-index.js'; -import { - threadOtherMembers, - chatNameMaxLength, - extractThreadID, -} from './thread-utils.js'; +import { threadOtherMembers, extractThreadID } from './thread-utils.js'; import { stringForUserExplicit } from './user-utils.js'; import { threadTypes } from '../types/thread-types-enum.js'; import type { @@ -16,7 +12,7 @@ ChatMentionCandidates, } from '../types/thread-types.js'; import { ET, entityTextToRawString } from '../utils/entity-text.js'; -import { idSchemaRegex } from '../utils/validation-utils.js'; +import { idSchemaRegex, chatNameMaxLength } from '../utils/validation-utils.js'; export type TypeaheadMatchedStrings = { +textBeforeAtSymbol: string, 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 @@ -108,12 +108,6 @@ import { trimText } from '../utils/text-utils.js'; import { idSchemaRegex } from '../utils/validation-utils.js'; -const chatNameMaxLength = 191; -const chatNameMinLength = 0; -const secondCharRange = `{${chatNameMinLength},${chatNameMaxLength}}`; -const validChatNameRegexString = `.${secondCharRange}`; -const validChatNameRegex: RegExp = new RegExp(`^${validChatNameRegexString}$`); - function threadHasPermission( threadInfo: ?(ThreadInfo | RawThreadInfo), permission: ThreadPermission, @@ -1875,9 +1869,6 @@ switchMemberAdminRoleInThread, getAvailableThreadMemberActions, threadMembersWithoutAddedAshoat, - validChatNameRegex, - validChatNameRegexString, - chatNameMaxLength, patchThreadInfoToIncludeMentionedMembersOfParent, threadInfoInsideCommunity, useRoleMemberCountsForCommunity, diff --git a/lib/utils/validation-utils.js b/lib/utils/validation-utils.js --- a/lib/utils/validation-utils.js +++ b/lib/utils/validation-utils.js @@ -105,6 +105,12 @@ const idSchemaRegex = '(?:[0-9]+\\|)?[0-9]+'; +const chatNameMaxLength = 191; +const chatNameMinLength = 0; +const secondCharRange = `{${chatNameMinLength},${chatNameMaxLength}}`; +const validChatNameRegexString = `.${secondCharRange}`; +const validChatNameRegex: RegExp = new RegExp(`^${validChatNameRegexString}$`); + export { tBool, tString, @@ -129,4 +135,7 @@ assertWithValidator, ashoatKeyserverID, idSchemaRegex, + validChatNameRegex, + validChatNameRegexString, + chatNameMaxLength, }; diff --git a/native/chat/settings/thread-settings-name.react.js b/native/chat/settings/thread-settings-name.react.js --- a/native/chat/settings/thread-settings-name.react.js +++ b/native/chat/settings/thread-settings-name.react.js @@ -14,7 +14,6 @@ changeThreadSettings, } from 'lib/actions/thread-actions.js'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; -import { chatNameMaxLength } from 'lib/shared/thread-utils.js'; import type { LoadingStatus } from 'lib/types/loading-types.js'; import { type ResolvedThreadInfo, @@ -27,6 +26,7 @@ useDispatchActionPromise, } from 'lib/utils/action-utils.js'; import { firstLine } from 'lib/utils/string-utils.js'; +import { chatNameMaxLength } from 'lib/utils/validation-utils.js'; import SaveSettingButton from './save-setting-button.react.js'; import EditSettingButton from '../../components/edit-setting-button.react.js'; diff --git a/native/utils/typeahead-utils.js b/native/utils/typeahead-utils.js --- a/native/utils/typeahead-utils.js +++ b/native/utils/typeahead-utils.js @@ -10,8 +10,8 @@ type TypeaheadTooltipActionItem, type MentionTypeaheadSuggestionItem, } from 'lib/shared/mention-utils.js'; -import { validChatNameRegexString } from 'lib/shared/thread-utils.js'; import { stringForUserExplicit } from 'lib/shared/user-utils.js'; +import { validChatNameRegexString } from 'lib/utils/validation-utils.js'; // Native regex is a little bit different than web one as // there are no named capturing groups yet on native. diff --git a/web/modals/threads/settings/thread-settings-general-tab.react.js b/web/modals/threads/settings/thread-settings-general-tab.react.js --- a/web/modals/threads/settings/thread-settings-general-tab.react.js +++ b/web/modals/threads/settings/thread-settings-general-tab.react.js @@ -7,10 +7,7 @@ changeThreadSettingsActionTypes, changeThreadSettings, } from 'lib/actions/thread-actions.js'; -import { - threadHasPermission, - chatNameMaxLength, -} from 'lib/shared/thread-utils.js'; +import { threadHasPermission } from 'lib/shared/thread-utils.js'; import { type SetState } from 'lib/types/hook-types.js'; import { threadPermissions } from 'lib/types/thread-permission-types.js'; import { type ThreadInfo, type ThreadChanges } from 'lib/types/thread-types.js'; @@ -19,6 +16,7 @@ useServerCall, } from 'lib/utils/action-utils.js'; import { firstLine } from 'lib/utils/string-utils.js'; +import { chatNameMaxLength } from 'lib/utils/validation-utils.js'; import SubmitSection from './submit-section.react.js'; import css from './thread-settings-general-tab.css'; diff --git a/web/utils/typeahead-utils.js b/web/utils/typeahead-utils.js --- a/web/utils/typeahead-utils.js +++ b/web/utils/typeahead-utils.js @@ -10,9 +10,9 @@ type TypeaheadTooltipActionItem, encodeChatMentionText, } from 'lib/shared/mention-utils.js'; -import { validChatNameRegexString } from 'lib/shared/thread-utils.js'; import { stringForUserExplicit } from 'lib/shared/user-utils.js'; import type { SetState } from 'lib/types/hook-types.js'; +import { validChatNameRegexString } from 'lib/utils/validation-utils.js'; import ThreadAvatar from '../avatars/thread-avatar.react.js'; import UserAvatar from '../avatars/user-avatar.react.js';