Even more comments.

This commit is contained in:
Half-Shot
2024-10-29 17:05:54 +00:00
parent a45b01dc00
commit 32294984fe

View File

@@ -40,8 +40,17 @@ const ReactionsContext = createContext<ReactionsContextType | undefined>(
); );
interface RaisedHandInfo { interface RaisedHandInfo {
/**
* Call membership event that was reacted to.
*/
membershipEventId: string; membershipEventId: string;
/**
* Event ID of the reaction itself.
*/
reactionEventId: string; reactionEventId: string;
/**
* The time when the reaction was raised.
*/
time: Date; time: Date;
} }
@@ -110,6 +119,8 @@ export const ReactionsProvider = ({
// This effect will check the state whenever the membership of the session changes. // This effect will check the state whenever the membership of the session changes.
useEffect(() => { useEffect(() => {
// Fetches the first reaction for a given event. We assume no more than
// one reaction on an event here.
const getLastReactionEvent = (eventId: string): MatrixEvent | undefined => { const getLastReactionEvent = (eventId: string): MatrixEvent | undefined => {
const relations = room.relations.getChildEventsForEvent( const relations = room.relations.getChildEventsForEvent(
eventId, eventId,
@@ -127,6 +138,8 @@ export const ReactionsProvider = ({
removeRaisedHand(userId); removeRaisedHand(userId);
} }
// For each member in the call, check to see if a reaction has
// been raised and adjust.
for (const m of memberships) { for (const m of memberships) {
if (!m.sender || !m.eventId) { if (!m.sender || !m.eventId) {
continue; continue;
@@ -135,7 +148,8 @@ export const ReactionsProvider = ({
raisedHands[m.sender] && raisedHands[m.sender] &&
raisedHands[m.sender].membershipEventId !== m.eventId raisedHands[m.sender].membershipEventId !== m.eventId
) { ) {
// Membership event for sender has changed. // Membership event for sender has changed since the hand
// was raised, reset.
removeRaisedHand(m.sender); removeRaisedHand(m.sender);
} }
const reaction = getLastReactionEvent(m.eventId); const reaction = getLastReactionEvent(m.eventId);
@@ -172,6 +186,8 @@ export const ReactionsProvider = ({
const content = event.getContent() as ReactionEventContent; const content = event.getContent() as ReactionEventContent;
const membershipEventId = content["m.relates_to"].event_id; const membershipEventId = content["m.relates_to"].event_id;
// Check to see if this reaction was made to a membership event (and the
// sender of the reaction matches the membership)
if ( if (
!memberships.some( !memberships.some(
(e) => e.eventId === membershipEventId && e.sender === sender, (e) => e.eventId === membershipEventId && e.sender === sender,
@@ -193,7 +209,7 @@ export const ReactionsProvider = ({
} else if (event.getType() === EventType.RoomRedaction) { } else if (event.getType() === EventType.RoomRedaction) {
const targetEvent = event.event.redacts; const targetEvent = event.event.redacts;
const targetUser = Object.entries(raisedHands).find( const targetUser = Object.entries(raisedHands).find(
([u, r]) => r.reactionEventId === targetEvent, ([_u, r]) => r.reactionEventId === targetEvent,
)?.[0]; )?.[0];
if (!targetUser) { if (!targetUser) {
// Reaction target was not for us, ignoring // Reaction target was not for us, ignoring