Skip to content

Commit

Permalink
fix use of MatrixClientContext
Browse files Browse the repository at this point in the history
  • Loading branch information
odelcroi committed Feb 12, 2024
1 parent 64aecb4 commit 9a17175
Showing 1 changed file with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { logger } from "matrix-js-sdk/src/logger";
import AccessibleButton from "matrix-react-sdk/src/components/views/elements/AccessibleButton";
import { _t } from "matrix-react-sdk/src/languageHandler";

import { MatrixClientPeg } from "matrix-react-sdk/src/MatrixClientPeg";
import SdkConfig from "matrix-react-sdk/src/SdkConfig";
import Modal from "matrix-react-sdk/src/Modal";

Expand All @@ -29,6 +28,7 @@ import UpdateCheckButton from "matrix-react-sdk/src/components/views/settings/Up
import BugReportDialog from "matrix-react-sdk/src/components/views/dialogs/BugReportDialog";
import CopyableText from "matrix-react-sdk/src/components/views/elements/CopyableText";
import ExternalLink from "matrix-react-sdk/src/components/views/elements/ExternalLink";
import MatrixClientContext from "matrix-react-sdk/src/contexts/MatrixClientContext";

interface IProps {
closeSettingsFn: () => void;
Expand All @@ -39,7 +39,12 @@ interface IState {
canUpdate: boolean;
}

//Tchap : This class is a replacement (via customizations) for matrix-react-sdk/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx
export default class HelpUserSettingsTab extends React.Component<IProps, IState> {
//those lines instantiate the 'context' which is kind of a singleton for a matrix client
public static contextType = MatrixClientContext;
public context!: React.ContextType<typeof MatrixClientContext>;

public constructor(props: IProps) {
super(props);

Expand Down Expand Up @@ -81,8 +86,8 @@ export default class HelpUserSettingsTab extends React.Component<IProps, IState>
// Dev note: please keep this log line, it's useful when troubleshooting a MatrixClient suddenly
// stopping in the middle of the logs.
logger.log("Clear cache & reload clicked");
MatrixClientPeg.get().stopClient();
MatrixClientPeg.get()
this.context.stopClient();
this.context
.store.deleteAllData()
.then(() => {
PlatformPeg.get()?.reload();
Expand Down Expand Up @@ -192,8 +197,8 @@ export default class HelpUserSettingsTab extends React.Component<IProps, IState>
}

private getVersionTextToCopy = (): string => {
const { appVersion, olmVersion } = this.getVersionInfo();
return `${appVersion}\n${olmVersion}`;
const { appVersion, cryptoVersion } = this.getVersionInfo();
return `${appVersion}\n${cryptoVersion}`;
};

/* :TCHAP: unused
Expand Down Expand Up @@ -296,7 +301,7 @@ export default class HelpUserSettingsTab extends React.Component<IProps, IState>
);
}

const { appVersion, olmVersion } = this.getVersionInfo();
const { appVersion, cryptoVersion } = this.getVersionInfo();

// :TCHAP: add Contact us section, proper FAQ section, Known Issues section
const supportEmail = "[email protected]";
Expand Down Expand Up @@ -398,7 +403,7 @@ export default class HelpUserSettingsTab extends React.Component<IProps, IState>
<CopyableText getTextToCopy={this.getVersionTextToCopy}>
{appVersion}
<br />
{olmVersion}
{cryptoVersion}
<br />
</CopyableText>
{updateButton}
Expand All @@ -413,19 +418,19 @@ export default class HelpUserSettingsTab extends React.Component<IProps, IState>
{_t(
"setting|help_about|homeserver",
{
homeserverUrl: MatrixClientPeg.get().getHomeserverUrl(),
homeserverUrl: this.context.getHomeserverUrl(),
},
{
code: (sub) => <code>{sub}</code>,
},
)}
</div>
<div>
{MatrixClientPeg.get().getIdentityServerUrl() &&
{this.context.getIdentityServerUrl() &&
_t(
"setting|help_about|identity_server",
{
identityServerUrl: MatrixClientPeg.get().getIdentityServerUrl(),
identityServerUrl: this.context.getIdentityServerUrl(),
},
{
code: (sub) => <code>{sub}</code>,
Expand All @@ -439,8 +444,8 @@ export default class HelpUserSettingsTab extends React.Component<IProps, IState>
"setting|help_about|access_token_detail",
)}
</b>
<CopyableText getTextToCopy={() => MatrixClientPeg.get().getAccessToken()}>
{MatrixClientPeg.get().getAccessToken()}
<CopyableText getTextToCopy={() => this.context.getAccessToken()}>
{this.context.getAccessToken()}
</CopyableText>
</details>
<AccessibleButton onClick={this.onClearCacheAndReload} kind="danger">
Expand Down

0 comments on commit 9a17175

Please sign in to comment.