use room creation event for activity sorting if latest event not found
This commit is contained in:
parent
24f5f7d679
commit
a2c8b0175f
5 changed files with 46 additions and 22 deletions
|
|
@ -38,7 +38,7 @@ import {
|
|||
import { RoomAvatar, RoomIcon } from '../../components/room-avatar';
|
||||
import { getAllParents, guessPerfectParent } from '../../utils/room';
|
||||
import { highlightText, makeHighlightRegex } from '../../plugins/react-custom-html-parser';
|
||||
import { factoryRoomIdByActivity } from '../../utils/sort';
|
||||
import { activityTsScope, factoryRoomIdByActivity } from '../../utils/sort';
|
||||
import { nameInitials } from '../../utils/common';
|
||||
import { useRoomNavigate } from '../../hooks/useRoomNavigate';
|
||||
import { useListFocusIndex } from '../../hooks/useListFocusIndex';
|
||||
|
|
@ -85,19 +85,23 @@ const useTopActiveRooms = (
|
|||
const roomToLatestEvent = useObservableValue(ct.roomToLatestEvent);
|
||||
|
||||
return useMemo(() => {
|
||||
const getTimestamp = (rId: string) => roomToLatestEvent.get(rId)?.origin_server_ts;
|
||||
|
||||
if (searchRoomType === SearchRoomType.Spaces) {
|
||||
return spaces;
|
||||
}
|
||||
if (searchRoomType === SearchRoomType.Directs) {
|
||||
return [...directs].sort(factoryRoomIdByActivity(getTimestamp)).slice(0, 20);
|
||||
return [...directs]
|
||||
.sort(factoryRoomIdByActivity(activityTsScope(ct, roomToLatestEvent)))
|
||||
.slice(0, 20);
|
||||
}
|
||||
if (searchRoomType === SearchRoomType.Rooms) {
|
||||
return [...rooms].sort(factoryRoomIdByActivity(getTimestamp)).slice(0, 20);
|
||||
return [...rooms]
|
||||
.sort(factoryRoomIdByActivity(activityTsScope(ct, roomToLatestEvent)))
|
||||
.slice(0, 20);
|
||||
}
|
||||
return [...rooms, ...directs].sort(factoryRoomIdByActivity(getTimestamp)).slice(0, 20);
|
||||
}, [roomToLatestEvent, rooms, directs, spaces, searchRoomType]);
|
||||
return [...rooms, ...directs]
|
||||
.sort(factoryRoomIdByActivity(activityTsScope(ct, roomToLatestEvent)))
|
||||
.slice(0, 20);
|
||||
}, [ct, roomToLatestEvent, rooms, directs, spaces, searchRoomType]);
|
||||
};
|
||||
|
||||
const useSearchTargetRooms = (
|
||||
|
|
|
|||
|
|
@ -6,7 +6,13 @@ import { getHierarchy, GetHierarchyOK } from 'neurone/lib/api/matrix/client/v1/r
|
|||
import { parseMatrixResp } from 'neurone/lib/matrix-request';
|
||||
import { SpaceChildContent } from '../../types/matrix/room';
|
||||
import { isRoomId } from '../utils/matrix';
|
||||
import { SortFunc, byOrderKey, byTsOldToNew, factoryRoomIdByActivity } from '../utils/sort';
|
||||
import {
|
||||
SortFunc,
|
||||
activityTsScope,
|
||||
byOrderKey,
|
||||
byTsOldToNew,
|
||||
factoryRoomIdByActivity,
|
||||
} from '../utils/sort';
|
||||
import { ErrorCode } from '../cs-errorcode';
|
||||
import { useObservableValue } from './useObservableValue';
|
||||
import { useClient } from './useClient';
|
||||
|
|
@ -223,6 +229,7 @@ export const useJoinedHierarchyItems = (
|
|||
closedCategories: Set<string>,
|
||||
selectedRoomId: string | undefined
|
||||
) => {
|
||||
const ct = useClient();
|
||||
const roomToLatestEvent = useRoomsLatestEvent(rooms);
|
||||
const [sortByActivity] = useSetting('roomListByActivity');
|
||||
|
||||
|
|
@ -238,19 +245,13 @@ export const useJoinedHierarchyItems = (
|
|||
return total.count > 0 || unreadRooms.has(item.roomId);
|
||||
})
|
||||
.sort((h1, h2) =>
|
||||
factoryRoomIdByActivity((rId) => roomToLatestEvent.get(rId)?.origin_server_ts)(
|
||||
h1.roomId,
|
||||
h2.roomId
|
||||
)
|
||||
factoryRoomIdByActivity(activityTsScope(ct, roomToLatestEvent))(h1.roomId, h2.roomId)
|
||||
);
|
||||
}
|
||||
|
||||
if (sortByActivity) {
|
||||
items.sort((h1, h2) =>
|
||||
factoryRoomIdByActivity((rId) => roomToLatestEvent.get(rId)?.origin_server_ts)(
|
||||
h1.roomId,
|
||||
h2.roomId
|
||||
)
|
||||
factoryRoomIdByActivity(activityTsScope(ct, roomToLatestEvent))(h1.roomId, h2.roomId)
|
||||
);
|
||||
return items;
|
||||
}
|
||||
|
|
@ -260,6 +261,7 @@ export const useJoinedHierarchyItems = (
|
|||
return items;
|
||||
},
|
||||
[
|
||||
ct,
|
||||
roomToLatestEvent,
|
||||
closedCategories,
|
||||
spaceId,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import {
|
|||
import { useVirtualizer } from '@tanstack/react-virtual';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { factoryRoomIdByActivity } from '../../../utils/sort';
|
||||
import { activityTsScope, factoryRoomIdByActivity } from '../../../utils/sort';
|
||||
import {
|
||||
NavButton,
|
||||
NavCategory,
|
||||
|
|
@ -210,12 +210,13 @@ export function Direct() {
|
|||
const total = getRoomTotalNotifications(notification);
|
||||
return total.count > 0 || unreadRooms.has(roomId);
|
||||
})
|
||||
.sort(factoryRoomIdByActivity((rId) => roomToLatestEvent.get(rId)?.origin_server_ts));
|
||||
.sort(factoryRoomIdByActivity(activityTsScope(ct, roomToLatestEvent)));
|
||||
}
|
||||
return Array.from(directs).sort(
|
||||
factoryRoomIdByActivity((rId) => roomToLatestEvent.get(rId)?.origin_server_ts)
|
||||
factoryRoomIdByActivity(activityTsScope(ct, roomToLatestEvent))
|
||||
);
|
||||
}, [
|
||||
ct,
|
||||
directs,
|
||||
closedCategories,
|
||||
roomToNotifications,
|
||||
|
|
@ -290,6 +291,7 @@ export function Direct() {
|
|||
ref={virtualizer.measureElement}
|
||||
>
|
||||
<RoomNavItem
|
||||
key={roomId}
|
||||
roomId={roomId}
|
||||
roomName={getRoomName(roomId) ?? 'Unknown'}
|
||||
avatarUrl={getRoomAvatar(roomId)}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import {
|
|||
import { useVirtualizer } from '@tanstack/react-virtual';
|
||||
import { useAtom } from 'jotai';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
import { factoryRoomIdByActivity, factoryRoomIdByAtoZ } from '../../../utils/sort';
|
||||
import { activityTsScope, factoryRoomIdByActivity, factoryRoomIdByAtoZ } from '../../../utils/sort';
|
||||
import {
|
||||
NavButton,
|
||||
NavCategory,
|
||||
|
|
@ -237,15 +237,16 @@ export function Home() {
|
|||
const total = getRoomTotalNotifications(notification);
|
||||
return total.count > 0 || unreadRooms.has(roomId);
|
||||
})
|
||||
.sort(factoryRoomIdByActivity((rId) => roomToLatestEvent.get(rId)?.origin_server_ts));
|
||||
.sort(factoryRoomIdByActivity(activityTsScope(ct, roomToLatestEvent)));
|
||||
}
|
||||
if (sortByActivity) {
|
||||
return Array.from(rooms).sort(
|
||||
factoryRoomIdByActivity((rId) => roomToLatestEvent.get(rId)?.origin_server_ts)
|
||||
factoryRoomIdByActivity(activityTsScope(ct, roomToLatestEvent))
|
||||
);
|
||||
}
|
||||
return Array.from(rooms).sort(factoryRoomIdByAtoZ(getRoomName));
|
||||
}, [
|
||||
ct,
|
||||
getRoomName,
|
||||
rooms,
|
||||
closedCategories,
|
||||
|
|
@ -376,6 +377,7 @@ export function Home() {
|
|||
ref={virtualizer.measureElement}
|
||||
>
|
||||
<RoomNavItem
|
||||
key={roomId}
|
||||
roomId={roomId}
|
||||
roomName={getRoomName(roomId) ?? 'Unknown'}
|
||||
avatarUrl={getRoomAvatar(roomId)}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,19 @@
|
|||
import { MessageEventWithoutRoomId } from 'neurone/lib/api/types';
|
||||
import { ClientContext } from '../../client/context';
|
||||
|
||||
export type SortFunc<T> = (a: T, b: T) => number;
|
||||
|
||||
export const activityTsScope = (
|
||||
ct: ClientContext,
|
||||
roomToLatestEvent: Map<string, MessageEventWithoutRoomId>
|
||||
) => {
|
||||
const getTs = (rId: string) =>
|
||||
roomToLatestEvent.get(rId)?.origin_server_ts ??
|
||||
ct.state.join.create.read.find((ev) => ev.roomId === rId)?.event.origin_server_ts;
|
||||
|
||||
return getTs;
|
||||
};
|
||||
|
||||
export const factoryRoomIdByActivity =
|
||||
(getLatestEventTs: (roomId: string) => number | undefined): SortFunc<string> =>
|
||||
(a, b) =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue