Augment the custom event types and make the dep arrays honest. [skip build]
This commit is contained in:
@@ -18,7 +18,6 @@ import FocusTrap from 'focus-trap-react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Icon, Icons } from '../icons';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
import { factoryRoomIdByActivity } from '../../utils/sort';
|
||||
import {
|
||||
NavButton,
|
||||
NavCategory,
|
||||
@@ -215,15 +214,14 @@ export function DirectList({
|
||||
const selectedRoomId = useSelectedRoom();
|
||||
const [closedCategories, setClosedCategories] = useAtom(useClosedNavCategoriesAtom());
|
||||
|
||||
const reorderTrigger = useRoomListReorder(mx, directs);
|
||||
const activityOrder = useRoomListReorder(mx, directs);
|
||||
|
||||
const sortedDirects = useMemo(() => {
|
||||
const items = Array.from(directs).sort(factoryRoomIdByActivity(mx));
|
||||
if (closedCategories.has(DEFAULT_CATEGORY_ID)) {
|
||||
return items.filter((rId) => roomToUnread.has(rId) || rId === selectedRoomId);
|
||||
return activityOrder.filter((rId) => roomToUnread.has(rId) || rId === selectedRoomId);
|
||||
}
|
||||
return items;
|
||||
}, [mx, directs, closedCategories, roomToUnread, selectedRoomId, reorderTrigger]);
|
||||
return activityOrder;
|
||||
}, [activityOrder, closedCategories, roomToUnread, selectedRoomId]);
|
||||
|
||||
const animationRef = useListReorderAnimation(sortedDirects);
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ function CreatePackTile({ packs, roomId }: CreatePackTileProps) {
|
||||
display_name: name,
|
||||
},
|
||||
};
|
||||
await mx.sendStateEvent(roomId, StateEvent.PoniesRoomEmotes as any, content, stateKey);
|
||||
await mx.sendStateEvent(roomId, StateEvent.PoniesRoomEmotes, content, stateKey);
|
||||
},
|
||||
[mx, roomId],
|
||||
),
|
||||
@@ -162,7 +162,7 @@ export function RoomPacks({ onViewPack }: RoomPacksProps) {
|
||||
useCallback(async () => {
|
||||
for (let i = 0; i < removedPacks.length; i += 1) {
|
||||
const addr = removedPacks[i];
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.PoniesRoomEmotes as any, {}, addr.stateKey);
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.PoniesRoomEmotes, {}, addr.stateKey);
|
||||
}
|
||||
}, [mx, room, removedPacks]),
|
||||
);
|
||||
|
||||
@@ -332,7 +332,7 @@ export function PowersEditor({ powerLevels, requestClose }: PowersEditorProps) {
|
||||
deleted.forEach((power) => {
|
||||
delete content[power];
|
||||
});
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.PowerLevelTags as any, content);
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.PowerLevelTags, content);
|
||||
}, [mx, room, powerLevelTags, editedPowerTags, deleted]),
|
||||
);
|
||||
|
||||
|
||||
@@ -348,7 +348,6 @@ function ForumThreadDetailBody({
|
||||
setReplyToEventId(rootEventId);
|
||||
}
|
||||
}, [replyDraft, rootEventId]);
|
||||
const [contentRevision, setContentRevision] = useState(0);
|
||||
const [collapsedBranches, setCollapsedBranches] = useState<Set<string>>(() => new Set());
|
||||
const localDropRef = useRef<HTMLDivElement>(null);
|
||||
const dropRef = fileDropContainerRef ?? localDropRef;
|
||||
@@ -393,14 +392,8 @@ function ForumThreadDetailBody({
|
||||
handleComposerSent();
|
||||
}, [handleComposerSent]);
|
||||
|
||||
useForumRoomLiveUpdates(
|
||||
[room],
|
||||
() => {
|
||||
setContentRevision((revision) => revision + 1);
|
||||
reloadThread();
|
||||
},
|
||||
{ threadRootId: rootEventId, wait: 150 },
|
||||
);
|
||||
// post is the reactive source: reloadThread pushes the local thread back through onPostUpdate
|
||||
useForumRoomLiveUpdates([room], reloadThread, { threadRootId: rootEventId, wait: 150 });
|
||||
|
||||
const rootEvent = room.findEventById(rootEventId);
|
||||
const rootEditing = editEventId === rootEventId;
|
||||
@@ -424,7 +417,6 @@ function ForumThreadDetailBody({
|
||||
|
||||
const handleEditRootClose = useCallback(() => {
|
||||
setEditEventId(undefined);
|
||||
setContentRevision((revision) => revision + 1);
|
||||
handleComposerSent();
|
||||
}, [handleComposerSent]);
|
||||
|
||||
@@ -476,7 +468,7 @@ function ForumThreadDetailBody({
|
||||
const title = useMemo(() => {
|
||||
const local = loadPostThreadLocal(mx, roomId, rootEventId);
|
||||
return local?.title || post.title || titleHint || '(untitled post)';
|
||||
}, [contentRevision, mx, post.title, roomId, rootEventId, titleHint]);
|
||||
}, [mx, post.title, roomId, rootEventId, titleHint]);
|
||||
|
||||
return (
|
||||
<article ref={localDropRef} className={theme.ForumTopicDetailRoot} data-event-id={post.eventId}>
|
||||
|
||||
@@ -79,8 +79,7 @@ export function useForumMessageReactions(room: Room, mEvent: MatrixEvent | undef
|
||||
const reactionRelations = useMemo(() => {
|
||||
if (!eventId) return undefined;
|
||||
return getEventReactions(roomTimelineSet, eventId);
|
||||
// relationsRevision forces re-read after timeline / relation updates
|
||||
}, [eventId, relationsRevision, roomTimelineSet]);
|
||||
}, [eventId, roomTimelineSet]);
|
||||
|
||||
const hasReactions = Boolean(reactionRelations?.getSortedAnnotationsByKey()?.length);
|
||||
|
||||
|
||||
@@ -456,7 +456,7 @@ function SpaceCardLobby() {
|
||||
newItems.push(rId);
|
||||
}
|
||||
const newSpacesContent = makeCinnySpacesContent(mx, newItems);
|
||||
mx.setAccountData(AccountDataEvent.CinnySpaces as any, newSpacesContent as any);
|
||||
mx.setAccountData(AccountDataEvent.CinnySpaces, newSpacesContent);
|
||||
},
|
||||
[mx, sidebarItems, sidebarSpaces],
|
||||
);
|
||||
|
||||
@@ -107,8 +107,9 @@ export const SpaceHierarchy = forwardRef<HTMLDivElement, SpaceHierarchyProps>(
|
||||
// This ensures sub-rooms are hidden even if their parent isn't in this space
|
||||
const globalSubRoomIds = useMemo(() => {
|
||||
const subRoomIds = new Set<string>();
|
||||
mx.getRooms().forEach((room) => {
|
||||
const subRoomsEvent = room.currentState.getStateEvents(StateEvent.PaarrotSubRooms, '');
|
||||
allJoinedRooms.forEach((roomId) => {
|
||||
const room = mx.getRoom(roomId);
|
||||
const subRoomsEvent = room?.currentState.getStateEvents(StateEvent.PaarrotSubRooms, '');
|
||||
const content = subRoomsEvent?.getContent<PaarrotSubRoomsContent>();
|
||||
content?.children?.forEach((childId: string) => subRoomIds.add(childId));
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ export function RoomAppView({ room, onShowChat }: RoomAppViewProps) {
|
||||
|
||||
const handleAction = useCallback(
|
||||
async (payload: PaarrotUiActionContent) => {
|
||||
await mx.sendEvent(room.roomId, MessageEvent.PaarrotUiAction as any, payload);
|
||||
await mx.sendEvent(room.roomId, MessageEvent.PaarrotUiAction, payload);
|
||||
},
|
||||
[mx, room.roomId],
|
||||
);
|
||||
|
||||
@@ -191,11 +191,7 @@ export function Permissions({ requestClose }: PermissionsProps) {
|
||||
|
||||
// Also copy power level tags if they exist
|
||||
if (powerLevelTags) {
|
||||
await mx.sendStateEvent(
|
||||
childId,
|
||||
'in.cinny.room.power_level_tags' as any,
|
||||
powerLevelTags,
|
||||
);
|
||||
await mx.sendStateEvent(childId, StateEvent.PowerLevelTags, powerLevelTags);
|
||||
}
|
||||
|
||||
completed += 1;
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { MatrixClient, MatrixEvent, Room, RoomEvent, IRoomTimelineData } from 'matrix-js-sdk';
|
||||
|
||||
/**
|
||||
* Hook that tracks timeline events across all rooms to trigger re-sorting of room lists.
|
||||
* Returns a counter that increments whenever a message is sent or received in any room.
|
||||
* This can be used as a dependency in useMemo to trigger re-sorting of room lists.
|
||||
* Hook that tracks timeline events across all rooms to order room lists by activity.
|
||||
* Returns the room IDs sorted by last active timestamp, recomputed on each live timeline event.
|
||||
*
|
||||
* @param mx - The Matrix client instance
|
||||
* @param roomIds - Optional array of room IDs to track. If not provided, tracks all rooms.
|
||||
* @returns A number that increments on each timeline event
|
||||
* @param roomIds - Room IDs to track
|
||||
* @returns Room IDs ordered by most recently active
|
||||
*/
|
||||
export const useRoomListReorder = (mx: MatrixClient, roomIds?: string[]): number => {
|
||||
const [updateCounter, setUpdateCounter] = useState(0);
|
||||
export const useRoomListReorder = (mx: MatrixClient, roomIds: string[]): string[] => {
|
||||
const [lastActivity, setLastActivity] = useState<Map<string, number>>(new Map());
|
||||
|
||||
useEffect(() => {
|
||||
const handleTimelineEvent = (
|
||||
@@ -24,9 +23,9 @@ export const useRoomListReorder = (mx: MatrixClient, roomIds?: string[]): number
|
||||
if (!room || !data.liveEvent) return;
|
||||
if (toStartOfTimeline) return;
|
||||
|
||||
if (roomIds && !roomIds.includes(room.roomId)) return;
|
||||
if (!roomIds.includes(room.roomId)) return;
|
||||
|
||||
setUpdateCounter((prev) => prev + 1);
|
||||
setLastActivity((prev) => new Map(prev).set(room.roomId, room.getLastActiveTimestamp()));
|
||||
};
|
||||
|
||||
mx.on(RoomEvent.Timeline, handleTimelineEvent);
|
||||
@@ -36,7 +35,14 @@ export const useRoomListReorder = (mx: MatrixClient, roomIds?: string[]): number
|
||||
};
|
||||
}, [mx, roomIds]);
|
||||
|
||||
return updateCounter;
|
||||
return useMemo(() => {
|
||||
const activityOf = (roomId: string) =>
|
||||
lastActivity.get(roomId) ??
|
||||
mx.getRoom(roomId)?.getLastActiveTimestamp() ??
|
||||
Number.MIN_SAFE_INTEGER;
|
||||
|
||||
return [...roomIds].sort((a, b) => activityOf(b) - activityOf(a));
|
||||
}, [mx, roomIds, lastActivity]);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,6 @@ import FocusTrap from 'focus-trap-react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Icon, Icons } from '../../../components/icons';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
import { factoryRoomIdByActivity } from '../../../utils/sort';
|
||||
import {
|
||||
NavButton,
|
||||
NavCategory,
|
||||
@@ -251,15 +250,14 @@ export function Direct() {
|
||||
const [closedCategories, setClosedCategories] = useAtom(useClosedNavCategoriesAtom());
|
||||
const scrollRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const reorderTrigger = useRoomListReorder(mx, directs);
|
||||
const activityOrder = useRoomListReorder(mx, directs);
|
||||
|
||||
const sortedDirects = useMemo(() => {
|
||||
const items = Array.from(directs).sort(factoryRoomIdByActivity(mx));
|
||||
if (closedCategories.has(DEFAULT_CATEGORY_ID)) {
|
||||
return items.filter((rId) => roomToUnread.has(rId) || rId === selectedRoomId);
|
||||
return activityOrder.filter((rId) => roomToUnread.has(rId) || rId === selectedRoomId);
|
||||
}
|
||||
return items;
|
||||
}, [mx, directs, closedCategories, roomToUnread, selectedRoomId, reorderTrigger]);
|
||||
return activityOrder;
|
||||
}, [activityOrder, closedCategories, roomToUnread, selectedRoomId]);
|
||||
|
||||
const animationRef = useListReorderAnimation(sortedDirects);
|
||||
|
||||
|
||||
@@ -362,13 +362,14 @@ export function Space() {
|
||||
// This prevents sub-rooms from appearing both as top-level entries AND nested under parents
|
||||
const globalSubRoomIds = useMemo(() => {
|
||||
const subRoomIds = new Set<string>();
|
||||
mx.getRooms().forEach((room) => {
|
||||
const subRoomsEvent = room.currentState.getStateEvents(StateEvent.PaarrotSubRooms, '');
|
||||
allJoinedRooms.forEach((roomId) => {
|
||||
const room = mx.getRoom(roomId);
|
||||
const subRoomsEvent = room?.currentState.getStateEvents(StateEvent.PaarrotSubRooms, '');
|
||||
const content = subRoomsEvent?.getContent<{ children: string[] }>();
|
||||
content?.children?.forEach((childId: string) => subRoomIds.add(childId));
|
||||
});
|
||||
return subRoomIds;
|
||||
}, [mx, allJoinedRooms, hierarchy]);
|
||||
}, [mx, allJoinedRooms]);
|
||||
|
||||
// Filter hierarchy to exclude sub-rooms (they'll be shown nested under their parent)
|
||||
const filteredHierarchy = useMemo(
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { InCinnySpacesContent } from '../../app/hooks/useSidebarItems';
|
||||
|
||||
export enum AccountDataEvent {
|
||||
PushRules = 'm.push_rules',
|
||||
Direct = 'm.direct',
|
||||
@@ -48,3 +50,9 @@ export type SecretContent = {
|
||||
export type SecretAccountData = {
|
||||
encrypted: Record<string, SecretContent>;
|
||||
};
|
||||
|
||||
declare module 'matrix-js-sdk' {
|
||||
interface AccountDataEvents {
|
||||
[AccountDataEvent.CinnySpaces]: InCinnySpacesContent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { PackContent } from '../../app/plugins/custom-emoji/types';
|
||||
import { PaarrotSubRoomsContent } from '../../app/hooks/useRoomSubRooms';
|
||||
import { IImageInfo } from './common';
|
||||
|
||||
export enum Membership {
|
||||
@@ -224,3 +226,15 @@ export type MemberPowerTag = {
|
||||
color?: string;
|
||||
icon?: MemberPowerTagIcon;
|
||||
};
|
||||
|
||||
declare module 'matrix-js-sdk' {
|
||||
interface StateEvents {
|
||||
[StateEvent.PowerLevelTags]: Record<number, MemberPowerTag>;
|
||||
[StateEvent.PoniesRoomEmotes]: PackContent;
|
||||
[StateEvent.PaarrotSubRooms]: PaarrotSubRoomsContent;
|
||||
}
|
||||
|
||||
interface TimelineEvents {
|
||||
[MessageEvent.PaarrotUiAction]: PaarrotUiActionContent;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user