Add Telegram-style delivery receipt to Paarrot.
Trigger cinny-mobile / dispatch (push) Successful in 1s
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.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user