Download spectrum/api/queries/message/author.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/queries/message/author.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/api/queries/message/author.js
-
curl -L -o author.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/queries/message/author.js
1.56 kB
| // @flow | |
| import type { DBMessage } from 'shared/types'; | |
| import type { GraphQLContext } from '../../'; | |
| export default async ( | |
| { senderId, threadId, threadType }: DBMessage, | |
| _: any, | |
| { loaders }: GraphQLContext | |
| ) => { | |
| // there will be no community to resolve in direct message threads, so we can escape early | |
| // and only return the sender | |
| if (threadType === 'directMessageThread') { | |
| const user = loaders.user.load(senderId); | |
| return { | |
| user, | |
| }; | |
| } | |
| const [thread, user] = await Promise.all([ | |
| loaders.thread.load(threadId), | |
| loaders.user.load(senderId), | |
| ]); | |
| if (!thread || !user) return null; | |
| let [communityPermissions = {}, channelPermissions = {}] = await Promise.all([ | |
| loaders.userPermissionsInCommunity.load([user.id, thread.communityId]), | |
| loaders.userPermissionsInChannel.load([user.id, thread.channelId]), | |
| ]); | |
| if (!communityPermissions) communityPermissions = {}; | |
| if (!channelPermissions) channelPermissions = {}; | |
| const isMember = communityPermissions.isMember || channelPermissions.isMember; | |
| const isOwner = communityPermissions.isOwner; | |
| const isModerator = | |
| communityPermissions.isModerator || channelPermissions.isModerator; | |
| const isBlocked = | |
| channelPermissions.isBlocked || communityPermissions.isBlocked; | |
| const roles = []; | |
| if (isModerator) roles.push('moderator'); | |
| if (isOwner) roles.push('admin'); | |
| if (isBlocked) roles.push('blocked'); | |
| return { | |
| id: communityPermissions.id, | |
| user, | |
| isOwner, | |
| isModerator, | |
| isBlocked, | |
| isMember, | |
| roles, | |
| }; | |
| }; | |