Skip to content

Commit

Permalink
Links to sha commit of matrix-js-sdk that exposes the call membership…
Browse files Browse the repository at this point in the history
… event id and refactors some async code

Signed-off-by: Milton Moura <miltonmoura@gmail.com>
  • Loading branch information
mgcm committed Sep 10, 2024
1 parent 5742355 commit 21d6c8d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 46 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"livekit-client": "^2.0.2",
"lodash": "^4.17.21",
"loglevel": "^1.9.1",
"matrix-js-sdk": "matrix-org/matrix-js-sdk#169e8f86139111574a3738f8557c6fa4b2a199db",
"matrix-js-sdk": "matrix-org/matrix-js-sdk#ed445149740231134d734cb411e13cb120cdb55b",
"matrix-widget-api": "^1.8.2",
"normalize.css": "^8.0.1",
"observable-hooks": "^4.2.3",
Expand Down
82 changes: 40 additions & 42 deletions src/room/InCallView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,19 @@ export const InCallView: FC<InCallViewProps> = ({
const getLastReactionEvent = async (
eventId: string,
): Promise<MatrixEvent | undefined> => {
const rels = await client.relations(
rtcSession.room.roomId,
eventId,
RelationType.Annotation,
EventType.Reaction,
{
limit: 1,
},
);

return rels.events.length > 0 ? rels.events[0] : undefined;
return client
.relations(
rtcSession.room.roomId,
eventId,
RelationType.Annotation,
EventType.Reaction,
{
limit: 1,
},
)
.then((rels) => {
return rels.events.length > 0 ? rels.events[0] : undefined;
});
};

const fetchReactions = async (): Promise<void> => {
Expand All @@ -347,7 +349,7 @@ export const InCallView: FC<InCallViewProps> = ({
setRaisedHands(newRaisedHands);
};

fetchReactions();
void fetchReactions();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down Expand Up @@ -556,43 +558,39 @@ export const InCallView: FC<InCallViewProps> = ({
.catch(logger.error);
}, [localParticipant, isScreenShareEnabled]);

const toggleRaisedHand = useCallback(async () => {
try {
if (isHandRaised) {
try {
if (reactionId) {
await client.redactEvent(rtcSession.room.roomId, reactionId);
const toggleRaisedHand = useCallback(() => {
if (isHandRaised) {
if (reactionId) {
client
.redactEvent(rtcSession.room.roomId, reactionId)
.then(() => {
setReactionId(null);
setRaisedHands(raisedHands.filter((id) => id !== userId));
logger.debug("Redacted reaction event");
}
} catch (e) {
logger.error("Failed to redact reaction event", e);
}
} else {
const m = memberships.filter((m) => m.sender === userId);
const eventId = m[0].eventId!;
try {
const reaction = await client.sendEvent(
rtcSession.room.roomId,
EventType.Reaction,
{
"m.relates_to": {
rel_type: RelationType.Annotation,
event_id: eventId,
key: "🖐️",
},
},
);
})
.catch((e) => {
logger.error("Failed to redact reaction event", e);
});
}
} else {
const m = memberships.filter((m) => m.sender === userId);
const eventId = m[0].eventId!;
client
.sendEvent(rtcSession.room.roomId, EventType.Reaction, {
"m.relates_to": {
rel_type: RelationType.Annotation,
event_id: eventId,
key: "🖐️",
},
})
.then((reaction) => {
setReactionId(reaction.event_id);
setRaisedHands([...raisedHands, userId]);
logger.debug("Sent reaction event", reaction.event_id);
} catch (e) {
})
.catch((e) => {
logger.error("Failed to send reaction event", e);
}
}
} catch (e) {
logger.error(e);
});
}
}, [
client,
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5949,9 +5949,9 @@ matrix-events-sdk@0.0.1:
resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1.tgz#c8c38911e2cb29023b0bbac8d6f32e0de2c957dd"
integrity sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA==

matrix-js-sdk@matrix-org/matrix-js-sdk#169e8f86139111574a3738f8557c6fa4b2a199db:
version "34.4.0"
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/169e8f86139111574a3738f8557c6fa4b2a199db"
matrix-js-sdk@matrix-org/matrix-js-sdk#ed445149740231134d734cb411e13cb120cdb55b:
version "34.5.0"
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/ed445149740231134d734cb411e13cb120cdb55b"
dependencies:
"@babel/runtime" "^7.12.5"
"@matrix-org/matrix-sdk-crypto-wasm" "^7.0.0"
Expand Down

0 comments on commit 21d6c8d

Please sign in to comment.