react-code-dataset / spectrum /api /queries /directMessageThread /rootDirectMessageThreadByUserIds.js
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame
693 Bytes
// @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);
});