1 Commits
Author SHA1 Message Date
litruv 76e5f960d1 Add Telegram-style delivery receipt to Paarrot.
Trigger cinny-mobile / dispatch (push) Successful in 1s
Matrix has no delivery receipt type in the spec (Synapse only accepts
m.read, m.read.private and m.fully_read), so delivery is recorded as a
client-defined event com.paarrot.received related to the target message
with m.reference. The app sends the marker when a notification fires for
a message, and the bottom-right indicator shows a single tick when
received-but-not-read and the existing double tick once read. Other
clients see an unknown event; cinny never renders it in the timeline
because events with a relation are skipped unless show hidden events is on.
2026-10-13 08:01:04 +11:00
4 changed files with 117 additions and 8 deletions
+20 -8
View File
@@ -11,6 +11,7 @@ import * as css from './RoomViewFollowing.css';
import { useMatrixClient } from '../../hooks/useMatrixClient';
import { useRoomLatestRenderedEvent } from '../../hooks/useRoomLatestRenderedEvent';
import { useRoomEventReaders } from '../../hooks/useRoomEventReaders';
import { useRoomEventDelivery } from '../../hooks/useRoomEventDelivery';
import { EventReaders } from '../../components/event-readers';
import { stopPropagation } from '../../utils/keyboard';
@@ -24,16 +25,23 @@ export type RoomViewFollowingProps = {
export const RoomViewFollowing = as<'div', RoomViewFollowingProps>(
({ className, room, ...props }, ref) => {
const mx = useMatrixClient();
const myUserId = mx.getUserId();
const [open, setOpen] = useState(false);
const latestEvent = useRoomLatestRenderedEvent(room);
const latestEventReaders = useRoomEventReaders(room, latestEvent?.getId());
const names = latestEventReaders
.filter((readerId) => readerId !== mx.getUserId())
.map(
(readerId) => getMemberDisplayName(room, readerId) ?? getMxIdLocalPart(readerId) ?? readerId
);
const eventId = latestEvent?.getId();
const latestEventReaders = useRoomEventReaders(room, eventId);
const received = useRoomEventDelivery(room, eventId, myUserId);
// 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) {
return null;
@@ -69,7 +77,11 @@ export const RoomViewFollowing = as<'div', RoomViewFollowingProps>(
{...props}
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>
{names.length === 1 && <b>{names[0]}</b>}
{names.length === 2 && (
+35
View File
@@ -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,
guessPerfectParent,
} from '../../utils/room';
import { sendReceivedMarker } from '../../utils/paarrotDelivery';
import { NotificationType, UnreadInfo } from '../../../types/matrix/room';
import { getMxIdLocalPart, mxcUrlToHttp, getCanonicalAliasOrRoomId } from '../../utils/matrix';
import { mDirectAtom } from '../../state/mDirectList';
@@ -387,6 +388,14 @@ function MessageNotifications() {
(notificationType === NotificationType.Default && !isDm);
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 (
showNotifications &&
((isTauri() && !isElectron()) || isCapacitorNative() || notificationPermission('granted'))
+53
View File
@@ -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;
}