Files
cinny/src/app/utils/consent.ts
T

22 lines
784 B
TypeScript
Raw Normal View History

import { EventStatus, MatrixEvent } from 'matrix-js-sdk';
export const CONSENT_ERRCODE = 'M_CONSENT_NOT_GIVEN';
/**
* The consent page comes from whichever homeserver the user is on (this client
* works with any of them), so only ever open a plain web link.
*/
export const safeConsentUri = (uri: unknown): string | undefined => {
if (typeof uri !== 'string') return undefined;
try {
const url = new URL(uri);
return url.protocol === 'https:' || url.protocol === 'http:' ? url.href : undefined;
} catch {
return undefined;
}
};
/** True when a local echo failed because the server wants the ToS accepted. */
export const failedForConsent = (event: MatrixEvent): boolean =>
event.status === EventStatus.NOT_SENT && event.error?.errcode === CONSENT_ERRCODE;