File size: 573 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// @flow
import type { GraphQLContext } from '../../';
import type { DBChannel } from 'shared/types';
import { canViewCommunity } from '../../utils/permissions';

export default async (channel: DBChannel, _: any, ctx: GraphQLContext) => {
  const { communityId } = channel;
  const { loaders, user: currentUser } = ctx;

  const community = await loaders.community.load(communityId);
  if (community.isPrivate) {
    if (await canViewCommunity(currentUser, community.id, loaders)) {
      return community;
    } else {
      return null;
    }
  }

  return community;
};