You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Set minimum supported Matrix 1.1 version (drop legacy r0 versions) (#3007)
Co-authored-by: Germain <germains@element.io> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
200
src/client.ts
200
src/client.ts
@@ -133,7 +133,6 @@ import {
|
||||
IFilterResponse,
|
||||
ITagsResponse,
|
||||
IStatusResponse,
|
||||
IAddThreePidBody,
|
||||
KnockRoomOpts,
|
||||
} from "./@types/requests";
|
||||
import {
|
||||
@@ -1287,7 +1286,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
baseUrl: opts.baseUrl,
|
||||
idBaseUrl: opts.idBaseUrl,
|
||||
accessToken: opts.accessToken,
|
||||
prefix: ClientPrefix.R0,
|
||||
prefix: ClientPrefix.V3,
|
||||
onlyData: true,
|
||||
extraParams: opts.queryParams,
|
||||
localTimeoutMs: opts.localTimeoutMs,
|
||||
@@ -3430,9 +3429,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
await this.crypto.crossSigningInfo.signObject(data.auth_data, "master");
|
||||
}
|
||||
|
||||
const res = await this.http.authedRequest<IKeyBackupInfo>(Method.Post, "/room_keys/version", undefined, data, {
|
||||
prefix: ClientPrefix.V3,
|
||||
});
|
||||
const res = await this.http.authedRequest<IKeyBackupInfo>(Method.Post, "/room_keys/version", undefined, data);
|
||||
|
||||
// We could assume everything's okay and enable directly, but this ensures
|
||||
// we run the same signature verification that will be used for future
|
||||
@@ -3929,7 +3926,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
*/
|
||||
public getMediaConfig(): Promise<IMediaConfig> {
|
||||
return this.http.authedRequest(Method.Get, "/config", undefined, undefined, {
|
||||
prefix: MediaPrefix.R0,
|
||||
prefix: MediaPrefix.V3,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5184,7 +5181,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
},
|
||||
undefined,
|
||||
{
|
||||
prefix: MediaPrefix.R0,
|
||||
prefix: MediaPrefix.V3,
|
||||
priority: "low",
|
||||
},
|
||||
);
|
||||
@@ -5351,7 +5348,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
address: address,
|
||||
};
|
||||
|
||||
if (this.identityServer?.getAccessToken && (await this.doesServerAcceptIdentityAccessToken())) {
|
||||
if (this.identityServer?.getAccessToken) {
|
||||
const identityAccessToken = await this.identityServer.getAccessToken();
|
||||
if (identityAccessToken) {
|
||||
params["id_access_token"] = identityAccessToken;
|
||||
@@ -6143,7 +6140,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
const opts = {
|
||||
prefix:
|
||||
Thread.hasServerSideListSupport === FeatureSupport.Stable
|
||||
? "/_matrix/client/v1"
|
||||
? ClientPrefix.V1
|
||||
: "/_matrix/client/unstable/org.matrix.msc3856",
|
||||
};
|
||||
|
||||
@@ -6669,20 +6666,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
): Promise<T> {
|
||||
const postParams = Object.assign({}, params);
|
||||
|
||||
// If the HS supports separate add and bind, then requestToken endpoints
|
||||
// don't need an IS as they are all validated by the HS directly.
|
||||
if (!(await this.doesServerSupportSeparateAddAndBind()) && this.idBaseUrl) {
|
||||
const idServerUrl = new URL(this.idBaseUrl);
|
||||
postParams.id_server = idServerUrl.host;
|
||||
|
||||
if (this.identityServer?.getAccessToken && (await this.doesServerAcceptIdentityAccessToken())) {
|
||||
const identityAccessToken = await this.identityServer.getAccessToken();
|
||||
if (identityAccessToken) {
|
||||
postParams.id_access_token = identityAccessToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.http.request(Method.Post, endpoint, undefined, postParams);
|
||||
}
|
||||
|
||||
@@ -7387,78 +7370,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
return versions && versions.includes(version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the server to see if it supports members lazy loading
|
||||
* @returns true if server supports lazy loading
|
||||
*/
|
||||
public async doesServerSupportLazyLoading(): Promise<boolean> {
|
||||
const response = await this.getVersions();
|
||||
if (!response) return false;
|
||||
|
||||
const versions = response["versions"];
|
||||
const unstableFeatures = response["unstable_features"];
|
||||
|
||||
return (
|
||||
(versions && versions.includes("r0.5.0")) || (unstableFeatures && unstableFeatures["m.lazy_load_members"])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the server to see if the `id_server` parameter is required
|
||||
* when registering with an 3pid, adding a 3pid or resetting password.
|
||||
* @returns true if id_server parameter is required
|
||||
*/
|
||||
public async doesServerRequireIdServerParam(): Promise<boolean> {
|
||||
const response = await this.getVersions();
|
||||
if (!response) return true;
|
||||
|
||||
const versions = response["versions"];
|
||||
|
||||
// Supporting r0.6.0 is the same as having the flag set to false
|
||||
if (versions && versions.includes("r0.6.0")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const unstableFeatures = response["unstable_features"];
|
||||
if (!unstableFeatures) return true;
|
||||
if (unstableFeatures["m.require_identity_server"] === undefined) {
|
||||
return true;
|
||||
} else {
|
||||
return unstableFeatures["m.require_identity_server"];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the server to see if the `id_access_token` parameter can be safely
|
||||
* passed to the homeserver. Some homeservers may trigger errors if they are not
|
||||
* prepared for the new parameter.
|
||||
* @returns true if id_access_token can be sent
|
||||
*/
|
||||
public async doesServerAcceptIdentityAccessToken(): Promise<boolean> {
|
||||
const response = await this.getVersions();
|
||||
if (!response) return false;
|
||||
|
||||
const versions = response["versions"];
|
||||
const unstableFeatures = response["unstable_features"];
|
||||
return (versions && versions.includes("r0.6.0")) || (unstableFeatures && unstableFeatures["m.id_access_token"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the server to see if it supports separate 3PID add and bind functions.
|
||||
* This affects the sequence of API calls clients should use for these operations,
|
||||
* so it's helpful to be able to check for support.
|
||||
* @returns true if separate functions are supported
|
||||
*/
|
||||
public async doesServerSupportSeparateAddAndBind(): Promise<boolean> {
|
||||
const response = await this.getVersions();
|
||||
if (!response) return false;
|
||||
|
||||
const versions = response["versions"];
|
||||
const unstableFeatures = response["unstable_features"];
|
||||
|
||||
return versions?.includes("r0.6.0") || unstableFeatures?.["m.separate_add_and_bind"];
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the server to see if it lists support for an unstable feature
|
||||
* in the /versions response
|
||||
@@ -7530,14 +7441,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the server to see if it supports the MSC2457 `logout_devices` parameter when setting password
|
||||
* @returns true if server supports the `logout_devices` parameter
|
||||
*/
|
||||
public doesServerSupportLogoutDevices(): Promise<boolean> {
|
||||
return this.isVersionSupported("r0.6.1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if lazy loading members is being used.
|
||||
* @returns Whether or not members are lazy loaded by this client
|
||||
@@ -7922,18 +7825,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param relayState - URL Callback after SAML2 Authentication
|
||||
* @returns Promise which resolves to a LoginResponse object
|
||||
* @returns Rejects: with an error response.
|
||||
* @deprecated this isn't in the Matrix spec anymore
|
||||
*/
|
||||
public loginWithSAML2(relayState: string): Promise<LoginResponse> {
|
||||
return this.login("m.login.saml2", {
|
||||
relay_state: relayState,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param redirectUrl - The URL to redirect to after the HS
|
||||
* authenticates with CAS.
|
||||
@@ -7963,7 +7854,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
[SSO_ACTION_PARAM.unstable!]: action,
|
||||
};
|
||||
|
||||
return this.http.getUrl(url, params, ClientPrefix.R0).href;
|
||||
return this.http.getUrl(url, params).href;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -8081,13 +7972,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
$loginType: loginType,
|
||||
});
|
||||
|
||||
return this.http.getUrl(
|
||||
path,
|
||||
{
|
||||
session: authSessionId,
|
||||
},
|
||||
ClientPrefix.R0,
|
||||
).href;
|
||||
return this.http.getUrl(path, {
|
||||
session: authSessionId,
|
||||
}).href;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -8102,11 +7989,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
|
||||
// inject the id_access_token if inviting 3rd party addresses
|
||||
const invitesNeedingToken = (options.invite_3pid || []).filter((i) => !i.id_access_token);
|
||||
if (
|
||||
invitesNeedingToken.length > 0 &&
|
||||
this.identityServer?.getAccessToken &&
|
||||
(await this.doesServerAcceptIdentityAccessToken())
|
||||
) {
|
||||
if (invitesNeedingToken.length > 0 && this.identityServer?.getAccessToken) {
|
||||
const identityAccessToken = await this.identityServer.getAccessToken();
|
||||
if (identityAccessToken) {
|
||||
for (const invite of invitesNeedingToken) {
|
||||
@@ -8465,30 +8348,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
return this.http.authedRequest(Method.Put, path, undefined, { visibility });
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the visbility of a room bridged to a 3rd party network in
|
||||
* the current HS's room directory.
|
||||
* @param networkId - the network ID of the 3rd party
|
||||
* instance under which this room is published under.
|
||||
* @param visibility - "public" to make the room visible
|
||||
* in the public directory, or "private" to make
|
||||
* it invisible.
|
||||
* @returns Promise which resolves: result object
|
||||
* @returns Rejects: with an error response.
|
||||
* @deprecated missing from the spec
|
||||
*/
|
||||
public setRoomDirectoryVisibilityAppService(
|
||||
networkId: string,
|
||||
roomId: string,
|
||||
visibility: "public" | "private",
|
||||
): Promise<any> {
|
||||
const path = utils.encodeUri("/directory/list/appservice/$networkId/$roomId", {
|
||||
$networkId: networkId,
|
||||
$roomId: roomId,
|
||||
});
|
||||
return this.http.authedRequest(Method.Put, path, undefined, { visibility: visibility });
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the user directory with a term matching user IDs, display names and domains.
|
||||
* @param term - the term with which to search.
|
||||
@@ -8571,31 +8430,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
return this.http.authedRequest(Method.Get, "/account/3pid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a 3PID to your homeserver account and optionally bind it to an identity
|
||||
* server as well. An identity server is required as part of the `creds` object.
|
||||
*
|
||||
* @deprecated this API is deprecated, and you should instead use `addThreePidOnly` for homeservers that support it.
|
||||
*
|
||||
* @returns Promise which resolves: on success
|
||||
* @returns Rejects: with an error response.
|
||||
*/
|
||||
public addThreePid(creds: IAddThreePidBody, bind: boolean): Promise<{ submit_url?: string }> {
|
||||
const path = "/account/3pid";
|
||||
const data = {
|
||||
threePidCreds: creds,
|
||||
bind: bind,
|
||||
};
|
||||
return this.http.authedRequest(Method.Post, path, undefined, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a 3PID to your homeserver account. This API does not use an identity
|
||||
* server, as the homeserver is expected to handle 3PID ownership validation.
|
||||
*
|
||||
* You can check whether a homeserver supports this API via
|
||||
* `doesServerSupportSeparateAddAndBind`.
|
||||
*
|
||||
* @param data - A object with 3PID validation data from having called
|
||||
* `account/3pid/<medium>/requestToken` on the homeserver.
|
||||
* @returns Promise which resolves: to an empty object `{}`
|
||||
@@ -8603,8 +8441,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
*/
|
||||
public async addThreePidOnly(data: IAddThreePidOnlyBody): Promise<{}> {
|
||||
const path = "/account/3pid/add";
|
||||
const prefix = (await this.isVersionSupported("r0.6.0")) ? ClientPrefix.R0 : ClientPrefix.Unstable;
|
||||
return this.http.authedRequest(Method.Post, path, undefined, data, { prefix });
|
||||
return this.http.authedRequest(Method.Post, path, undefined, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -8612,9 +8449,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* identity server handles 3PID ownership validation and the homeserver records
|
||||
* the new binding to track where all 3PIDs for the account are bound.
|
||||
*
|
||||
* You can check whether a homeserver supports this API via
|
||||
* `doesServerSupportSeparateAddAndBind`.
|
||||
*
|
||||
* @param data - A object with 3PID validation data from having called
|
||||
* `validate/<medium>/requestToken` on the identity server. It should also
|
||||
* contain `id_server` and `id_access_token` fields as well.
|
||||
@@ -8623,8 +8457,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
*/
|
||||
public async bindThreePid(data: IBindThreePidBody): Promise<{}> {
|
||||
const path = "/account/3pid/bind";
|
||||
const prefix = (await this.isVersionSupported("r0.6.0")) ? ClientPrefix.R0 : ClientPrefix.Unstable;
|
||||
return this.http.authedRequest(Method.Post, path, undefined, data, { prefix });
|
||||
return this.http.authedRequest(Method.Post, path, undefined, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -8649,8 +8482,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
address,
|
||||
id_server: this.getIdentityServerUrl(true),
|
||||
};
|
||||
const prefix = (await this.isVersionSupported("r0.6.0")) ? ClientPrefix.R0 : ClientPrefix.Unstable;
|
||||
return this.http.authedRequest(Method.Post, path, undefined, data, { prefix });
|
||||
return this.http.authedRequest(Method.Post, path, undefined, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -8958,9 +8790,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
}
|
||||
|
||||
public uploadKeySignatures(content: KeySignatures): Promise<IUploadKeySignaturesResponse> {
|
||||
return this.http.authedRequest(Method.Post, "/keys/signatures/upload", undefined, content, {
|
||||
prefix: ClientPrefix.V3,
|
||||
});
|
||||
return this.http.authedRequest(Method.Post, "/keys/signatures/upload", undefined, content);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user