1
Fork 0
mirror of https://github.com/RGBCube/cinny synced 2025-07-30 16:37:46 +00:00

Stop showing notification from invite/left rooms (#2267)

This commit is contained in:
Ajay Bura 2025-03-12 22:50:23 +11:00 committed by GitHub
parent d8009978e5
commit 00f3df8719
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -26,6 +26,7 @@ import {
import { useVirtualizer } from '@tanstack/react-virtual'; import { useVirtualizer } from '@tanstack/react-virtual';
import { HTMLReactParserOptions } from 'html-react-parser'; import { HTMLReactParserOptions } from 'html-react-parser';
import { Opts as LinkifyOpts } from 'linkifyjs'; import { Opts as LinkifyOpts } from 'linkifyjs';
import { useAtomValue } from 'jotai';
import { Page, PageContent, PageContentCenter, PageHeader } from '../../../components/page'; import { Page, PageContent, PageContentCenter, PageHeader } from '../../../components/page';
import { useMatrixClient } from '../../../hooks/useMatrixClient'; import { useMatrixClient } from '../../../hooks/useMatrixClient';
import { getMxIdLocalPart, mxcUrlToHttp } from '../../../utils/matrix'; import { getMxIdLocalPart, mxcUrlToHttp } from '../../../utils/matrix';
@ -82,6 +83,7 @@ import { useSpoilerClickHandler } from '../../../hooks/useSpoilerClickHandler';
import { ScreenSize, useScreenSizeContext } from '../../../hooks/useScreenSize'; import { ScreenSize, useScreenSizeContext } from '../../../hooks/useScreenSize';
import { BackRouteHandler } from '../../../components/BackRouteHandler'; import { BackRouteHandler } from '../../../components/BackRouteHandler';
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication'; import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
import { allRoomsAtom } from '../../../state/room-list/roomList';
type RoomNotificationsGroup = { type RoomNotificationsGroup = {
roomId: string; roomId: string;
@ -94,9 +96,14 @@ type NotificationTimeline = {
type LoadTimeline = (from?: string) => Promise<void>; type LoadTimeline = (from?: string) => Promise<void>;
type SilentReloadTimeline = () => Promise<void>; type SilentReloadTimeline = () => Promise<void>;
const groupNotifications = (notifications: INotification[]): RoomNotificationsGroup[] => { const groupNotifications = (
notifications: INotification[],
allowRooms: Set<string>
): RoomNotificationsGroup[] => {
const groups: RoomNotificationsGroup[] = []; const groups: RoomNotificationsGroup[] = [];
notifications.forEach((notification) => { notifications.forEach((notification) => {
if (!allowRooms.has(notification.room_id)) return;
const groupIndex = groups.length - 1; const groupIndex = groups.length - 1;
const lastAddedGroup: RoomNotificationsGroup | undefined = groups[groupIndex]; const lastAddedGroup: RoomNotificationsGroup | undefined = groups[groupIndex];
if (lastAddedGroup && notification.room_id === lastAddedGroup.roomId) { if (lastAddedGroup && notification.room_id === lastAddedGroup.roomId) {
@ -116,6 +123,9 @@ const useNotificationTimeline = (
onlyHighlight?: boolean onlyHighlight?: boolean
): [NotificationTimeline, LoadTimeline, SilentReloadTimeline] => { ): [NotificationTimeline, LoadTimeline, SilentReloadTimeline] => {
const mx = useMatrixClient(); const mx = useMatrixClient();
const allRooms = useAtomValue(allRoomsAtom);
const allJoinedRooms = useMemo(() => new Set(allRooms), [allRooms]);
const [notificationTimeline, setNotificationTimeline] = useState<NotificationTimeline>({ const [notificationTimeline, setNotificationTimeline] = useState<NotificationTimeline>({
groups: [], groups: [],
}); });
@ -142,7 +152,7 @@ const useNotificationTimeline = (
paginationLimit, paginationLimit,
onlyHighlight ? 'highlight' : undefined onlyHighlight ? 'highlight' : undefined
); );
const groups = groupNotifications(data.notifications); const groups = groupNotifications(data.notifications, allJoinedRooms);
setNotificationTimeline((currentTimeline) => { setNotificationTimeline((currentTimeline) => {
if (currentTimeline.nextToken === from) { if (currentTimeline.nextToken === from) {
@ -154,7 +164,7 @@ const useNotificationTimeline = (
return currentTimeline; return currentTimeline;
}); });
}, },
[paginationLimit, onlyHighlight, fetchNotifications] [paginationLimit, onlyHighlight, fetchNotifications, allJoinedRooms]
); );
/** /**
@ -167,12 +177,12 @@ const useNotificationTimeline = (
paginationLimit, paginationLimit,
onlyHighlight ? 'highlight' : undefined onlyHighlight ? 'highlight' : undefined
); );
const groups = groupNotifications(data.notifications); const groups = groupNotifications(data.notifications, allJoinedRooms);
setNotificationTimeline({ setNotificationTimeline({
nextToken: data.next_token, nextToken: data.next_token,
groups, groups,
}); });
}, [paginationLimit, onlyHighlight, fetchNotifications]); }, [paginationLimit, onlyHighlight, fetchNotifications, allJoinedRooms]);
return [notificationTimeline, loadTimeline, silentReloadTimeline]; return [notificationTimeline, loadTimeline, silentReloadTimeline];
}; };