File size: 693 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// @flow
import type { GraphQLContext } from '../../';
import { checkForExistingDMThread } from '../../models/directMessageThread';
import { isAuthedResolver as requireAuth } from '../../utils/permissions';

type Args = {
  userIds: Array<string>,
};

export default requireAuth(async (_: any, args: Args, ctx: GraphQLContext) => {
  // signed out users will never be able to view a dm thread
  const { user: currentUser, loaders } = ctx;
  const { userIds } = args;

  const allMemberIds = [...userIds, currentUser.id];
  const existingThread = await checkForExistingDMThread(allMemberIds);

  if (!existingThread) return null;

  return loaders.directMessageThread.load(existingThread);
});