Skip to content

Commit

Permalink
notifications: only show dm notifications for talk
Browse files Browse the repository at this point in the history
  • Loading branch information
patosullivan committed Oct 11, 2023
1 parent 66a0b47 commit c5a45c2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions ui/src/nav/notifications/useNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo } from 'react';
import { useSkeins } from '@/state/hark';
import _ from 'lodash';
import { Skein, Yarn } from '@/gear';
import { Rope, Skein, Yarn } from '@/gear';
import { makePrettyDay } from '@/logic/utils';

export interface DayGrouping {
Expand Down Expand Up @@ -31,6 +31,12 @@ export const isComment = (yarn: Yarn) =>
export const isReply = (yarn: Yarn) =>
yarn.con.some((con) => con === ' replied to your message “');

export const isDM = (rope: Rope) => rope.thread.startsWith('/dm');

export const isClub = (rope: Rope) => rope.thread.startsWith('/club');

export const isGroups = (rope: Rope) => rope.desk === 'groups';

export const useNotifications = (mentionsOnly = false) => {
const { data: skeins, status: skeinsStatus } = useSkeins();

Expand All @@ -44,10 +50,15 @@ export const useNotifications = (mentionsOnly = false) => {
};
}

const unreads = skeins.filter((s) => s.unread);
const filteredSkeins = skeins.filter((s) =>
mentionsOnly ? isMention(s.top) : s
);
const notDmsFromGroupsDesk = (s: Skein) =>
!((isDM(s.top.rope) || isClub(s.top.rope)) && isGroups(s.top.rope));

const unreads = skeins
.filter((s) => s.unread)
.filter((s) => notDmsFromGroupsDesk(s));
const filteredSkeins = skeins
.filter((s) => (mentionsOnly ? isMention(s.top) : s))
.filter((s) => notDmsFromGroupsDesk(s));

return {
notifications: groupSkeinsByDate(filteredSkeins),
Expand Down

0 comments on commit c5a45c2

Please sign in to comment.