mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-15 11:20:36 +08:00
18 lines
521 B
TypeScript
18 lines
521 B
TypeScript
export type GroupedReactions = Map<string, { all: string[]; self: boolean }>;
|
|
|
|
// Takes reactions from a comment and groups them by emoji
|
|
// and if the current user has reacted with that emoji.
|
|
export function groupReactions(
|
|
reactions: [string, string][],
|
|
publicKey?: string,
|
|
) {
|
|
return reactions.reduce(
|
|
(acc, [nid, emoji]) =>
|
|
acc.set(emoji, {
|
|
all: [...(acc.get(emoji)?.all ?? []), nid],
|
|
self: publicKey === nid,
|
|
}),
|
|
new Map<string, { all: string[]; self: boolean }>(),
|
|
);
|
|
}
|