Compare commits
2
Commits
bd649d4e16
...
f0495cccca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0495cccca | ||
|
|
76e5f960d1 |
No files matched your search
@@ -362,6 +362,7 @@ type RoomTimelineProps = {
|
|||||||
eventId?: string;
|
eventId?: string;
|
||||||
roomInputRef: RefObject<HTMLElement>;
|
roomInputRef: RefObject<HTMLElement>;
|
||||||
editor: Editor;
|
editor: Editor;
|
||||||
|
onViewportAnchorChange?: (eventId?: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const PAGINATION_LIMIT = 80;
|
const PAGINATION_LIMIT = 80;
|
||||||
@@ -564,7 +565,13 @@ const getRoomUnreadInfo = (room: Room, scrollTo = false) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimelineProps) {
|
export function RoomTimeline({
|
||||||
|
room,
|
||||||
|
eventId,
|
||||||
|
roomInputRef,
|
||||||
|
editor,
|
||||||
|
onViewportAnchorChange,
|
||||||
|
}: RoomTimelineProps) {
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
const useAuthentication = useMediaAuthentication();
|
const useAuthentication = useMediaAuthentication();
|
||||||
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
|
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
|
||||||
@@ -1189,6 +1196,29 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
|||||||
};
|
};
|
||||||
}, [room.roomId, eventId, persistTimelineScroll]);
|
}, [room.roomId, eventId, persistTimelineScroll]);
|
||||||
|
|
||||||
|
// Report the message the user is actually looking at, so the activity bar
|
||||||
|
// reflects the shown message instead of the newest event in the room.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!onViewportAnchorChange) return undefined;
|
||||||
|
const scrollEl = scrollRef.current;
|
||||||
|
if (!scrollEl) return undefined;
|
||||||
|
|
||||||
|
let raf = 0;
|
||||||
|
const report = () => {
|
||||||
|
window.cancelAnimationFrame(raf);
|
||||||
|
raf = window.requestAnimationFrame(() => {
|
||||||
|
onViewportAnchorChange(eventId ?? getViewportAnchorEventId() ?? getRangeCenterEventId());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
report();
|
||||||
|
scrollEl.addEventListener('scroll', report, { passive: true });
|
||||||
|
return () => {
|
||||||
|
window.cancelAnimationFrame(raf);
|
||||||
|
scrollEl.removeEventListener('scroll', report);
|
||||||
|
};
|
||||||
|
}, [onViewportAnchorChange, eventId, getViewportAnchorEventId, getRangeCenterEventId]);
|
||||||
|
|
||||||
// Restore saved scroll or default to bottom on first open.
|
// Restore saved scroll or default to bottom on first open.
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
const scrollEl = scrollRef.current;
|
const scrollEl = scrollRef.current;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useCallback, useRef } from 'react';
|
import React, { useCallback, useRef, useState } from 'react';
|
||||||
import { Box, Text, config } from 'folds';
|
import { Box, Text, config } from 'folds';
|
||||||
import { EventType, Room } from 'matrix-js-sdk';
|
import { EventType, Room } from 'matrix-js-sdk';
|
||||||
import { ReactEditor } from 'slate-react';
|
import { ReactEditor } from 'slate-react';
|
||||||
@@ -65,6 +65,7 @@ export function RoomView({ room, eventId }: { room: Room; eventId?: string }) {
|
|||||||
const roomViewRef = useRef<HTMLDivElement>(null);
|
const roomViewRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
|
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
|
||||||
|
const [viewportEventId, setViewportEventId] = useState<string>();
|
||||||
|
|
||||||
const { roomId } = room;
|
const { roomId } = room;
|
||||||
const editor = useEditor();
|
const editor = useEditor();
|
||||||
@@ -117,10 +118,11 @@ export function RoomView({ room, eventId }: { room: Room; eventId?: string }) {
|
|||||||
eventId={eventId}
|
eventId={eventId}
|
||||||
roomInputRef={roomInputRef}
|
roomInputRef={roomInputRef}
|
||||||
editor={editor}
|
editor={editor}
|
||||||
|
onViewportAnchorChange={setViewportEventId}
|
||||||
/>
|
/>
|
||||||
<div className={roomViewCss.RoomViewBottomFloat}>
|
<div className={roomViewCss.RoomViewBottomFloat}>
|
||||||
<RoomViewTyping room={room} />
|
<RoomViewTyping room={room} />
|
||||||
{!hideActivity && <RoomViewFollowing room={room} />}
|
{!hideActivity && <RoomViewFollowing room={room} eventId={viewportEventId} />}
|
||||||
</div>
|
</div>
|
||||||
</Box>
|
</Box>
|
||||||
<Box shrink="No" direction="Column">
|
<Box shrink="No" direction="Column">
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import * as css from './RoomViewFollowing.css';
|
|||||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||||
import { useRoomLatestRenderedEvent } from '../../hooks/useRoomLatestRenderedEvent';
|
import { useRoomLatestRenderedEvent } from '../../hooks/useRoomLatestRenderedEvent';
|
||||||
import { useRoomEventReaders } from '../../hooks/useRoomEventReaders';
|
import { useRoomEventReaders } from '../../hooks/useRoomEventReaders';
|
||||||
|
import { useRoomEventDelivery } from '../../hooks/useRoomEventDelivery';
|
||||||
import { EventReaders } from '../../components/event-readers';
|
import { EventReaders } from '../../components/event-readers';
|
||||||
import { stopPropagation } from '../../utils/keyboard';
|
import { stopPropagation } from '../../utils/keyboard';
|
||||||
|
|
||||||
@@ -20,20 +21,29 @@ export function RoomViewFollowingPlaceholder() {
|
|||||||
|
|
||||||
export type RoomViewFollowingProps = {
|
export type RoomViewFollowingProps = {
|
||||||
room: Room;
|
room: Room;
|
||||||
|
/** Message the user is looking at. Falls back to the latest rendered event. */
|
||||||
|
eventId?: string;
|
||||||
};
|
};
|
||||||
export const RoomViewFollowing = as<'div', RoomViewFollowingProps>(
|
export const RoomViewFollowing = as<'div', RoomViewFollowingProps>(
|
||||||
({ className, room, ...props }, ref) => {
|
({ className, room, eventId, ...props }, ref) => {
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
|
const myUserId = mx.getUserId();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const latestEvent = useRoomLatestRenderedEvent(room);
|
const latestEvent = useRoomLatestRenderedEvent(room);
|
||||||
const latestEventReaders = useRoomEventReaders(room, latestEvent?.getId());
|
const shownEventId = eventId ?? latestEvent?.getId();
|
||||||
const names = latestEventReaders
|
const latestEventReaders = useRoomEventReaders(room, shownEventId);
|
||||||
.filter((readerId) => readerId !== mx.getUserId())
|
const received = useRoomEventDelivery(room, shownEventId, myUserId);
|
||||||
.map(
|
|
||||||
(readerId) => getMemberDisplayName(room, readerId) ?? getMxIdLocalPart(readerId) ?? readerId
|
|
||||||
);
|
|
||||||
|
|
||||||
const eventId = latestEvent?.getId();
|
// Received but not read shows a single tick, read shows the double tick.
|
||||||
|
const receivedOnly = received && !latestEventReaders.includes(myUserId);
|
||||||
|
|
||||||
|
const getName = (userId: string) =>
|
||||||
|
getMemberDisplayName(room, userId) ?? getMxIdLocalPart(userId) ?? userId;
|
||||||
|
|
||||||
|
const names = [
|
||||||
|
...(receivedOnly && myUserId ? [myUserId] : []),
|
||||||
|
...latestEventReaders.filter((readerId) => readerId !== myUserId),
|
||||||
|
].map(getName);
|
||||||
|
|
||||||
if (names.length === 0) {
|
if (names.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
@@ -41,7 +51,7 @@ export const RoomViewFollowing = as<'div', RoomViewFollowingProps>(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{eventId && (
|
{shownEventId && (
|
||||||
<Overlay open={open} backdrop={<OverlayBackdrop />}>
|
<Overlay open={open} backdrop={<OverlayBackdrop />}>
|
||||||
<OverlayCenter>
|
<OverlayCenter>
|
||||||
<FocusTrap
|
<FocusTrap
|
||||||
@@ -53,7 +63,7 @@ export const RoomViewFollowing = as<'div', RoomViewFollowingProps>(
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Modal variant="Surface" size="300">
|
<Modal variant="Surface" size="300">
|
||||||
<EventReaders room={room} eventId={eventId} requestClose={() => setOpen(false)} />
|
<EventReaders room={room} eventId={shownEventId} requestClose={() => setOpen(false)} />
|
||||||
</Modal>
|
</Modal>
|
||||||
</FocusTrap>
|
</FocusTrap>
|
||||||
</OverlayCenter>
|
</OverlayCenter>
|
||||||
@@ -69,7 +79,11 @@ export const RoomViewFollowing = as<'div', RoomViewFollowingProps>(
|
|||||||
{...props}
|
{...props}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
>
|
>
|
||||||
<Icon style={{ opacity: config.opacity.P300 }} size="100" src={Icons.CheckTwice} />
|
<Icon
|
||||||
|
style={{ opacity: config.opacity.P300 }}
|
||||||
|
size="100"
|
||||||
|
src={receivedOnly ? Icons.Check : Icons.CheckTwice}
|
||||||
|
/>
|
||||||
<Text size="T300" truncate>
|
<Text size="T300" truncate>
|
||||||
{names.length === 1 && <b>{names[0]}</b>}
|
{names.length === 1 && <b>{names[0]}</b>}
|
||||||
{names.length === 2 && (
|
{names.length === 2 && (
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { MatrixEvent, Room, RoomEvent } from 'matrix-js-sdk';
|
||||||
|
import { PAARROT_RECEIVED_EVENT, hasReceivedMarker } from '../utils/paarrotDelivery';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether `userId` has recorded a delivery marker for `eventId` - received, but
|
||||||
|
* not necessarily read. Read state still comes from the read receipt.
|
||||||
|
*/
|
||||||
|
export const useRoomEventDelivery = (room: Room, eventId?: string, userId?: string): boolean => {
|
||||||
|
const [received, setReceived] = useState(() =>
|
||||||
|
eventId && userId ? hasReceivedMarker(room, eventId, userId) : false,
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setReceived(eventId && userId ? hasReceivedMarker(room, eventId, userId) : false);
|
||||||
|
if (!eventId || !userId) return;
|
||||||
|
|
||||||
|
const update = () => setReceived(hasReceivedMarker(room, eventId, userId));
|
||||||
|
|
||||||
|
const handleTimeline = (event: MatrixEvent, r: Room) => {
|
||||||
|
if (r.roomId !== room.roomId) return;
|
||||||
|
if (event.getRelation()?.event_id !== eventId) return;
|
||||||
|
if (event.getType() !== PAARROT_RECEIVED_EVENT && !event.isRedaction()) return;
|
||||||
|
|
||||||
|
update();
|
||||||
|
};
|
||||||
|
|
||||||
|
room.on(RoomEvent.Timeline, handleTimeline);
|
||||||
|
return () => {
|
||||||
|
room.removeListener(RoomEvent.Timeline, handleTimeline);
|
||||||
|
};
|
||||||
|
}, [room, eventId, userId]);
|
||||||
|
|
||||||
|
return received;
|
||||||
|
};
|
||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
getOrphanParents,
|
getOrphanParents,
|
||||||
guessPerfectParent,
|
guessPerfectParent,
|
||||||
} from '../../utils/room';
|
} from '../../utils/room';
|
||||||
|
import { sendReceivedMarker } from '../../utils/paarrotDelivery';
|
||||||
import { NotificationType, UnreadInfo } from '../../../types/matrix/room';
|
import { NotificationType, UnreadInfo } from '../../../types/matrix/room';
|
||||||
import { getMxIdLocalPart, mxcUrlToHttp, getCanonicalAliasOrRoomId } from '../../utils/matrix';
|
import { getMxIdLocalPart, mxcUrlToHttp, getCanonicalAliasOrRoomId } from '../../utils/matrix';
|
||||||
import { mDirectAtom } from '../../state/mDirectList';
|
import { mDirectAtom } from '../../state/mDirectList';
|
||||||
@@ -387,6 +388,14 @@ function MessageNotifications() {
|
|||||||
(notificationType === NotificationType.Default && !isDm);
|
(notificationType === NotificationType.Default && !isDm);
|
||||||
if (mentionsOnly && unreadInfo.highlight === 0) return;
|
if (mentionsOnly && unreadInfo.highlight === 0) return;
|
||||||
|
|
||||||
|
// Record that Paarrot received this message. This is the single tick; the
|
||||||
|
// read receipt below is what turns it into the double tick.
|
||||||
|
if (showNotifications) {
|
||||||
|
sendReceivedMarker(mx, room, eventId).catch((error) => {
|
||||||
|
console.error('[PaarrotDelivery] Failed to send delivery marker:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
showNotifications &&
|
showNotifications &&
|
||||||
((isTauri() && !isElectron()) || isCapacitorNative() || notificationPermission('granted'))
|
((isTauri() && !isElectron()) || isCapacitorNative() || notificationPermission('granted'))
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { MatrixClient, RelationType, Room } from 'matrix-js-sdk';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client-defined event marking that Paarrot has received a message.
|
||||||
|
*
|
||||||
|
* The spec has no delivery receipt type - Synapse only accepts `m.read`,
|
||||||
|
* `m.read.private` and `m.fully_read` on the receipts endpoint - so delivery is
|
||||||
|
* recorded as a custom event related to the target message with `m.reference`.
|
||||||
|
*
|
||||||
|
* It never shows in the cinny timeline (events with a relation are skipped
|
||||||
|
* unless "show hidden events" is on), and other clients only see an unknown
|
||||||
|
* event. Delivery is always self-reported: in E2EE, only the receiving client
|
||||||
|
* can know it actually got the event.
|
||||||
|
*/
|
||||||
|
export const PAARROT_RECEIVED_EVENT = 'com.paarrot.received';
|
||||||
|
|
||||||
|
export const getReceivedContent = (eventId: string) => ({
|
||||||
|
'm.relates_to': {
|
||||||
|
event_id: eventId,
|
||||||
|
rel_type: RelationType.Reference,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const getEventDeliveryRelations = (room: Room, eventId: string) =>
|
||||||
|
room
|
||||||
|
.getUnfilteredTimelineSet()
|
||||||
|
.relations.getChildEventsForEvent(eventId, RelationType.Reference, PAARROT_RECEIVED_EVENT);
|
||||||
|
|
||||||
|
export const hasReceivedMarker = (room: Room, eventId: string, userId: string): boolean => {
|
||||||
|
const relations = getEventDeliveryRelations(room, eventId);
|
||||||
|
if (!relations) return false;
|
||||||
|
|
||||||
|
return relations
|
||||||
|
.getRelations()
|
||||||
|
.some(
|
||||||
|
(rel) =>
|
||||||
|
!rel.isRedacted() && rel.getSender() === userId && rel.getRelation()?.event_id === eventId,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends the delivery marker for `eventId`. Skips events that are still local
|
||||||
|
* echoes (no `$` id yet) and events this user already marked, so a room that
|
||||||
|
* re-syncs does not spam markers.
|
||||||
|
*/
|
||||||
|
export async function sendReceivedMarker(mx: MatrixClient, room: Room, eventId: string) {
|
||||||
|
const userId = mx.getUserId();
|
||||||
|
if (!userId || !eventId.startsWith('$')) return false;
|
||||||
|
if (hasReceivedMarker(room, eventId, userId)) return false;
|
||||||
|
|
||||||
|
await mx.sendEvent(room.roomId, PAARROT_RECEIVED_EVENT, getReceivedContent(eventId));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user