You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
committed by
GitHub
parent
21cc9c3d8a
commit
d70ffdbc02
@ -1336,18 +1336,25 @@ describe("MatrixClient", function () {
|
||||
it.each([
|
||||
{
|
||||
userId: "alice@localhost",
|
||||
powerLevel: 100,
|
||||
expectation: {
|
||||
"alice@localhost": 100,
|
||||
},
|
||||
},
|
||||
{
|
||||
userId: ["alice@localhost", "bob@localhost"],
|
||||
powerLevel: 100,
|
||||
expectation: {
|
||||
"alice@localhost": 100,
|
||||
"bob@localhost": 100,
|
||||
},
|
||||
},
|
||||
])("should modify power levels of $userId correctly", async ({ userId, expectation }) => {
|
||||
{
|
||||
userId: "alice@localhost",
|
||||
powerLevel: undefined,
|
||||
expectation: {},
|
||||
},
|
||||
])("should modify power levels of $userId correctly", async ({ userId, powerLevel, expectation }) => {
|
||||
const event = {
|
||||
getType: () => "m.room.power_levels",
|
||||
getContent: () => ({
|
||||
@ -1364,7 +1371,7 @@ describe("MatrixClient", function () {
|
||||
})
|
||||
.respond(200, {});
|
||||
|
||||
const prom = client!.setPowerLevel("!room_id:server", userId, 100, event);
|
||||
const prom = client!.setPowerLevel("!room_id:server", userId, powerLevel, event);
|
||||
await httpBackend!.flushAllExpected();
|
||||
await prom;
|
||||
});
|
||||
|
@ -20,5 +20,5 @@ export interface IIdentityServerProvider {
|
||||
* for the associated client.
|
||||
* @returns Promise which resolves to the access token.
|
||||
*/
|
||||
getAccessToken(): Promise<string>;
|
||||
getAccessToken(): Promise<string | null>;
|
||||
}
|
||||
|
@ -4130,7 +4130,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
public setPowerLevel(
|
||||
roomId: string,
|
||||
userId: string | string[],
|
||||
powerLevel: number,
|
||||
powerLevel: number | undefined,
|
||||
event: MatrixEvent | null,
|
||||
): Promise<ISendEventResponse> {
|
||||
let content = {
|
||||
@ -4141,13 +4141,16 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
// existing client state with a failed power level change
|
||||
content = utils.deepCopy(event.getContent());
|
||||
}
|
||||
if (Array.isArray(userId)) {
|
||||
for (const user of userId) {
|
||||
|
||||
const users = Array.isArray(userId) ? userId : [userId];
|
||||
for (const user of users) {
|
||||
if (powerLevel == null) {
|
||||
delete content.users[user];
|
||||
} else {
|
||||
content.users[user] = powerLevel;
|
||||
}
|
||||
} else {
|
||||
content.users[userId] = powerLevel;
|
||||
}
|
||||
|
||||
const path = utils.encodeUri("/rooms/$roomId/state/m.room.power_levels", {
|
||||
$roomId: roomId,
|
||||
});
|
||||
@ -8746,18 +8749,19 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
email: string,
|
||||
clientSecret: string,
|
||||
sendAttempt: number,
|
||||
nextLink: string,
|
||||
nextLink?: string,
|
||||
identityAccessToken?: string,
|
||||
): Promise<any> {
|
||||
// TODO: Types
|
||||
const params = {
|
||||
): Promise<IRequestTokenResponse> {
|
||||
const params: Record<string, string> = {
|
||||
client_secret: clientSecret,
|
||||
email: email,
|
||||
send_attempt: sendAttempt?.toString(),
|
||||
next_link: nextLink,
|
||||
};
|
||||
if (nextLink) {
|
||||
params.next_link = nextLink;
|
||||
}
|
||||
|
||||
return this.http.idServerRequest(
|
||||
return this.http.idServerRequest<IRequestTokenResponse>(
|
||||
Method.Post,
|
||||
"/validate/email/requestToken",
|
||||
params,
|
||||
@ -8788,7 +8792,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @param identityAccessToken - The `access_token` field of the Identity
|
||||
* Server `/account/register` response (see {@link registerWithIdentityServer}).
|
||||
*
|
||||
* @returns Promise which resolves: TODO
|
||||
* @returns Promise which resolves to an object with a sid string
|
||||
* @returns Rejects: with an error response.
|
||||
* @throws Error if no identity server is set
|
||||
*/
|
||||
@ -8797,19 +8801,20 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
phoneNumber: string,
|
||||
clientSecret: string,
|
||||
sendAttempt: number,
|
||||
nextLink: string,
|
||||
nextLink?: string,
|
||||
identityAccessToken?: string,
|
||||
): Promise<any> {
|
||||
// TODO: Types
|
||||
const params = {
|
||||
): Promise<IRequestMsisdnTokenResponse> {
|
||||
const params: Record<string, string> = {
|
||||
client_secret: clientSecret,
|
||||
country: phoneCountry,
|
||||
phone_number: phoneNumber,
|
||||
send_attempt: sendAttempt?.toString(),
|
||||
next_link: nextLink,
|
||||
};
|
||||
if (nextLink) {
|
||||
params.next_link = nextLink;
|
||||
}
|
||||
|
||||
return this.http.idServerRequest(
|
||||
return this.http.idServerRequest<IRequestMsisdnTokenResponse>(
|
||||
Method.Post,
|
||||
"/validate/msisdn/requestToken",
|
||||
params,
|
||||
|
@ -70,7 +70,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
|
||||
this.opts.idBaseUrl = url;
|
||||
}
|
||||
|
||||
public idServerRequest<T extends Record<string, unknown>>(
|
||||
public idServerRequest<T extends {} = Record<string, unknown>>(
|
||||
method: Method,
|
||||
path: string,
|
||||
params: Record<string, string | string[]> | undefined,
|
||||
|
Reference in New Issue
Block a user