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

export default ({ id }: DBMessage, _: any, { user, loaders }: GraphQLContext) =>
  loaders.messageReaction.load(id).then(result => {
    if (!result)
      return {
        count: 0,
        hasReacted: false,
      };
    const reactions = result.reduction;
    return {
      count: reactions.length,
      hasReacted: user
        ? reactions.some(reaction => reaction.userId === user.id)
        : false,
    };
  });