room name, refactor

This commit is contained in:
tezlm 2022-05-20 12:42:24 -07:00
parent ac45490297
commit 61bd179cec

View file

@ -65,6 +65,10 @@ class Room {
return this._client.getRoom(this.id).currentState; return this._client.getRoom(this.id).currentState;
} }
get name() {
return this._client.getRoom(this.id).name;
}
send(content) { send(content) {
return this._client.sendMessage(this.id, null, { return this._client.sendMessage(this.id, null, {
body: content, body: content,
@ -78,18 +82,18 @@ class Room {
join() { join() {
return this._client.joinRoom(this.id); return this._client.joinRoom(this.id);
} }
setName(name) {
return this._client.setRoomName(this.id, name);
}
} }
class Message { class Event {
constructor(client, event) { constructor(client, event) {
this._client = client; this._client = client;
this._event = event; this._event = event;
} }
get content() {
return this._event.getContent().body;
}
get id() { get id() {
return this._event.getId(); return this._event.getId();
} }
@ -101,9 +105,18 @@ class Message {
get author() { get author() {
return new Member(this._client, this._event.getSender(), this._event.getRoomId()); return new Member(this._client, this._event.getSender(), this._event.getRoomId());
} }
}
class Message extends Event {
constructor(client, event) {
super(client, event);
}
get content() {
return this._event.getContent().body;
}
redact() { redact() {
console.log("redacting event..");
return this._client.redactEvent(this.room.id, this.id); return this._client.redactEvent(this.room.id, this.id);
} }
@ -113,6 +126,10 @@ class Message {
"m.relates_to": { "m.in_reply_to": { event_id: this.id } }, "m.relates_to": { "m.in_reply_to": { event_id: this.id } },
}); });
} }
relations() {
return this._client.fetchRelations(this.room.id, this.id);
}
} }
class Bot extends EventEmitter { class Bot extends EventEmitter {
@ -146,6 +163,16 @@ class Bot extends EventEmitter {
return this._client.getUserId(); return this._client.getUserId();
} }
getRooms() {
return this._client
.getRooms()
.map(room => new Room(this._client, room.roomId));
}
getRoom(id) {
return new Room(this._client, id));
}
async start() { async start() {
this._client.once("sync", (state) => { this._client.once("sync", (state) => {
if(state === 'PREPARED') { if(state === 'PREPARED') {