Merge pull request #230 from tloncorp/po/land-1048-only-show-dm-notifications-for-talk-in-lanscape

notifications: only show dm notifications for talk
This commit is contained in:
Patrick O'Sullivan 2023-10-11 15:46:15 -05:00 committed by GitHub
commit 36168d738e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {
@ -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();
@ -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),