File size: 748 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// @flow
import type { GraphQLContext } from '../../';
import type { DBThread } from 'shared/types';
import generateImageFromText from '../../utils/generate-thread-meta-image-from-text';
import { signImageUrl } from 'shared/imgix';

export default async (thread: DBThread, _: any, ctx: GraphQLContext) => {
  const { loaders } = ctx;
  const { watercooler, communityId, content } = thread;

  const community = await loaders.community.load(communityId);
  if (!community) return null;

  const imageUrl = generateImageFromText({
    title: watercooler
      ? `Chat with the ${community.name} community`
      : content.title,
    footer: `spectrum.chat/${community.slug}`,
  });

  if (!imageUrl) return null;

  return signImageUrl(imageUrl);
};