Download spectrum/api/queries/directMessageThread/snippet.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 832 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/queries/directMessageThread/snippet.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/api/queries/directMessageThread/snippet.js
-
curl -L -o snippet.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/queries/directMessageThread/snippet.js
832 Bytes
| // @flow | |
| import type { GraphQLContext } from '../../'; | |
| import { canViewDMThread } from '../../utils/permissions'; | |
| import { toPlainText, toState } from 'shared/draft-utils'; | |
| import { messageTypeObj } from 'shared/draft-utils/process-message-content'; | |
| export default async ( | |
| { id }: { id: string }, | |
| _: any, | |
| { loaders, user }: GraphQLContext | |
| ) => { | |
| if (!user || !user.id) return null; | |
| const canViewThread = await canViewDMThread(user.id, id, loaders); | |
| if (!canViewThread) return null; | |
| return loaders.directMessageSnippet.load(id).then(message => { | |
| if (!message) return 'No messages yet...'; | |
| if (message.messageType === 'media') return '📷 Photo'; | |
| return message.messageType === messageTypeObj.draftjs | |
| ? toPlainText(toState(JSON.parse(message.content.body))) | |
| : message.content.body; | |
| }); | |
| }; | |