Support for MSC3882 revision 1 (#10443)
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
700af0954a
commit
5c0e5eb0fb
8 changed files with 114 additions and 9 deletions
|
@ -15,8 +15,12 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import React from "react";
|
||||
import {
|
||||
IMSC3882GetLoginTokenCapability,
|
||||
IServerVersions,
|
||||
UNSTABLE_MSC3882_CAPABILITY,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import type { IServerVersions } from "matrix-js-sdk/src/matrix";
|
||||
import { _t } from "../../../../languageHandler";
|
||||
import AccessibleButton from "../../elements/AccessibleButton";
|
||||
import SettingsSubsection from "../shared/SettingsSubsection";
|
||||
|
@ -24,6 +28,8 @@ import SettingsSubsection from "../shared/SettingsSubsection";
|
|||
interface IProps {
|
||||
onShowQr: () => void;
|
||||
versions?: IServerVersions;
|
||||
// we can't use the capabilities type from the js-sdk because it isn't exported
|
||||
capabilities?: Record<string, any>;
|
||||
}
|
||||
|
||||
export default class LoginWithQRSection extends React.Component<IProps> {
|
||||
|
@ -33,7 +39,10 @@ export default class LoginWithQRSection extends React.Component<IProps> {
|
|||
|
||||
public render(): JSX.Element | null {
|
||||
// Needs server support for MSC3882 and MSC3886:
|
||||
const msc3882Supported = !!this.props.versions?.unstable_features?.["org.matrix.msc3882"];
|
||||
// in r0 of MSC3882 it is exposed as a feature flag, but in r1 it is a capability
|
||||
const capability = UNSTABLE_MSC3882_CAPABILITY.findIn<IMSC3882GetLoginTokenCapability>(this.props.capabilities);
|
||||
const msc3882Supported =
|
||||
!!this.props.versions?.unstable_features?.["org.matrix.msc3882"] || !!capability?.enabled;
|
||||
const msc3886Supported = !!this.props.versions?.unstable_features?.["org.matrix.msc3886"];
|
||||
const offerShowQr = msc3882Supported && msc3886Supported;
|
||||
|
||||
|
|
|
@ -82,6 +82,8 @@ interface IState {
|
|||
invitedRoomIds: Set<string>;
|
||||
showLoginWithQR: Mode | null;
|
||||
versions?: IServerVersions;
|
||||
// we can't use the capabilities type from the js-sdk because it isn't exported
|
||||
capabilities?: Record<string, any>;
|
||||
}
|
||||
|
||||
export default class SecurityUserSettingsTab extends React.Component<IProps, IState> {
|
||||
|
@ -116,6 +118,9 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt
|
|||
MatrixClientPeg.get()
|
||||
.getVersions()
|
||||
.then((versions) => this.setState({ versions }));
|
||||
MatrixClientPeg.get()
|
||||
.getCapabilities()
|
||||
.then((capabilities) => this.setState({ capabilities }));
|
||||
}
|
||||
|
||||
public componentWillUnmount(): void {
|
||||
|
@ -393,7 +398,11 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt
|
|||
</span>
|
||||
<DevicesPanel />
|
||||
</div>
|
||||
<LoginWithQRSection onShowQr={this.onShowQRClicked} versions={this.state.versions} />
|
||||
<LoginWithQRSection
|
||||
onShowQr={this.onShowQRClicked}
|
||||
versions={this.state.versions}
|
||||
capabilities={this.state.capabilities}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
|
|
|
@ -132,6 +132,7 @@ const SessionManagerTab: React.FC = () => {
|
|||
const userId = matrixClient?.getUserId();
|
||||
const currentUserMember = (userId && matrixClient?.getUser(userId)) || undefined;
|
||||
const clientVersions = useAsyncMemo(() => matrixClient.getVersions(), [matrixClient]);
|
||||
const capabilities = useAsyncMemo(async () => matrixClient?.getCapabilities(), [matrixClient]);
|
||||
|
||||
const onDeviceExpandToggle = (deviceId: ExtendedDevice["device_id"]): void => {
|
||||
if (expandedDeviceIds.includes(deviceId)) {
|
||||
|
@ -279,7 +280,7 @@ const SessionManagerTab: React.FC = () => {
|
|||
/>
|
||||
</SettingsSubsection>
|
||||
)}
|
||||
<LoginWithQRSection onShowQr={onShowQrClicked} versions={clientVersions} />
|
||||
<LoginWithQRSection onShowQr={onShowQrClicked} versions={clientVersions} capabilities={capabilities} />
|
||||
</SettingsTab>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue