Download spectrum/api/queries/thread/editedBy.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/queries/thread/editedBy.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/spectrum/api/queries/thread/editedBy.js
-
curl -L -o editedBy.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/spectrum/api/queries/thread/editedBy.js
1.23 kB
| // @flow | |
| import type { GraphQLContext } from '../../'; | |
| import type { DBThread } from 'shared/types'; | |
| export default async ( | |
| { editedBy, communityId, channelId }: DBThread, | |
| _: any, | |
| { loaders }: GraphQLContext | |
| ) => { | |
| if (!editedBy) return null; | |
| let [ | |
| user, | |
| communityPermissions = {}, | |
| channelPermissions = {}, | |
| ] = await Promise.all([ | |
| loaders.user.load(editedBy), | |
| loaders.userPermissionsInCommunity.load([editedBy, communityId]), | |
| loaders.userPermissionsInChannel.load([editedBy, 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, | |
| }; | |
| }; | |