File size: 782 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
26
27
28
// @flow
import { db } from 'shared/db';
import type { DBThreadReaction } from 'shared/types';

// prettier-ignore
export const getThreadReactions = (threadIds: Array<string>): Promise<Array<DBThreadReaction>> => {
  const distinctMessageIds = threadIds.filter((x, i, a) => a.indexOf(x) == i);
  return db
    .table('threadReactions')
    .getAll(...distinctMessageIds, { index: 'threadId' })
    .filter(row => row.hasFields('deletedAt').not())
    .group('threadId')
    .run();
};

export const hasReactedToThread = (
  userId: string,
  threadId: string
): Promise<boolean> => {
  return db
    .table('threadReactions')
    .getAll([userId, threadId], { index: 'userIdAndThreadId' })
    .filter(row => row.hasFields('deletedAt').not())
    .count()
    .eq(1)
    .run();
};