Page MenuHomePhabricator

D5532.id18183.diff
No OneTemporary

D5532.id18183.diff

diff --git a/lib/shared/mention-utils.js b/lib/shared/mention-utils.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/mention-utils.js
@@ -0,0 +1,29 @@
+// @flow
+
+import type { RelativeMemberInfo } from '../types/thread-types';
+import { oldValidUsernameRegexString } from './account-utils';
+import SearchIndex from './search-index';
+import { stringForUserExplicit } from './user-utils';
+
+function getTypeaheadUserSuggestions(
+ userSearchIndex: SearchIndex,
+ usersInThread: $ReadOnlyArray<RelativeMemberInfo>,
+ typedPrefix: string,
+): $ReadOnlyArray<RelativeMemberInfo> {
+ const userIDs = userSearchIndex.getSearchResults(typedPrefix);
+
+ return usersInThread
+ .filter(
+ (user: RelativeMemberInfo) =>
+ typedPrefix.length === 0 || userIDs.includes(user.id),
+ )
+ .sort((userA, userB) =>
+ stringForUserExplicit(userA).localeCompare(stringForUserExplicit(userB)),
+ );
+}
+
+const mentionRegex: RegExp = new RegExp(
+ `(^|.* )@(${oldValidUsernameRegexString})?$`,
+);
+
+export { getTypeaheadUserSuggestions, mentionRegex };
diff --git a/lib/shared/user-utils.js b/lib/shared/user-utils.js
--- a/lib/shared/user-utils.js
+++ b/lib/shared/user-utils.js
@@ -18,7 +18,15 @@
function stringForUser(user: RelativeUserInfo | RelativeMemberInfo): string {
if (user.isViewer) {
return 'you';
- } else if (user.username) {
+ }
+
+ return stringForUserExplicit(user);
+}
+
+function stringForUserExplicit(
+ user: RelativeUserInfo | RelativeMemberInfo,
+): string {
+ if (user.username) {
return user.username;
} else {
return 'anonymous';
@@ -49,4 +57,4 @@
return admin ? userInfos[admin.id] : undefined;
}
-export { stringForUser, isStaff, getKeyserverAdmin };
+export { stringForUser, stringForUserExplicit, isStaff, getKeyserverAdmin };

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 29, 9:31 AM (21 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2596332
Default Alt Text
D5532.id18183.diff (1 KB)

Event Timeline