Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3294568
D6512.id21815.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D6512.id21815.diff
View Options
diff --git a/lib/shared/messages/add-members-message-spec.js b/lib/shared/messages/add-members-message-spec.js
--- a/lib/shared/messages/add-members-message-spec.js
+++ b/lib/shared/messages/add-members-message-spec.js
@@ -15,6 +15,11 @@
import type { NotifTexts } from '../../types/notif-types';
import type { ThreadInfo } from '../../types/thread-types';
import type { RelativeUserInfo } from '../../types/user-types';
+import {
+ ET,
+ type EntityText,
+ pluralizeEntityText,
+} from '../../utils/entity-text';
import { values } from '../../utils/objects';
import {
robotextForMessageInfo,
@@ -26,7 +31,6 @@
MessageSpec,
MessageTitleParam,
NotificationTextsParams,
- RobotextParams,
} from './message-spec';
import { joinResult } from './utils';
@@ -122,15 +126,16 @@
return { ...messageData, id };
},
- robotext(
- messageInfo: AddMembersMessageInfo,
- creator: string,
- params: RobotextParams,
- ): string {
+ robotext(messageInfo: AddMembersMessageInfo): EntityText {
const users = messageInfo.addedMembers;
invariant(users.length !== 0, 'added who??');
- const addedUsersString = params.robotextForUsers(users);
- return `${creator} added ${addedUsersString}`;
+
+ const creator = ET.user({ userInfo: messageInfo.creator });
+ const addedUsers = pluralizeEntityText(
+ users.map(user => ET`${ET.user({ userInfo: user })}`),
+ );
+
+ return ET`${creator} added ${addedUsers}`;
},
notificationTexts(
diff --git a/lib/shared/messages/remove-members-message-spec.js b/lib/shared/messages/remove-members-message-spec.js
--- a/lib/shared/messages/remove-members-message-spec.js
+++ b/lib/shared/messages/remove-members-message-spec.js
@@ -15,6 +15,11 @@
import type { NotifTexts } from '../../types/notif-types';
import type { ThreadInfo } from '../../types/thread-types';
import type { RelativeUserInfo } from '../../types/user-types';
+import {
+ ET,
+ type EntityText,
+ pluralizeEntityText,
+} from '../../utils/entity-text';
import { values } from '../../utils/objects';
import {
robotextForMessageInfo,
@@ -26,7 +31,6 @@
MessageSpec,
MessageTitleParam,
NotificationTextsParams,
- RobotextParams,
} from './message-spec';
import { joinResult } from './utils';
@@ -122,15 +126,16 @@
return { ...messageData, id };
},
- robotext(
- messageInfo: RemoveMembersMessageInfo,
- creator: string,
- params: RobotextParams,
- ): string {
+ robotext(messageInfo: RemoveMembersMessageInfo): EntityText {
const users = messageInfo.removedMembers;
- invariant(users.length !== 0, 'removed who??');
- const removedUsersString = params.robotextForUsers(users);
- return `${creator} removed ${removedUsersString}`;
+ invariant(users.length !== 0, 'added who??');
+
+ const creator = ET.user({ userInfo: messageInfo.creator });
+ const removedUsers = pluralizeEntityText(
+ users.map(user => ET`${ET.user({ userInfo: user })}`),
+ );
+
+ return ET`${creator} removed ${removedUsers}`;
},
notificationTexts(
diff --git a/lib/utils/entity-text.js b/lib/utils/entity-text.js
--- a/lib/utils/entity-text.js
+++ b/lib/utils/entity-text.js
@@ -11,6 +11,7 @@
type RawThreadInfo,
type ThreadInfo,
} from '../types/thread-types';
+import { basePluralize } from '../utils/text-utils';
type UserEntity = {
+type: 'user',
@@ -288,4 +289,17 @@
});
}
-export { ET, entityTextToRawString, entityTextToReact };
+function pluralizeEntityText(
+ nouns: $ReadOnlyArray<EntityText>,
+ maxNumberOfNouns: number = 3,
+): EntityText {
+ return basePluralize<EntityText>(
+ nouns,
+ maxNumberOfNouns,
+ [],
+ (a: EntityText | string, b: ?EntityText | string) =>
+ b ? ET`${a}${b}` : ET`${a}`,
+ );
+}
+
+export { ET, entityTextToRawString, entityTextToReact, pluralizeEntityText };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 7:32 PM (19 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2531486
Default Alt Text
D6512.id21815.diff (3 KB)
Attached To
Mode
D6512: [lib] Convert AddMembers/RemoveMembers robotext to use EntityText
Attached
Detach File
Event Timeline
Log In to Comment