Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 148a360

Browse files
authored
Avoid using deprecated exports, fields, and duplicate code (#12555)
1 parent 1973197 commit 148a360

33 files changed

+258
-108
lines changed

src/MatrixClientPeg.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,6 @@ export interface IMatrixClientPeg {
7878
*/
7979
opts: IStartClientOpts;
8080

81-
/**
82-
* Return the server name of the user's homeserver
83-
* Throws an error if unable to deduce the homeserver name
84-
* (e.g. if the user is not logged in)
85-
*
86-
* @returns {string} The homeserver name, if present.
87-
*/
88-
getHomeserverName(): string;
89-
9081
/**
9182
* Get the current MatrixClient, if any
9283
*/
@@ -384,14 +375,6 @@ class MatrixClientPegClass implements IMatrixClientPeg {
384375
logger.log(`MatrixClientPeg: MatrixClient started`);
385376
}
386377

387-
public getHomeserverName(): string {
388-
const matches = /^@[^:]+:(.+)$/.exec(this.safeGet().getSafeUserId());
389-
if (matches === null || matches.length < 1) {
390-
throw new Error("Failed to derive homeserver name from user ID!");
391-
}
392-
return matches[1];
393-
}
394-
395378
private namesToRoomName(names: string[], count: number): string | undefined {
396379
const countWithoutMe = count - 1;
397380
if (!names.length) {

src/SecurityManager.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import {
18-
DeviceVerificationStatus,
19-
ICryptoCallbacks,
20-
MatrixClient,
21-
encodeBase64,
22-
SecretStorage,
23-
} from "matrix-js-sdk/src/matrix";
17+
import { Crypto, ICryptoCallbacks, MatrixClient, encodeBase64, SecretStorage } from "matrix-js-sdk/src/matrix";
2418
import { deriveKey } from "matrix-js-sdk/src/crypto/key_passphrase";
2519
import { decodeRecoveryKey } from "matrix-js-sdk/src/crypto/recoverykey";
2620
import { logger } from "matrix-js-sdk/src/logger";
@@ -249,7 +243,7 @@ async function onSecretRequested(
249243
deviceId: string,
250244
requestId: string,
251245
name: string,
252-
deviceTrust: DeviceVerificationStatus,
246+
deviceTrust: Crypto.DeviceVerificationStatus,
253247
): Promise<string | undefined> {
254248
logger.log("onSecretRequested", userId, deviceId, requestId, name, deviceTrust);
255249
const client = MatrixClientPeg.safeGet();

src/components/views/dialogs/CreateRoomDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
436436
</summary>
437437
<LabelledToggleSwitch
438438
label={_t("create_room|unfederated", {
439-
serverName: MatrixClientPeg.getHomeserverName(),
439+
serverName: MatrixClientPeg.safeGet().getDomain(),
440440
})}
441441
onChange={this.onNoFederateChange}
442442
value={this.state.noFederate}

src/components/views/dialogs/ServerOfflineDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default class ServerOfflineDialog extends React.PureComponent<IProps> {
9595
timeline = [<div key={1}>{_t("server_offline|empty_timeline")}</div>];
9696
}
9797

98-
const serverName = MatrixClientPeg.getHomeserverName();
98+
const serverName = MatrixClientPeg.safeGet().getDomain();
9999
return (
100100
<BaseDialog
101101
title={_t("server_offline|title")}

src/components/views/dialogs/devtools/ServerInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function getServerVersionFromFederationApi(client: MatrixClient): P
3838
let baseUrl = client.getHomeserverUrl();
3939

4040
try {
41-
const hsName = MatrixClientPeg.getHomeserverName();
41+
const hsName = MatrixClientPeg.safeGet().getDomain();
4242
// We don't use the js-sdk Autodiscovery module here as it only support client well-known, not server ones.
4343
const response = await fetch(`https://${hsName}/.well-known/matrix/server`);
4444
const json = await response.json();

src/components/views/directory/NetworkDropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function useServers(): ServerList {
118118
SettingLevel.ACCOUNT,
119119
);
120120

121-
const homeServer = MatrixClientPeg.getHomeserverName();
121+
const homeServer = MatrixClientPeg.safeGet().getDomain()!;
122122
const configServers = new Set<string>(SdkConfig.getObject("room_directory")?.get("servers") ?? []);
123123
removeAll(configServers, homeServer);
124124
// configured servers take preference over user-defined ones, if one occurs in both ignore the latter one.

src/components/views/right_panel/UserInfo.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import DMRoomMap from "../../../utils/DMRoomMap";
4343
import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton";
4444
import SdkConfig from "../../../SdkConfig";
4545
import MultiInviter from "../../../utils/MultiInviter";
46-
import { MatrixClientPeg } from "../../../MatrixClientPeg";
4746
import E2EIcon from "../rooms/E2EIcon";
4847
import { useTypedEventEmitter } from "../../../hooks/useEventEmitter";
4948
import { textualPowerLevel } from "../../../Roles";
@@ -1413,8 +1412,7 @@ const BasicUserInfo: React.FC<{
14131412

14141413
// We don't need a perfect check here, just something to pass as "probably not our homeserver". If
14151414
// someone does figure out how to bypass this check the worst that happens is an error.
1416-
// FIXME this should be using cli instead of MatrixClientPeg.matrixClient
1417-
if (isSynapseAdmin && member.userId.endsWith(`:${MatrixClientPeg.getHomeserverName()}`)) {
1415+
if (isSynapseAdmin && member.userId.endsWith(`:${cli.getDomain()}`)) {
14181416
synapseDeactivateButton = (
14191417
<AccessibleButton
14201418
kind="link"

src/hooks/usePublicRoomDirectory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const usePublicRoomDirectory = (): {
9090
async ({ limit = 20, query, roomTypes }: IPublicRoomsOpts): Promise<boolean> => {
9191
const opts: IRoomDirectoryOptions = { limit };
9292

93-
if (config?.roomServer != MatrixClientPeg.getHomeserverName()) {
93+
if (config?.roomServer != MatrixClientPeg.safeGet().getDomain()) {
9494
opts.server = config?.roomServer;
9595
}
9696

@@ -139,7 +139,7 @@ export const usePublicRoomDirectory = (): {
139139
return;
140140
}
141141

142-
const myHomeserver = MatrixClientPeg.getHomeserverName();
142+
const myHomeserver = MatrixClientPeg.safeGet().getDomain()!;
143143
const lsRoomServer = localStorage.getItem(LAST_SERVER_KEY);
144144
const lsInstanceId: string | undefined = localStorage.getItem(LAST_INSTANCE_KEY) ?? undefined;
145145

src/rageshake/submit-rageshake.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
*/
1818

1919
import { logger } from "matrix-js-sdk/src/logger";
20-
import { Method, MatrixClient, CryptoApi } from "matrix-js-sdk/src/matrix";
20+
import { Method, MatrixClient, Crypto } from "matrix-js-sdk/src/matrix";
2121

2222
import type * as Pako from "pako";
2323
import { MatrixClientPeg } from "../MatrixClientPeg";
@@ -177,7 +177,7 @@ async function collectSynapseSpecific(client: MatrixClient, body: FormData): Pro
177177
/**
178178
* Collects crypto related information.
179179
*/
180-
async function collectCryptoInfo(cryptoApi: CryptoApi, body: FormData): Promise<void> {
180+
async function collectCryptoInfo(cryptoApi: Crypto.CryptoApi, body: FormData): Promise<void> {
181181
body.append("crypto_version", cryptoApi.getVersion());
182182

183183
const ownDeviceKeys = await cryptoApi.getOwnDeviceKeys();
@@ -206,7 +206,7 @@ async function collectCryptoInfo(cryptoApi: CryptoApi, body: FormData): Promise<
206206
/**
207207
* Collects information about secret storage and backup.
208208
*/
209-
async function collectRecoveryInfo(client: MatrixClient, cryptoApi: CryptoApi, body: FormData): Promise<void> {
209+
async function collectRecoveryInfo(client: MatrixClient, cryptoApi: Crypto.CryptoApi, body: FormData): Promise<void> {
210210
const secretStorage = client.secretStorage;
211211
body.append("secret_storage_ready", String(await cryptoApi.isSecretStorageReady()));
212212
body.append("secret_storage_key_in_account", String(await secretStorage.hasKey()));

src/utils/AutoDiscoveryUtils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const mapAutoDiscoveryErrorTranslation = (err: AutoDiscoveryError): TranslationK
6868
return _td("auth|autodiscovery_no_well_known");
6969
case AutoDiscoveryError.InvalidJson:
7070
return _td("auth|autodiscovery_invalid_json");
71-
case AutoDiscoveryError.HomeserverTooOld:
71+
case AutoDiscoveryError.UnsupportedHomeserverSpecVersion:
7272
return _td("auth|autodiscovery_hs_incompatible");
7373
}
7474
};

0 commit comments

Comments
 (0)