mirror of
https://github.com/cinnyapp/cinny.git
synced 2026-11-28 21:06:38 -08:00
show notification threads in room list
This commit is contained in:
1 parent
1a7655fe51
commit
9b75cbb41c
6 files changed
+52
-12
No files matched your search
@@ -12,6 +12,7 @@ import { MessageEventWithoutRoomId, UnreadNotificationCounts } from 'neurone/lib
|
||||
import { Box, Chip, Icon, Icons, Text } from 'folds';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { Opts as LinkifyOpts } from 'linkifyjs';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Timeline } from '../../../client/room';
|
||||
import { useObservableValue } from '../../hooks/useObservableValue';
|
||||
import { NavButton, NavItem } from '../../components/nav';
|
||||
@@ -39,7 +40,6 @@ import { useRoomHeroes } from '../../hooks/storage/useRoomHeros';
|
||||
type ThreadNavItemProps = {
|
||||
thread: ThreadTimeline;
|
||||
notification?: UnreadNotificationCounts;
|
||||
selected: boolean;
|
||||
redactedEvents?: Set<string>;
|
||||
editEvents?: MessageEventWithoutRoomId[];
|
||||
htmlReactParserOptions: HTMLReactParserOptions;
|
||||
@@ -49,7 +49,6 @@ type ThreadNavItemProps = {
|
||||
function ThreadNavItem({
|
||||
thread,
|
||||
notification,
|
||||
selected,
|
||||
redactedEvents,
|
||||
editEvents,
|
||||
htmlReactParserOptions,
|
||||
@@ -121,17 +120,20 @@ function ThreadNavItem({
|
||||
}
|
||||
|
||||
type ThreadNavItemsProps = {
|
||||
linkPath: string;
|
||||
timeline: Timeline;
|
||||
roomSelected: boolean;
|
||||
threadNotifications: Map<string, UnreadNotificationCounts>;
|
||||
};
|
||||
export function ThreadNavItems({
|
||||
linkPath,
|
||||
timeline,
|
||||
roomSelected,
|
||||
threadNotifications,
|
||||
}: ThreadNavItemsProps) {
|
||||
const ct = useClient();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const navigate = useNavigate();
|
||||
const [viewMore, setViewMore] = useState(false);
|
||||
|
||||
const threads = useObservableValue(timeline.threads);
|
||||
@@ -175,6 +177,15 @@ export function ThreadNavItems({
|
||||
const threadIds = Array.from(threadNotifications.keys());
|
||||
const slicedThreadIds = viewMore ? threadIds : threadIds.slice(0, 5);
|
||||
|
||||
const handleOpenThread = (threadId: string) => {
|
||||
if (!activeThread) {
|
||||
timeline.openThread(threadId);
|
||||
}
|
||||
if (!roomSelected) {
|
||||
navigate(linkPath);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box className={css.ThreadNavItems} direction="Column">
|
||||
@@ -187,13 +198,12 @@ export function ThreadNavItems({
|
||||
<ThreadNavItem
|
||||
key={threadId}
|
||||
thread={thread}
|
||||
selected={roomSelected && threadId === activeThread}
|
||||
notification={notification}
|
||||
editEvents={edits.get(threadId)}
|
||||
redactedEvents={redactedSet}
|
||||
htmlReactParserOptions={htmlReactParserInlineOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
onClick={() => timeline.openThread(threadId)}
|
||||
onClick={() => handleOpenThread(threadId)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -9,3 +9,4 @@ Please see LICENSE file in root of repository for full details.
|
||||
|
||||
export * from './RoomNavItem';
|
||||
export * from './RoomNavCategoryButton';
|
||||
export * from './ThreadNavItems';
|
||||
@@ -40,7 +40,7 @@ import {
|
||||
import { getDirectCreatePath, getDirectRoomPath } from '../../pathUtils';
|
||||
import { useSelectedRoom } from '../../../hooks/router/useSelectedRoom';
|
||||
import { VirtualTile } from '../../../components/virtualizer';
|
||||
import { RoomNavCategoryButton, RoomNavItem } from '../../../features/room-nav';
|
||||
import { RoomNavCategoryButton, RoomNavItem, ThreadNavItems } from '../../../features/room-nav';
|
||||
import { makeNavCategoryId } from '../../../state/closedNavCategories';
|
||||
import { useCategoryHandler } from '../../../hooks/useCategoryHandler';
|
||||
import { useNavToActivePathMapper } from '../../../hooks/useNavToActivePathMapper';
|
||||
@@ -199,6 +199,7 @@ export function Direct() {
|
||||
const roomToNotifications = useRoomsNotifications(directs, roomToNotificationsAtom);
|
||||
const unreadRooms = useRoomsUnread(directs, unreadRoomsAtom);
|
||||
const roomToLatestEvent = useRoomsLatestEvent(directs);
|
||||
const roomToTimeline = useObservableValue(ct.roomToTimeline);
|
||||
|
||||
const notificationPreferences = useRoomsNotificationPreferencesContext();
|
||||
const navigate = useNavigate();
|
||||
@@ -291,7 +292,9 @@ export function Direct() {
|
||||
const roomId = sortedDirects[vItem.index];
|
||||
const selected = selectedRoomId === roomId;
|
||||
const n = roomToNotifications.get(roomId);
|
||||
const notifications = n && getRoomTotalNotifications(n);
|
||||
const notifications = n && getRoomTotalNotifications(n, true);
|
||||
const threadNotifications = n?.threads;
|
||||
const timeline = roomToTimeline.get(roomId);
|
||||
|
||||
return (
|
||||
<VirtualTile
|
||||
@@ -312,6 +315,15 @@ export function Direct() {
|
||||
notifications={notifications}
|
||||
unread={unreadRooms.has(roomId)}
|
||||
/>
|
||||
|
||||
{timeline && threadNotifications && threadNotifications.size > 0 && (
|
||||
<ThreadNavItems
|
||||
linkPath={getDirectRoomPath(ct.roomToAlias.read.get(roomId) ?? roomId)}
|
||||
roomSelected={selectedRoomId === roomId}
|
||||
timeline={timeline}
|
||||
threadNotifications={threadNotifications}
|
||||
/>
|
||||
)}
|
||||
</VirtualTile>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -53,7 +53,7 @@ import {
|
||||
} from '../../../hooks/router/useHomeSelected';
|
||||
import { useHomeRooms } from './useHomeRooms';
|
||||
import { VirtualTile } from '../../../components/virtualizer';
|
||||
import { RoomNavCategoryButton, RoomNavItem } from '../../../features/room-nav';
|
||||
import { RoomNavCategoryButton, RoomNavItem, ThreadNavItems } from '../../../features/room-nav';
|
||||
import { makeNavCategoryId } from '../../../state/closedNavCategories';
|
||||
import { useCategoryHandler } from '../../../hooks/useCategoryHandler';
|
||||
import { useNavToActivePathMapper } from '../../../hooks/useNavToActivePathMapper';
|
||||
@@ -227,6 +227,7 @@ export function Home() {
|
||||
const roomToNotifications = useRoomsNotifications(rooms, roomToNotificationsAtom);
|
||||
const unreadRooms = useRoomsUnread(rooms, unreadRoomsAtom);
|
||||
const roomToLatestEvent = useRoomsLatestEvent(rooms);
|
||||
const roomToTimeline = useObservableValue(ct.roomToTimeline);
|
||||
|
||||
const notificationPreferences = useRoomsNotificationPreferencesContext();
|
||||
const navigate = useNavigate();
|
||||
@@ -377,7 +378,9 @@ export function Home() {
|
||||
const roomId = sortedRooms[vItem.index];
|
||||
const selected = selectedRoomId === roomId;
|
||||
const n = roomToNotifications.get(roomId);
|
||||
const notifications = n && getRoomTotalNotifications(n);
|
||||
const notifications = n && getRoomTotalNotifications(n, true);
|
||||
const threadNotifications = n?.threads;
|
||||
const timeline = roomToTimeline.get(roomId);
|
||||
|
||||
return (
|
||||
<VirtualTile
|
||||
@@ -398,6 +401,14 @@ export function Home() {
|
||||
notifications={notifications}
|
||||
unread={unreadRooms.has(roomId)}
|
||||
/>
|
||||
{timeline && threadNotifications && threadNotifications.size > 0 && (
|
||||
<ThreadNavItems
|
||||
linkPath={getHomeRoomPath(ct.roomToAlias.read.get(roomId) ?? roomId)}
|
||||
roomSelected={selectedRoomId === roomId}
|
||||
timeline={timeline}
|
||||
threadNotifications={threadNotifications}
|
||||
/>
|
||||
)}
|
||||
</VirtualTile>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -55,7 +55,7 @@ import {
|
||||
} from '../../../hooks/router/useSelectedSpace';
|
||||
import { useSpace } from '../../../hooks/useSpace';
|
||||
import { VirtualTile } from '../../../components/virtualizer';
|
||||
import { RoomNavCategoryButton, RoomNavItem } from '../../../features/room-nav';
|
||||
import { RoomNavCategoryButton, RoomNavItem, ThreadNavItems } from '../../../features/room-nav';
|
||||
import { makeNavCategoryId } from '../../../state/closedNavCategories';
|
||||
import { useCategoryHandler } from '../../../hooks/useCategoryHandler';
|
||||
import { useNavToActivePathMapper } from '../../../hooks/useNavToActivePathMapper';
|
||||
@@ -102,7 +102,6 @@ import { useAllJoinedRoomsSet } from '../../../hooks/useAllJoinedRoomsSet';
|
||||
import { unreadRoomsAtom } from '../../../state/room/roomToUnread';
|
||||
import { useRoomsUnread } from '../../../state/hooks/unread';
|
||||
import { RoomAccessIndicator } from '../../../components/RoomAccessIndicator';
|
||||
import { ThreadNavItems } from '../../../features/room-nav/ThreadNavItems';
|
||||
|
||||
type SpaceMenuProps = {
|
||||
requestClose: () => void;
|
||||
@@ -528,7 +527,7 @@ export function Space() {
|
||||
}
|
||||
|
||||
const n = roomToNotifications.get(roomId);
|
||||
const notifications = n && getRoomTotalNotifications(n);
|
||||
const notifications = n && getRoomTotalNotifications(n, true);
|
||||
const threadNotifications = n?.threads;
|
||||
const timeline = roomToTimeline.get(roomId);
|
||||
|
||||
@@ -548,6 +547,7 @@ export function Space() {
|
||||
/>
|
||||
{timeline && threadNotifications && threadNotifications.size > 0 && (
|
||||
<ThreadNavItems
|
||||
linkPath={getToLink(roomId)}
|
||||
roomSelected={selectedRoomId === roomId}
|
||||
timeline={timeline}
|
||||
threadNotifications={threadNotifications}
|
||||
|
||||
@@ -112,13 +112,19 @@ export const getRoomsTotalNotifications = (
|
||||
export const useRoomsTotalNotifications = (roomsToNotifications: RoomToNotifications) =>
|
||||
useMemo(() => getRoomsTotalNotifications(roomsToNotifications), [roomsToNotifications]);
|
||||
|
||||
export const getRoomTotalNotifications = (notifications?: Notifications): TotalNotifications => {
|
||||
export const getRoomTotalNotifications = (
|
||||
notifications?: Notifications,
|
||||
excludeThreads?: boolean
|
||||
): TotalNotifications => {
|
||||
const total: TotalNotifications = {
|
||||
count: 0,
|
||||
highlight: false,
|
||||
};
|
||||
|
||||
setTotal(total, notifications ?? {});
|
||||
|
||||
if (excludeThreads) return total;
|
||||
|
||||
notifications?.threads.forEach((tn) => setTotal(total, tn));
|
||||
|
||||
return total;
|
||||
|
||||
Reference in new issue
Block a user