Skip to content

Commit

Permalink
WIP: check for reaction and redaction event capabilities to enable / …
Browse files Browse the repository at this point in the history
…disable hand raise feature

Signed-off-by: Milton Moura <[email protected]>
  • Loading branch information
mgcm committed Sep 18, 2024
1 parent c285a2f commit f6b811b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 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#ed445149740231134d734cb411e13cb120cdb55b",
"matrix-js-sdk": "matrix-org/matrix-js-sdk#fab9cab3df0622b5b9d3e047a05b6bd93431077e",
"matrix-widget-api": "^1.8.2",
"normalize.css": "^8.0.1",
"observable-hooks": "^4.2.3",
Expand Down
26 changes: 26 additions & 0 deletions src/ClientContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
import { translatedError } from "./TranslatedError";
import { useEventTarget } from "./useEvents";
import { Config } from "./config/Config";
import { WidgetApi } from "matrix-widget-api";

declare global {
interface Window {
Expand Down Expand Up @@ -188,6 +189,7 @@ export const ClientProvider: FC<Props> = ({ children }) => {
saveSession({ ...session, passwordlessUser: false });

setInitClientState({
widgetApi: initClientState.widgetApi,

Check warning on line 192 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L192

Added line #L192 was not covered by tests
client: initClientState.client,
passwordlessUser: false,
});
Expand All @@ -206,6 +208,7 @@ export const ClientProvider: FC<Props> = ({ children }) => {
if (clientParams) {
saveSession(clientParams.session);
setInitClientState({
widgetApi: null,

Check warning on line 211 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L211

Added line #L211 was not covered by tests
client: clientParams.client,
passwordlessUser: clientParams.session.passwordlessUser,
});
Expand Down Expand Up @@ -309,6 +312,26 @@ export const ClientProvider: FC<Props> = ({ children }) => {
initClientState.client.on(ClientEvent.Sync, onSync);
}

console.warn("Checking for WidgetApi capabilities");
if (initClientState.widgetApi) {
let supportsReactions = true;

Check warning on line 317 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L315-L317

Added lines #L315 - L317 were not covered by tests

const reactSend = initClientState.widgetApi.hasCapability("org.matrix.msc2762.send.event:m.reaction");
const redactSend = initClientState.widgetApi.hasCapability("org.matrix.msc2762.send.event:m.room.redaction");
const reactRcv = initClientState.widgetApi.hasCapability("org.matrix.msc2762.receive.event:m.reaction");
const redactRcv = initClientState.widgetApi.hasCapability("org.matrix.msc2762.receive.event:m.room.redaction");

Check warning on line 322 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L319-L322

Added lines #L319 - L322 were not covered by tests

if (!reactSend || !reactRcv || !redactSend || !redactRcv) {
supportsReactions = false;
}

Check warning on line 326 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L324-L326

Added lines #L324 - L326 were not covered by tests

if (!supportsReactions) {
console.warn("Widget does not support reactions");
} else {
console.warn("Widget does support reactions");
}
}

Check warning on line 333 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L328-L333

Added lines #L328 - L333 were not covered by tests

return (): void => {
if (initClientState.client) {
initClientState.client.removeListener(ClientEvent.Sync, onSync);
Expand All @@ -326,6 +349,7 @@ export const ClientProvider: FC<Props> = ({ children }) => {
};

type InitResult = {
widgetApi: WidgetApi | null;
client: MatrixClient;
passwordlessUser: boolean;
};
Expand All @@ -336,6 +360,7 @@ async function loadClient(): Promise<InitResult | null> {
logger.log("Using a matryoshka client");
const client = await widget.client;
return {
widgetApi: widget.api,

Check warning on line 363 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L363

Added line #L363 was not covered by tests
client,
passwordlessUser: false,
};
Expand Down Expand Up @@ -364,6 +389,7 @@ async function loadClient(): Promise<InitResult | null> {
try {
const client = await initClient(initClientParams, true);
return {
widgetApi: null,

Check warning on line 392 in src/ClientContext.tsx

View check run for this annotation

Codecov / codecov/patch

src/ClientContext.tsx#L392

Added line #L392 was not covered by tests
client,
passwordlessUser,
};
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1894,10 +1894,10 @@
dependencies:
"@bufbuild/protobuf" "^1.7.2"

"@matrix-org/matrix-sdk-crypto-wasm@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-7.0.0.tgz#8d6abdb9ded8656cc9e2a7909913a34bf3fc9b3a"
integrity sha512-MOencXiW/gI5MuTtCNsuojjwT5DXCrjMqv9xOslJC9h2tPdLFFFMGr58dY5Lis4DRd9MRWcgrGowUIHOqieWTA==
"@matrix-org/matrix-sdk-crypto-wasm@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-8.0.0.tgz#6ddc0e63538e821a2efbc5c1a2f0fa0f71d489ff"
integrity sha512-s0q3O2dK8b6hOJ+SZFz+s/IiMabmVsNue6r17sTwbrRD8liBkCrpjYnxoMYvtC01GggJ9TZLQbeqpt8hQSPHAg==

"@matrix-org/[email protected]":
version "3.2.15"
Expand Down Expand Up @@ -5954,12 +5954,12 @@ [email protected]:
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#ed445149740231134d734cb411e13cb120cdb55b:
matrix-js-sdk@matrix-org/matrix-js-sdk#fab9cab3df0622b5b9d3e047a05b6bd93431077e:
version "34.5.0"
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/ed445149740231134d734cb411e13cb120cdb55b"
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/fab9cab3df0622b5b9d3e047a05b6bd93431077e"
dependencies:
"@babel/runtime" "^7.12.5"
"@matrix-org/matrix-sdk-crypto-wasm" "^7.0.0"
"@matrix-org/matrix-sdk-crypto-wasm" "^8.0.0"
"@matrix-org/olm" "3.2.15"
another-json "^0.2.0"
bs58 "^6.0.0"
Expand Down

0 comments on commit f6b811b

Please sign in to comment.