Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3504949
D6526.id21858.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
27 KB
Referenced Files
None
Subscribers
None
D6526.id21858.diff
View Options
diff --git a/lib/selectors/chat-selectors.js b/lib/selectors/chat-selectors.js
--- a/lib/selectors/chat-selectors.js
+++ b/lib/selectors/chat-selectors.js
@@ -276,7 +276,7 @@
+startsConversation: boolean,
+startsCluster: boolean,
endsCluster: boolean,
- +robotext: EntityText | string,
+ +robotext: EntityText,
+threadCreatedFromMessage: ?ThreadInfo,
+reactions: $ReadOnlyMap<string, MessageReactionInfo>,
};
diff --git a/lib/shared/message-utils.js b/lib/shared/message-utils.js
--- a/lib/shared/message-utils.js
+++ b/lib/shared/message-utils.js
@@ -30,9 +30,8 @@
ReactionMessageInfo,
} from '../types/messages/reaction';
import { type ThreadInfo } from '../types/thread-types';
-import type { RelativeUserInfo, UserInfos } from '../types/user-types';
-import { type EntityText, entityTextToRawString } from '../utils/entity-text';
-import { pluralize } from '../utils/text-utils';
+import type { UserInfos } from '../types/user-types';
+import type { EntityText } from '../utils/entity-text';
import { codeBlockRegex, type ParserRules } from './markdown';
import { messageSpecs } from './messages/message-specs';
import { threadIsGroupChat } from './thread-utils';
@@ -57,50 +56,16 @@
return messageInfo.localID;
}
-function robotextForUser(user: RelativeUserInfo): string {
- if (user.isViewer) {
- return 'you';
- } else if (user.username) {
- return `<${encodeURI(user.username)}|u${user.id}>`;
- } else {
- return 'anonymous';
- }
-}
-
-function robotextForUsers(users: RelativeUserInfo[]): string {
- return pluralize(users.map(robotextForUser), 3);
-}
-
-function encodedThreadEntity(threadID: string, text: string): string {
- return `<${text}|t${threadID}>`;
-}
-
function robotextForMessageInfo(
messageInfo: RobotextMessageInfo,
threadInfo: ?ThreadInfo,
-): string | EntityText {
- const creator = robotextForUser(messageInfo.creator);
+): EntityText {
const messageSpec = messageSpecs[messageInfo.type];
invariant(
messageSpec.robotext,
`we're not aware of messageType ${messageInfo.type}`,
);
- return messageSpec.robotext(messageInfo, creator, {
- encodedThreadEntity,
- robotextForUsers,
- robotextForUser,
- threadInfo,
- });
-}
-
-function robotextToRawString(
- robotext: string | EntityText,
- threadID?: string,
-): string {
- if (typeof robotext !== 'string') {
- return entityTextToRawString(robotext, threadID);
- }
- return decodeURI(robotext.replace(/<([^<>|]+)\|[^<>|]+>/g, '$1'));
+ return messageSpec.robotext(messageInfo, { threadInfo });
}
function createMessageInfo(
@@ -211,25 +176,6 @@
return _maxBy('time')(messageInfos).time;
}
-function splitRobotext(robotext: string): string[] {
- return robotext.split(/(<[^<>|]+\|[^<>|]+>)/g);
-}
-
-const robotextEntityRegex = /<([^<>|]+)\|([^<>|]+)>/;
-type RobotextEntityInfo = {
- +rawText: string,
- +entityType: string,
- +id: string,
-};
-function parseRobotextEntity(robotextPart: string): RobotextEntityInfo {
- const entityParts = robotextPart.match(robotextEntityRegex);
- invariant(entityParts && entityParts[1], 'malformed robotext');
- const rawText = decodeURI(entityParts[1]);
- const entityType = entityParts[2].charAt(0);
- const id = entityParts[2].substr(1);
- return { rawText, entityType, id };
-}
-
function usersInMessageInfos(
messageInfos: $ReadOnlyArray<MessageInfo | RawMessageInfo>,
): string[] {
@@ -560,14 +506,11 @@
messageKey,
messageID,
robotextForMessageInfo,
- robotextToRawString,
createMessageInfo,
sortMessageInfoList,
sortMessageIDs,
rawMessageInfoFromMessageData,
mostRecentMessageTimestamp,
- splitRobotext,
- parseRobotextEntity,
usersInMessageInfos,
combineTruncationStatuses,
shimUnsupportedRawMessageInfos,
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
@@ -19,11 +19,11 @@
ET,
type EntityText,
pluralizeEntityText,
+ entityTextToRawString,
} from '../../utils/entity-text';
import { values } from '../../utils/objects';
import {
robotextForMessageInfo,
- robotextToRawString,
removeCreatorAsViewer,
} from '../message-utils';
import type {
@@ -65,7 +65,7 @@
})),
};
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/change-role-message-spec.js b/lib/shared/messages/change-role-message-spec.js
--- a/lib/shared/messages/change-role-message-spec.js
+++ b/lib/shared/messages/change-role-message-spec.js
@@ -19,10 +19,10 @@
ET,
type EntityText,
pluralizeEntityText,
+ entityTextToRawString,
} from '../../utils/entity-text';
import { values } from '../../utils/objects';
import {
- robotextToRawString,
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -70,7 +70,7 @@
})),
};
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
@@ -136,7 +136,6 @@
robotext(
messageInfo: ChangeRoleMessageInfo,
- creatorString: string,
params: RobotextParams,
): EntityText {
const users = messageInfo.members;
diff --git a/lib/shared/messages/change-settings-message-spec.js b/lib/shared/messages/change-settings-message-spec.js
--- a/lib/shared/messages/change-settings-message-spec.js
+++ b/lib/shared/messages/change-settings-message-spec.js
@@ -16,10 +16,13 @@
import { assertThreadType } from '../../types/thread-types';
import type { ThreadInfo } from '../../types/thread-types';
import type { RelativeUserInfo } from '../../types/user-types';
-import { ET, type EntityText } from '../../utils/entity-text';
+import {
+ ET,
+ type EntityText,
+ entityTextToRawString,
+} from '../../utils/entity-text';
import { validHexColorRegex } from '../account-utils';
import {
- robotextToRawString,
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -58,7 +61,7 @@
if (viewerContext === 'global_viewer') {
validMessageInfo = removeCreatorAsViewer(validMessageInfo);
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/create-entry-message-spec.js b/lib/shared/messages/create-entry-message-spec.js
--- a/lib/shared/messages/create-entry-message-spec.js
+++ b/lib/shared/messages/create-entry-message-spec.js
@@ -16,9 +16,12 @@
import type { ThreadInfo } from '../../types/thread-types';
import type { RelativeUserInfo } from '../../types/user-types';
import { prettyDate } from '../../utils/date-utils';
-import { ET, type EntityText } from '../../utils/entity-text';
import {
- robotextToRawString,
+ ET,
+ type EntityText,
+ entityTextToRawString,
+} from '../../utils/entity-text';
+import {
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -59,7 +62,7 @@
if (viewerContext === 'global_viewer') {
validMessageInfo = removeCreatorAsViewer(validMessageInfo);
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/create-sidebar-message-spec.js b/lib/shared/messages/create-sidebar-message-spec.js
--- a/lib/shared/messages/create-sidebar-message-spec.js
+++ b/lib/shared/messages/create-sidebar-message-spec.js
@@ -21,9 +21,9 @@
ET,
type EntityText,
pluralizeEntityText,
+ entityTextToRawString,
} from '../../utils/entity-text';
import {
- robotextToRawString,
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -80,7 +80,7 @@
},
};
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/create-sub-thread-message-spec.js b/lib/shared/messages/create-sub-thread-message-spec.js
--- a/lib/shared/messages/create-sub-thread-message-spec.js
+++ b/lib/shared/messages/create-sub-thread-message-spec.js
@@ -17,9 +17,12 @@
import { threadPermissions, threadTypes } from '../../types/thread-types';
import type { ThreadInfo } from '../../types/thread-types';
import type { RelativeUserInfo } from '../../types/user-types';
-import { ET, type EntityText } from '../../utils/entity-text';
import {
- robotextToRawString,
+ ET,
+ type EntityText,
+ entityTextToRawString,
+} from '../../utils/entity-text';
+import {
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -57,7 +60,7 @@
if (viewerContext === 'global_viewer') {
validMessageInfo = removeCreatorAsViewer(validMessageInfo);
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/create-thread-message-spec.js b/lib/shared/messages/create-thread-message-spec.js
--- a/lib/shared/messages/create-thread-message-spec.js
+++ b/lib/shared/messages/create-thread-message-spec.js
@@ -19,9 +19,9 @@
ET,
type EntityText,
pluralizeEntityText,
+ entityTextToRawString,
} from '../../utils/entity-text';
import {
- robotextToRawString,
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -71,7 +71,7 @@
},
};
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/delete-entry-message-spec.js b/lib/shared/messages/delete-entry-message-spec.js
--- a/lib/shared/messages/delete-entry-message-spec.js
+++ b/lib/shared/messages/delete-entry-message-spec.js
@@ -16,9 +16,12 @@
import type { ThreadInfo } from '../../types/thread-types';
import type { RelativeUserInfo } from '../../types/user-types';
import { prettyDate } from '../../utils/date-utils';
-import { ET, type EntityText } from '../../utils/entity-text';
import {
- robotextToRawString,
+ ET,
+ type EntityText,
+ entityTextToRawString,
+} from '../../utils/entity-text';
+import {
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -59,7 +62,7 @@
if (viewerContext === 'global_viewer') {
validMessageInfo = removeCreatorAsViewer(validMessageInfo);
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/edit-entry-message-spec.js b/lib/shared/messages/edit-entry-message-spec.js
--- a/lib/shared/messages/edit-entry-message-spec.js
+++ b/lib/shared/messages/edit-entry-message-spec.js
@@ -16,9 +16,12 @@
import type { ThreadInfo } from '../../types/thread-types';
import type { RelativeUserInfo } from '../../types/user-types';
import { prettyDate } from '../../utils/date-utils';
-import { ET, type EntityText } from '../../utils/entity-text';
import {
- robotextToRawString,
+ ET,
+ type EntityText,
+ entityTextToRawString,
+} from '../../utils/entity-text';
+import {
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -59,7 +62,7 @@
if (viewerContext === 'global_viewer') {
validMessageInfo = removeCreatorAsViewer(validMessageInfo);
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/join-thread-message-spec.js b/lib/shared/messages/join-thread-message-spec.js
--- a/lib/shared/messages/join-thread-message-spec.js
+++ b/lib/shared/messages/join-thread-message-spec.js
@@ -15,11 +15,14 @@
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 } from '../../utils/entity-text';
+import {
+ ET,
+ type EntityText,
+ entityTextToRawString,
+} from '../../utils/entity-text';
import { values } from '../../utils/objects';
import { pluralize } from '../../utils/text-utils';
import {
- robotextToRawString,
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -68,7 +71,7 @@
if (viewerContext === 'global_viewer') {
validMessageInfo = removeCreatorAsViewer(validMessageInfo);
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/leave-thread-message-spec.js b/lib/shared/messages/leave-thread-message-spec.js
--- a/lib/shared/messages/leave-thread-message-spec.js
+++ b/lib/shared/messages/leave-thread-message-spec.js
@@ -15,11 +15,14 @@
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 } from '../../utils/entity-text';
+import {
+ ET,
+ type EntityText,
+ entityTextToRawString,
+} from '../../utils/entity-text';
import { values } from '../../utils/objects';
import { pluralize } from '../../utils/text-utils';
import {
- robotextToRawString,
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -68,7 +71,7 @@
if (viewerContext === 'global_viewer') {
validMessageInfo = removeCreatorAsViewer(validMessageInfo);
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/message-spec.js b/lib/shared/messages/message-spec.js
--- a/lib/shared/messages/message-spec.js
+++ b/lib/shared/messages/message-spec.js
@@ -43,9 +43,6 @@
};
export type RobotextParams = {
- +encodedThreadEntity: (threadID: string, text: string) => string,
- +robotextForUsers: (users: RelativeUserInfo[]) => string,
- +robotextForUser: (user: RelativeUserInfo) => string,
+threadInfo: ?ThreadInfo,
};
@@ -97,11 +94,7 @@
params: CreateMessageInfoParams,
) => ?Info,
+rawMessageInfoFromMessageData?: (messageData: Data, id: ?string) => RawInfo,
- +robotext?: (
- messageInfo: Info,
- creator: string,
- params: RobotextParams,
- ) => string | EntityText,
+ +robotext?: (messageInfo: Info, params: RobotextParams) => EntityText,
+shimUnsupportedMessageInfo?: (
rawMessageInfo: RawInfo,
platformDetails: ?PlatformDetails,
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
@@ -19,11 +19,11 @@
ET,
type EntityText,
pluralizeEntityText,
+ entityTextToRawString,
} from '../../utils/entity-text';
import { values } from '../../utils/objects';
import {
robotextForMessageInfo,
- robotextToRawString,
removeCreatorAsViewer,
} from '../message-utils';
import type {
@@ -65,7 +65,7 @@
})),
};
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/restore-entry-message-spec.js b/lib/shared/messages/restore-entry-message-spec.js
--- a/lib/shared/messages/restore-entry-message-spec.js
+++ b/lib/shared/messages/restore-entry-message-spec.js
@@ -16,9 +16,12 @@
import type { ThreadInfo } from '../../types/thread-types';
import type { RelativeUserInfo } from '../../types/user-types';
import { prettyDate } from '../../utils/date-utils';
-import { ET, type EntityText } from '../../utils/entity-text';
import {
- robotextToRawString,
+ ET,
+ type EntityText,
+ entityTextToRawString,
+} from '../../utils/entity-text';
+import {
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -59,7 +62,7 @@
if (viewerContext === 'global_viewer') {
validMessageInfo = removeCreatorAsViewer(validMessageInfo);
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/unsupported-message-spec.js b/lib/shared/messages/unsupported-message-spec.js
--- a/lib/shared/messages/unsupported-message-spec.js
+++ b/lib/shared/messages/unsupported-message-spec.js
@@ -11,9 +11,12 @@
UnsupportedMessageInfo,
} from '../../types/messages/unsupported';
import type { RelativeUserInfo } from '../../types/user-types';
-import { ET, type EntityText } from '../../utils/entity-text';
import {
- robotextToRawString,
+ ET,
+ type EntityText,
+ entityTextToRawString,
+} from '../../utils/entity-text';
+import {
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -83,7 +86,7 @@
if (viewerContext === 'global_viewer') {
validMessageInfo = removeCreatorAsViewer(validMessageInfo);
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/messages/update-relationship-message-spec.js b/lib/shared/messages/update-relationship-message-spec.js
--- a/lib/shared/messages/update-relationship-message-spec.js
+++ b/lib/shared/messages/update-relationship-message-spec.js
@@ -17,9 +17,12 @@
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 } from '../../utils/entity-text';
import {
- robotextToRawString,
+ ET,
+ type EntityText,
+ entityTextToRawString,
+} from '../../utils/entity-text';
+import {
robotextForMessageInfo,
removeCreatorAsViewer,
} from '../message-utils';
@@ -64,7 +67,7 @@
target: { ...validMessageInfo.target, isViewer: false },
};
}
- return robotextToRawString(
+ return entityTextToRawString(
robotextForMessageInfo(validMessageInfo, threadInfo),
);
},
diff --git a/lib/shared/notif-utils.js b/lib/shared/notif-utils.js
--- a/lib/shared/notif-utils.js
+++ b/lib/shared/notif-utils.js
@@ -11,8 +11,9 @@
import type { NotifTexts } from '../types/notif-types';
import type { ThreadInfo, ThreadType } from '../types/thread-types';
import type { RelativeUserInfo } from '../types/user-types';
+import { entityTextToRawString } from '../utils/entity-text';
import { trimText } from '../utils/text-utils';
-import { robotextForMessageInfo, robotextToRawString } from './message-utils';
+import { robotextForMessageInfo } from './message-utils';
import { messageSpecs } from './messages/message-specs';
import { threadNoun } from './thread-utils';
import { stringForUser } from './user-utils';
@@ -97,23 +98,17 @@
): string {
const robotext = robotextForMessageInfo(messageInfo, threadInfo);
const threadName = notifThreadName(threadInfo);
- if (typeof robotext === 'string') {
- const threadEntityRegex = new RegExp(`<[^<>\\|]+\\|t${threadInfo.id}>`);
- const threadMadeExplicit = robotext.replace(threadEntityRegex, threadName);
- return robotextToRawString(threadMadeExplicit);
- } else {
- const threadMadeExplicit = robotext.map(entity => {
- if (
- typeof entity !== 'string' &&
- entity.type === 'thread' &&
- entity.id === threadInfo.id
- ) {
- return threadName;
- }
- return entity;
- });
- return robotextToRawString(threadMadeExplicit);
- }
+ const threadMadeExplicit = robotext.map(entity => {
+ if (
+ typeof entity !== 'string' &&
+ entity.type === 'thread' &&
+ entity.id === threadInfo.id
+ ) {
+ return threadName;
+ }
+ return entity;
+ });
+ return entityTextToRawString(threadMadeExplicit);
}
function notifCollapseKeyForRawMessageInfo(
diff --git a/native/chat/chat-item-height-measurer.react.js b/native/chat/chat-item-height-measurer.react.js
--- a/native/chat/chat-item-height-measurer.react.js
+++ b/native/chat/chat-item-height-measurer.react.js
@@ -4,8 +4,9 @@
import * as React from 'react';
import type { ChatMessageItem } from 'lib/selectors/chat-selectors';
-import { messageID, robotextToRawString } from 'lib/shared/message-utils';
+import { messageID } from 'lib/shared/message-utils';
import { messageTypes, type MessageType } from 'lib/types/message-types';
+import { entityTextToRawString } from 'lib/utils/entity-text';
import NodeHeightMeasurer from '../components/node-height-measurer.react';
import { InputStateContext } from '../input/input-state';
@@ -29,7 +30,7 @@
if (messageInfo.type === messageTypes.TEXT) {
return messageInfo.text;
} else if (item.robotext) {
- return robotextToRawString(item.robotext, item.messageInfo.threadID);
+ return entityTextToRawString(item.robotext, item.messageInfo.threadID);
}
return null;
};
diff --git a/native/chat/inner-robotext-message.react.js b/native/chat/inner-robotext-message.react.js
--- a/native/chat/inner-robotext-message.react.js
+++ b/native/chat/inner-robotext-message.react.js
@@ -6,11 +6,10 @@
import { threadInfoSelector } from 'lib/selectors/thread-selectors';
import {
- splitRobotext,
- parseRobotextEntity,
- robotextToRawString,
-} from 'lib/shared/message-utils';
-import { entityTextToReact, type EntityText } from 'lib/utils/entity-text';
+ entityTextToReact,
+ entityTextToRawString,
+ type EntityText,
+} from 'lib/utils/entity-text';
import Markdown from '../markdown/markdown.react';
import { inlineMarkdownRules } from '../markdown/rules.react';
@@ -20,13 +19,13 @@
import { useNavigateToThread } from './message-list-types';
function dummyNodeForRobotextMessageHeightMeasurement(
- robotext: string | EntityText,
+ robotext: EntityText,
threadID: string,
): React.Element<typeof View> {
return (
<View style={unboundStyles.robotextContainer}>
<Text style={unboundStyles.dummyRobotext}>
- {robotextToRawString(robotext, threadID)}
+ {entityTextToRawString(robotext, threadID)}
</Text>
</View>
);
@@ -46,59 +45,21 @@
const { threadID } = messageInfo;
const textParts = React.useMemo(() => {
const darkColor = activeTheme === 'dark';
-
- if (typeof robotext !== 'string') {
- return entityTextToReact(robotext, threadID, {
- // eslint-disable-next-line react/display-name
- renderText: ({ text }) => (
- <Markdown
- style={styles.robotext}
- rules={inlineMarkdownRules(darkColor)}
- >
- {text}
- </Markdown>
- ),
- // eslint-disable-next-line react/display-name
- renderThread: ({ id, name }) => <ThreadEntity id={id} name={name} />,
- // eslint-disable-next-line react/display-name
- renderColor: ({ hex }) => <ColorEntity color={hex} />,
- });
- }
-
- const robotextParts = splitRobotext(robotext);
- const result = [];
- let keyIndex = 0;
-
- for (const splitPart of robotextParts) {
- if (splitPart === '') {
- continue;
- }
- const key = `text${keyIndex++}`;
- if (splitPart.charAt(0) !== '<') {
- result.push(
- <Markdown
- style={styles.robotext}
- key={key}
- rules={inlineMarkdownRules(darkColor)}
- >
- {decodeURI(splitPart)}
- </Markdown>,
- );
- continue;
- }
-
- const { rawText, entityType, id } = parseRobotextEntity(splitPart);
-
- if (entityType === 't' && id !== threadID) {
- result.push(<ThreadEntity key={key} id={id} name={rawText} />);
- } else if (entityType === 'c') {
- result.push(<ColorEntity key={key} color={rawText} />);
- } else {
- result.push(rawText);
- }
- }
-
- return result;
+ return entityTextToReact(robotext, threadID, {
+ // eslint-disable-next-line react/display-name
+ renderText: ({ text }) => (
+ <Markdown
+ style={styles.robotext}
+ rules={inlineMarkdownRules(darkColor)}
+ >
+ {text}
+ </Markdown>
+ ),
+ // eslint-disable-next-line react/display-name
+ renderThread: ({ id, name }) => <ThreadEntity id={id} name={name} />,
+ // eslint-disable-next-line react/display-name
+ renderColor: ({ hex }) => <ColorEntity color={hex} />,
+ });
}, [robotext, activeTheme, threadID, styles.robotext]);
const viewStyle = [styles.robotextContainer];
diff --git a/native/types/chat-types.js b/native/types/chat-types.js
--- a/native/types/chat-types.js
+++ b/native/types/chat-types.js
@@ -20,7 +20,7 @@
+startsConversation: boolean,
+startsCluster: boolean,
+endsCluster: boolean,
- +robotext: string | EntityText,
+ +robotext: EntityText,
+threadCreatedFromMessage: ?ThreadInfo,
+contentHeight: number,
+reactions: $ReadOnlyMap<string, MessageReactionInfo>,
diff --git a/web/chat/robotext-message.react.js b/web/chat/robotext-message.react.js
--- a/web/chat/robotext-message.react.js
+++ b/web/chat/robotext-message.react.js
@@ -5,10 +5,9 @@
import { type RobotextChatMessageInfoItem } from 'lib/selectors/chat-selectors';
import { threadInfoSelector } from 'lib/selectors/thread-selectors';
-import { splitRobotext, parseRobotextEntity } from 'lib/shared/message-utils';
import type { Dispatch } from 'lib/types/redux-types';
import { type ThreadInfo } from 'lib/types/thread-types';
-import { type EntityText, entityTextToReact } from 'lib/utils/entity-text';
+import { entityTextToReact } from 'lib/utils/entity-text';
import Markdown from '../markdown/markdown.react';
import { linkRules } from '../markdown/rules.react';
@@ -72,47 +71,7 @@
const { item } = this.props;
const { robotext } = item;
const { threadID } = item.messageInfo;
- if (typeof robotext === 'string') {
- return this.renderStringRobotext(robotext, threadID);
- } else {
- return this.renderEntityText(robotext, threadID);
- }
- }
-
- renderStringRobotext(robotext: string, threadID: string): React.Node {
- const robotextParts = splitRobotext(robotext);
- const textParts = [];
- let keyIndex = 0;
- for (const splitPart of robotextParts) {
- if (splitPart === '') {
- continue;
- }
- const key = `text${keyIndex++}`;
- if (splitPart.charAt(0) !== '<') {
- textParts.push(
- <Markdown key={key} rules={linkRules(false)}>
- {decodeURI(splitPart)}
- </Markdown>,
- );
- continue;
- }
-
- const { rawText, entityType, id } = parseRobotextEntity(splitPart);
-
- if (entityType === 't' && id !== threadID) {
- textParts.push(<ThreadEntity key={key} id={id} name={rawText} />);
- } else if (entityType === 'c') {
- textParts.push(<ColorEntity key={key} color={rawText} />);
- } else {
- textParts.push(rawText);
- }
- }
-
- return textParts;
- }
-
- renderEntityText(entityText: EntityText, threadID: string): React.Node {
- return entityTextToReact(entityText, threadID, {
+ return entityTextToReact(robotext, threadID, {
renderText: ({ text }) => (
<Markdown rules={linkRules(false)}>{text}</Markdown>
),
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 21, 11:28 AM (19 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2686618
Default Alt Text
D6526.id21858.diff (27 KB)
Attached To
Mode
D6526: [lib][native][web] Deprecate code for dealing with old robotext
Attached
Detach File
Event Timeline
Log In to Comment