Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3486332
D3597.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
D3597.diff
View Options
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
@@ -31,6 +31,7 @@
import type { RelativeUserInfo, UserInfos } from '../types/user-types';
import { codeBlockRegex, type ParserRules } from './markdown';
import { messageSpecs } from './messages/message-specs';
+import { threadIsGroupChat } from './thread-utils';
import { stringForUser } from './user-utils';
const localIDPrefix = 'local';
@@ -507,6 +508,35 @@
};
}
+type MessagePreviewResult = {
+ +message: string,
+ +username: ?string,
+};
+function getMessagePreview(
+ originalMessageInfo: MessageInfo,
+ threadInfo: ThreadInfo,
+ markdownRules: ParserRules,
+): MessagePreviewResult {
+ const messageInfo: ComposableMessageInfo | RobotextMessageInfo =
+ originalMessageInfo.type === messageTypes.SIDEBAR_SOURCE
+ ? originalMessageInfo.sourceMessage
+ : originalMessageInfo;
+
+ const messageTitle = getMessageTitle(messageInfo, threadInfo, markdownRules);
+
+ const hasUsername =
+ threadIsGroupChat(threadInfo) ||
+ threadInfo.name !== '' ||
+ messageInfo.creator.isViewer;
+
+ let userString = null;
+ if (messageInfo.type === messageTypes.TEXT && hasUsername) {
+ userString = stringForUser(messageInfo.creator);
+ }
+
+ return { message: messageTitle, username: userString };
+}
+
export {
localIDPrefix,
messageKey,
@@ -534,4 +564,5 @@
getMessageTitle,
removeCreatorAsViewer,
mergeThreadMessageInfos,
+ getMessagePreview,
};
diff --git a/web/chat/message-preview.react.js b/web/chat/message-preview.react.js
--- a/web/chat/message-preview.react.js
+++ b/web/chat/message-preview.react.js
@@ -3,15 +3,8 @@
import classNames from 'classnames';
import * as React from 'react';
-import { getMessageTitle } from 'lib/shared/message-utils';
-import { threadIsGroupChat } from 'lib/shared/thread-utils';
-import { stringForUser } from 'lib/shared/user-utils';
-import {
- type MessageInfo,
- messageTypes,
- type ComposableMessageInfo,
- type RobotextMessageInfo,
-} from 'lib/types/message-types';
+import { getMessagePreview } from 'lib/shared/message-utils';
+import { type MessageInfo } from 'lib/types/message-types';
import { type ThreadInfo } from 'lib/types/thread-types';
import { getDefaultTextMessageRules } from '../markdown/rules.react';
@@ -38,26 +31,16 @@
</div>
);
}
- const messageInfo: ComposableMessageInfo | RobotextMessageInfo =
- originalMessageInfo.type === messageTypes.SIDEBAR_SOURCE
- ? originalMessageInfo.sourceMessage
- : originalMessageInfo;
- const messageTitle = getMessageTitle(
- messageInfo,
+ const { message: messageTitle, username } = getMessagePreview(
+ originalMessageInfo,
threadInfo,
getDefaultTextMessageRules().simpleMarkdownRules,
);
- const hasUsername =
- threadIsGroupChat(threadInfo) ||
- threadInfo.name !== '' ||
- messageInfo.creator.isViewer;
-
let usernameText = null;
- if (messageInfo.type === messageTypes.TEXT && hasUsername) {
- const userString = stringForUser(messageInfo.creator);
- usernameText = <span className={colorStyle}>{`${userString}: `}</span>;
+ if (username) {
+ usernameText = <span className={colorStyle}>{`${username}: `}</span>;
}
return (
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 4:32 AM (21 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2675298
Default Alt Text
D3597.diff (3 KB)
Attached To
Mode
D3597: [web] [lib] Introduce `getMessagePreview` function
Attached
Detach File
Event Timeline
Log In to Comment