Room joins and leaves

This commit is contained in:
tezlm 2023-12-05 21:37:39 -08:00
parent 55cda4d4ae
commit b4f27d76b0
Signed by: tezlm
GPG key ID: 649733FCD94AFBBA
18 changed files with 101 additions and 34 deletions

11
dist/src/api.d.ts vendored
View file

@ -26,16 +26,7 @@ export type ApiEphemeralEvent = {
};
type Query = {
required_state?: Array<[string, string]>;
timeline?: {
limit?: number;
types?: Array<string>;
not_types?: Array<string>;
};
ephemeral?: {
limit?: number;
types?: Array<string>;
include_old?: boolean;
};
timeline_limit?: number;
};
export type RoomSubscription = Query;
export type ListSubscription = Query & {

View file

@ -47,6 +47,7 @@ declare class Rooms extends Map<string, Room> {
client: Client;
constructor(client: Client);
create(options: CreateRoom): Promise<unknown>;
join(roomIdOrAlias: RoomId | string, reason?: string): Promise<unknown>;
subscribe(roomId: RoomId, subscription: RoomSubscription): void;
unsubscribe(roomId: RoomId): void;
}

3
dist/src/client.js vendored
View file

@ -23,6 +23,9 @@ class Rooms extends Map {
creation_content: options.creationContent,
});
}
async join(roomIdOrAlias, reason) {
return this.client.net.joinRoom(roomIdOrAlias, reason);
}
subscribe(roomId, subscription) {
this.client.conn.roomSubscribe(roomId, subscription);
}

View file

@ -1 +1 @@
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAG7D,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,YAAY,MAAM,QAAQ,CAAC;AAqDlC,MAAM,KAAM,SAAQ,GAAiB;IACnC,YAAmB,MAAc;QAC/B,KAAK,EAAE,CAAC;QADE;;;;mBAAO,MAAM;WAAQ;IAEjC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAmB;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;YAChC,YAAY,EAAE,OAAO,CAAC,OAAO;YAC7B,aAAa,EA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oBACH,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACzB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;gBACjD,CAAC;YACH,CAAC;QACH,CAAC,CAAC,EAAE,CAAA;IACN,CAAC;IAED,oCAAoC;IACpC,IAAI;QACF,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IACnC,CAAC;CACF"}

2
dist/src/net.d.ts vendored
View file

@ -11,6 +11,8 @@ export declare class Network {
private fetch;
sync(options: t.SyncRequest, signal: AbortSignal): Promise<t.SyncResponse>;
createRoom(options: t.CreateRoomRequest): Promise<t.CreateRoomResponse>;
leaveRoom(roomId: t.RoomId, reason?: string): Promise<void>;
joinRoom(roomIdOrAlias: t.RoomId | string, reason?: string): Promise<void>;
fetchEvent(roomId: t.RoomId, eventId: t.EventId): Promise<t.ApiEvent>;
fetchContext(roomId: t.RoomId, eventId: t.EventId, limit?: number): Promise<t.ContextResponse>;
fetchMessages(opts: {

14
dist/src/net.js vendored
View file

@ -64,6 +64,20 @@ export class Network {
body: options,
});
}
async leaveRoom(roomId, reason) {
return this.fetch({
method: "POST",
path: `/_matrix/client/v3/rooms/${e(roomId)}/leave`,
body: { reason },
});
}
async joinRoom(roomIdOrAlias, reason) {
return this.fetch({
method: "POST",
path: `/_matrix/client/v3/join/${e(roomIdOrAlias)}`,
body: { reason },
});
}
async fetchEvent(roomId, eventId) {
return this.fetch({
method: "GET",

2
dist/src/net.js.map vendored

File diff suppressed because one or more lines are too long

1
dist/src/room.d.ts vendored
View file

@ -26,5 +26,6 @@ export declare class Room extends Room_base {
getAllState(type: string): Array<StateEvent>;
sendState(type: string, stateKey: string, content: any): Promise<void>;
sendEvent(type: string, content: any): Promise<void>;
leave(reason?: string): Promise<void>;
}
export {};

17
dist/src/room.js vendored
View file

@ -3,6 +3,20 @@ import { Event, StateEvent } from "./event.js";
import { TimelineSet } from "./timeline.js";
import { nanoid } from "nanoid";
export class Room extends EventEmitter {
// public members: Members;
/*
// There isn't really one "canonical" Member, but rather bits of data
// relating to users. Having a Member class as a "view" aggregating that
// data may be useful, but may be a bit wonky
class Member {
async ban() {}
async kick() {}
async unban() {} // won't work?
}
room.ban(who: UserId | Member)
room.unban(userid)
*/
constructor(client, id, data) {
super();
Object.defineProperty(this, "client", {
@ -66,5 +80,8 @@ export class Room extends EventEmitter {
async sendEvent(type, content) {
await this.client.net.sendEvent(this.id, type, nanoid(), content);
}
async leave(reason) {
await this.client.net.leaveRoom(this.id, reason);
}
}
//# sourceMappingURL=room.js.map

View file

@ -1 +1 @@
{"version":3,"file":"room.js","sourceRoot":"","sources":["../../src/room.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAIlC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAsBhC,MAAM,OAAO,IAAK,SAAS,YAA8D;IAMvF,YACS,MAAc,EACd,EAAU,EACjB,IAAsB;QAEtB,KAAK,EAAE,CAAC;QAJR;;;;mBAAO,MAAM;WAAQ;QACrB;;;;mBAAO,EAAE;WAAQ;QAPnB,+CAA+C;QACvC;;;;mBAA8C,IAAI,GAAG,EAAE;WAAC;QAEzD;;;;;WAAuB;QAQ5B,IAAI,CAAC,SAAS,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,U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EAAE,QAAgB,EAAE,OAAY;QAC1D,0FAA0F;QAC1F,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;IAED,qBAAqB;IACrB,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,OAAY;QACxC,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,MAAe;QACzB,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;CACF"}

3
dist/src/sync.js vendored
View file

@ -56,7 +56,6 @@ export class Connection {
});
if (!json)
return;
console.log(json);
this.stripSticky();
this.pos = json.pos;
this.delta = json.delta_token;
@ -108,7 +107,7 @@ export class Connection {
}
}
// query.queries = {};
query.rooms = {};
delete query.rooms;
}
listSubscribe(name, subscription) {
if (!this.query.lists)

View file

@ -1 +1 @@
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/sync.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,6DAA6D;AAG7D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,OAAO,UAAU;IAOrB,YAAoB,MAAc;QAAtB;;;;mBAAQ,MAAM;WAAQ;QAN1B;;;;mBAAS,MAAM,EAAE;WAAC;QAClB;;;;mBAAa,IAAI,eAAe,EAAE;WAAC;QACnC;;;;mBAAc,GAAG;WAAC;QAClB;;;;;WAA0B;QAC1B;;;;mBAAqB,EAAE;WAAC;IAEK,CAAC;IAEtC,gBAAgB;IAChB,KAAK,CA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,YAAY,CAAC;QACtC,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,eAAe,CAAC,IAAY;QAC1B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;YAAE,OAAO;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,aAAa,CAAC,MAAc,EAAE,YAA8B;QAC1D,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC;QACxC,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,eAAe,CAAC,MAAc;QAC5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;QAChC,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,MAAe;QACnB,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;CACF"}

File diff suppressed because one or more lines are too long

View file

@ -33,22 +33,23 @@ export type ApiEphemeralEvent = {
type Query = {
required_state?: Array<[string, string]>,
timeline?: {
limit?: number,
types?: Array<string>,
not_types?: Array<string>,
timeline_limit?: number,
// timeline?: {
// limit?: number,
// types?: Array<string>,
// not_types?: Array<string>,
// theoretically, the best option would be to hide m.reaction events
// in the historical timeline while showing them in the live timeline
// i'd need to implement proper filtering for that though
// live_filter?: string,
// historical_filter?: string,
},
ephemeral?: {
limit?: number,
types?: Array<string>,
include_old?: boolean, // include temporarily persisted events replaced with the same key
},
// // theoretically, the best option would be to hide m.reaction events
// // in the historical timeline while showing them in the live timeline
// // i'd need to implement proper filtering for that though
// // live_filter?: string,
// // historical_filter?: string,
// },
// ephemeral?: {
// limit?: number,
// types?: Array<string>,
// include_old?: boolean, // include temporarily persisted events replaced with the same key
// },
};
// export type RoomSubscription = {

View file

@ -74,6 +74,10 @@ class Rooms extends Map<string, Room> {
});
}
async join(roomIdOrAlias: RoomId | string, reason?: string): Promise<unknown> {
return this.client.net.joinRoom(roomIdOrAlias, reason);
}
subscribe(roomId: RoomId, subscription: RoomSubscription) {
this.client.conn.roomSubscribe(roomId, subscription);
}

View file

@ -72,6 +72,22 @@ export class Network {
});
}
public async leaveRoom(roomId: t.RoomId, reason?: string): Promise<void> {
return this.fetch({
method: "POST",
path: `/_matrix/client/v3/rooms/${e(roomId)}/leave`,
body: { reason },
});
}
public async joinRoom(roomIdOrAlias: t.RoomId | string, reason?: string): Promise<void> {
return this.fetch({
method: "POST",
path: `/_matrix/client/v3/join/${e(roomIdOrAlias)}`,
body: { reason },
});
}
public async fetchEvent(roomId: t.RoomId, eventId: t.EventId): Promise<t.ApiEvent> {
return this.fetch({
method: "GET",

View file

@ -31,6 +31,21 @@ export class Room extends (EventEmitter as unknown as new () => TypedEmitter<Roo
private state: Map<string, Map<string, StateEvent>> = new Map();
public timelines: TimelineSet;
// public members: Members;
/*
// There isn't really one "canonical" Member, but rather bits of data
// relating to users. Having a Member class as a "view" aggregating that
// data may be useful, but may be a bit wonky
class Member {
async ban() {}
async kick() {}
async unban() {} // won't work?
}
room.ban(who: UserId | Member)
room.unban(userid)
*/
constructor(
public client: Client,
@ -78,4 +93,8 @@ export class Room extends (EventEmitter as unknown as new () => TypedEmitter<Roo
async sendEvent(type: string, content: any) {
await this.client.net.sendEvent(this.id, type, nanoid(), content);
}
async leave(reason?: string) {
await this.client.net.leaveRoom(this.id, reason);
}
}

View file

@ -28,7 +28,6 @@ export class Connection {
throw reason;
});
if (!json) return;
console.log(json)
this.stripSticky();
this.pos = json.pos;
@ -90,7 +89,7 @@ export class Connection {
}
// query.queries = {};
query.rooms = {};
delete query.rooms;
}
listSubscribe(name: string, subscription: ListSubscription) {