From 0b62346992796486503cdf7b9db33afa2d05f4a9 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Fri, 27 Feb 2026 00:36:13 -0600 Subject: [PATCH] satisfy the linter overlords a little --- src/app/features/room/RoomViewHeader.tsx | 49 +++++++++++++++--------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/app/features/room/RoomViewHeader.tsx b/src/app/features/room/RoomViewHeader.tsx index 9a468f1b..c194176c 100644 --- a/src/app/features/room/RoomViewHeader.tsx +++ b/src/app/features/room/RoomViewHeader.tsx @@ -78,10 +78,16 @@ async function getPinsHash(pinnedIds: string[]): Promise { const data = encoder.encode(sorted); const hashBuffer = await crypto.subtle.digest('SHA-256', data); const hashArray = Array.from(new Uint8Array(hashBuffer)); - const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join(''); return hashHex.slice(0, 10); } +interface PinReadMarker { + hash: string; + count: number; + last_seen_id: string; +} + type RoomMenuProps = { room: Room; requestClose: () => void; @@ -292,13 +298,15 @@ export function RoomViewHeader() { const widgets = useRoomWidgets(room); const pinnedIds = useRoomPinnedEvents(room); - const pinMarker = room.getAccountData(AccountDataEvent.SablePinStatus)?.getContent(); + const pinMarker = room + .getAccountData(AccountDataEvent.SablePinStatus) + ?.getContent() as PinReadMarker; const [unreadPinsCount, setUnreadPinsCount] = useState(0); const [currentHash, setCurrentHash] = useState(''); useEffect(() => { - getPinsHash(pinnedIds).then(setCurrentHash); + void getPinsHash(pinnedIds).then(setCurrentHash); }, [pinnedIds]); useEffect(() => { @@ -308,9 +316,9 @@ export function RoomViewHeader() { return; } - const currentHash = await getPinsHash(pinnedIds); + const hash = await getPinsHash(pinnedIds); - if (pinMarker?.hash === currentHash) { + if (pinMarker?.hash === hash) { setUnreadPinsCount(0); return; } @@ -326,7 +334,7 @@ export function RoomViewHeader() { setUnreadPinsCount(Math.max(0, newCount)); } }; - checkUnreads(); + void checkUnreads(); }, [pinnedIds, pinMarker]); const handleSearchClick = () => { @@ -343,17 +351,22 @@ export function RoomViewHeader() { setMenuAnchor(evt.currentTarget.getBoundingClientRect()); }; - const handleOpenPinMenu: MouseEventHandler = async (evt) => { + const handleOpenPinMenu: MouseEventHandler = (evt) => {\ setPinMenuAnchor(evt.currentTarget.getBoundingClientRect()); - - const currentHash = await getPinsHash(pinnedIds); - mx.setRoomAccountData(room.roomId, AccountDataEvent.SablePinStatus, { - hash: currentHash, - count: pinnedIds.length, - last_seen_id: pinnedIds[pinnedIds.length - 1], - }); - }; + const updateMarker = async () => { + if (pinnedIds.length === 0) return; + + const currentHash = await getPinsHash(pinnedIds); + await mx.setRoomAccountData(room.roomId, AccountDataEvent.SablePinStatus, { + hash: currentHash, + count: pinnedIds.length, + last_seen_id: pinnedIds[pinnedIds.length - 1], + }); + }; + + void updateMarker(); + }; return ( - setPinMenuAnchor(undefined)} + setPinMenuAnchor(undefined)} currentHash={currentHash} />