-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3698 from tloncorp/hm/recursive-unreads
activity: recursive unreads
- Loading branch information
Showing
24 changed files
with
833 additions
and
387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,19 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { useIsChannelUnread } from '@/logic/channel'; | ||
import { useNotifications } from '@/notifications/useNotifications'; | ||
import { useRouteGroup } from '@/state/groups'; | ||
import { useSawRopeMutation } from '@/state/hark'; | ||
|
||
import { nestToFlag } from './utils'; | ||
|
||
interface UseDismissChannelProps { | ||
nest: string; | ||
markRead: (flag: string) => Promise<void> | void; | ||
markRead: () => Promise<void>; | ||
isMarking: boolean; | ||
} | ||
|
||
export default function useDismissChannelNotifications({ | ||
nest, | ||
markRead, | ||
isMarking, | ||
}: UseDismissChannelProps) { | ||
const flag = useRouteGroup(); | ||
const [, chFlag] = nestToFlag(nest); | ||
const unread = useIsChannelUnread(nest); | ||
const { notifications } = useNotifications(flag); | ||
const { mutate: sawRopeMutation } = useSawRopeMutation(); | ||
|
||
/** | ||
* TODO: Confirm expected behavior for navigating to a Channel with Unreads. | ||
* | ||
* Does clicking on an Unread Channel automatically scrollback to the | ||
* last read message? Should it only be dismissed when reaching the end of | ||
* new messages? | ||
*/ | ||
// dismiss unread notifications while viewing channel | ||
useEffect(() => { | ||
if (nest && unread && !isMarking) { | ||
if (!isMarking) { | ||
// dismiss unread | ||
markRead(chFlag); | ||
// iterate bins, saw each rope | ||
notifications.forEach((n) => { | ||
n.skeins.forEach((b) => { | ||
if ( | ||
b.unread && | ||
b.top?.rope.channel && | ||
b.top.rope.channel.includes(chFlag) | ||
) { | ||
sawRopeMutation({ rope: b.top.rope }); | ||
} | ||
}); | ||
}); | ||
markRead(); | ||
} | ||
}, [ | ||
nest, | ||
chFlag, | ||
markRead, | ||
unread, | ||
notifications, | ||
sawRopeMutation, | ||
isMarking, | ||
]); | ||
}, [markRead, isMarking]); | ||
} |
Oops, something went wrong.