Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial MSC3244 support and type cleanup #1745

Merged
merged 15 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/@types/partials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,31 @@ export enum Preset {
}

export type ResizeMethod = "crop" | "scale";

// Knock and private are reserved keywords which are not yet implemented.
export enum JoinRule {
Public = "public",
Invite = "invite",
/**
* @deprecated Reserved keyword. Should not be used. Not yet implemented.
*/
Private = "private",
Knock = "knock", // MSC2403 - only valid inside experimental room versions at this time.
Restricted = "restricted", // MSC3083 - only valid inside experimental room versions at this time.
}

export enum RestrictedAllowType {
RoomMembership = "m.room_membership", // MSC3083 - only valid inside experimental room versions at this time.
}

export enum GuestAccess {
CanJoin = "can_join",
Forbidden = "forbidden",
}

export enum HistoryVisibility {
Invited = "invited",
Joined = "joined",
Shared = "shared",
WorldReadable = "world_readable",
}
3 changes: 2 additions & 1 deletion src/@types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

import { Callback } from "../client";
import { IContent } from "../models/event";
import { Preset, Visibility } from "./partials";

// allow camelcase as these are things go onto the wire
Expand Down Expand Up @@ -82,7 +83,7 @@ export interface IInvite3PID {
export interface ICreateRoomStateEvent {
type: string;
state_key?: string; // defaults to an empty string
content: object;
content: IContent;
}

export interface ICreateRoomOpts {
Expand Down
20 changes: 15 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,15 @@ export enum RoomVersionStability {
Unstable = "unstable",
}

export interface IRoomCapability { // MSC3244
preferred: string | null;
support: string[];
}

export interface IRoomVersionsCapability {
default: string;
available: Record<string, RoomVersionStability>;
"org.matrix.msc3244.room_capabilities"?: Record<string, IRoomCapability>; // MSC3244
}

export interface IChangePasswordCapability {
Expand Down Expand Up @@ -404,6 +410,10 @@ export interface ISignedKey {
algorithms: string[];
device_id: string;
}

export interface IEventIdResponse {
event_id: string;
}
/* eslint-enable camelcase */

export type KeySignatures = Record<string, Record<string, ICrossSigningKey | ISignedKey>>;
Expand Down Expand Up @@ -2991,7 +3001,7 @@ export class MatrixClient extends EventEmitter {
* @return {Promise} Resolves: TODO
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
public setRoomName(roomId: string, name: string, callback?: Callback): Promise<void> {
public setRoomName(roomId: string, name: string, callback?: Callback): Promise<IEventIdResponse> {
return this.sendStateEvent(roomId, "m.room.name", { name: name }, undefined, callback);
}

Expand All @@ -3002,7 +3012,7 @@ export class MatrixClient extends EventEmitter {
* @return {Promise} Resolves: TODO
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
public setRoomTopic(roomId: string, topic: string, callback?: Callback): Promise<void> {
public setRoomTopic(roomId: string, topic: string, callback?: Callback): Promise<IEventIdResponse> {
return this.sendStateEvent(roomId, "m.room.topic", { topic: topic }, undefined, callback);
}

Expand Down Expand Up @@ -4186,7 +4196,7 @@ export class MatrixClient extends EventEmitter {
*/
public _unstable_setStatusMessage(newMessage: string): Promise<void> { // eslint-disable-line camelcase
const type = "im.vector.user_status";
return Promise.all(this.getRooms().map((room) => {
return Promise.all(this.getRooms().map((room): Promise<any> => {
const isJoined = room.getMyMembership() === "join";
const looksLikeDm = room.getInvitedAndJoinedMemberCount() === 2;
if (!isJoined || !looksLikeDm) {
Expand Down Expand Up @@ -4674,7 +4684,7 @@ export class MatrixClient extends EventEmitter {
guest_access: opts.allowJoin ? "can_join" : "forbidden",
}, "");

let readPromise = Promise.resolve();
let readPromise = Promise.resolve<any>(undefined);
if (opts.allowRead) {
readPromise = this.sendStateEvent(roomId, "m.room.history_visibility", {
history_visibility: "world_readable",
Expand Down Expand Up @@ -6342,7 +6352,7 @@ export class MatrixClient extends EventEmitter {
content: any,
stateKey = "",
callback?: Callback,
): Promise<any> { // TODO: Types
): Promise<IEventIdResponse> {
const pathParams = {
$roomId: roomId,
$eventType: eventType,
Expand Down
4 changes: 2 additions & 2 deletions src/models/MSC3089Branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export class MSC3089Branch {
* @param {string} name The new name for this file.
* @returns {Promise<void>} Resolves when complete.
*/
public setName(name: string): Promise<void> {
return this.client.sendStateEvent(this.roomId, UNSTABLE_MSC3089_BRANCH.name, {
public async setName(name: string): Promise<void> {
await this.client.sendStateEvent(this.roomId, UNSTABLE_MSC3089_BRANCH.name, {
...this.indexEvent.getContent(),
name: name,
}, this.id);
Expand Down
6 changes: 3 additions & 3 deletions src/models/MSC3089TreeSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export class MSC3089TreeSpace {
* @param {string} name The new name for the space.
* @returns {Promise<void>} Resolves when complete.
*/
public setName(name: string): Promise<void> {
return this.client.sendStateEvent(this.roomId, EventType.RoomName, { name }, "");
public async setName(name: string): Promise<void> {
await this.client.sendStateEvent(this.roomId, EventType.RoomName, { name }, "");
}

/**
Expand Down Expand Up @@ -190,7 +190,7 @@ export class MSC3089TreeSpace {
}
pls['users'] = users;

return this.client.sendStateEvent(this.roomId, EventType.RoomPowerLevels, pls, "");
await this.client.sendStateEvent(this.roomId, EventType.RoomPowerLevels, pls, "");
}

/**
Expand Down