diff --git a/src/Channel.ts b/src/Channel.ts index 863c9f5..51ab8cf 100644 --- a/src/Channel.ts +++ b/src/Channel.ts @@ -36,27 +36,31 @@ export class Channel { doInitialSync() { this.syncLocks.add("m.room.canonical_alias"); - axios.get(`https://${this.ircUser.homeserver}/_matrix/client/v3/rooms/${this.roomId}/event/m.room.canonical_alias?access_token=${this.ircUser.accessToken}`).then(response => { - const canonical_alias = response.data["content"]?.["alias"]; + axios.get(`https://${this.ircUser.homeserver}/_matrix/client/v3/rooms/${this.roomId}/state/m.room.canonical_alias?access_token=${this.ircUser.accessToken}`).then(response => { + const canonical_alias = response.data["alias"]; if (canonical_alias) { this.name = canonical_alias; } this.syncLocks.delete("m.room.canonical_alias") }).catch(e => { + const errcode = e.response?.data?.errcode; + if (errcode !== "M_NOT_FOUND") + console.log(e); this.syncLocks.delete("m.room.canonical_alias") }) this.syncLocks.add("m.room.topic"); - axios.get(`https://${this.ircUser.homeserver}/_matrix/client/v3/rooms/${this.roomId}/event/m.room.topic?access_token=${this.ircUser.accessToken}`).then(response => { + axios.get(`https://${this.ircUser.homeserver}/_matrix/client/v3/rooms/${this.roomId}/state/m.room.topic?access_token=${this.ircUser.accessToken}`).then(response => { this.syncLocks.delete("m.room.topic") - const topicText = response.data["content"]?.["topic"]; - if (!topicText) + const topicText = response.data["topic"]; + if (!topicText || this.topic.get("text") !== "") return; - const topicSetter = this.ircUser.getOrCreateMatrixUser(response.data["sender"]); - const topicTS: string = response.data["origin_server_ts"].toString(); this.topic.set("text", topicText); - this.topic.set("timestamp", topicTS.substring(0,10)) - this.topic.set('setter', topicSetter.nick); + this.topic.set("timestamp", Date.now().toString(10).substring(0, 10)); + this.topic.set('setter', "matrix"); }).catch(e => { + const errcode = e.response?.data?.errcode; + if (errcode !== "M_NOT_FOUND") + console.log(this.roomId, e); this.syncLocks.delete("m.room.topic") }) this.syncLocks.add("m.room.members"); @@ -68,12 +72,15 @@ export class Channel { } this.syncLocks.delete("m.room.members") }).catch(e => { + const errcode = e.response?.data?.errcode; + if (errcode !== "M_NOT_FOUND") + console.log(e); this.syncLocks.delete("m.room.members") }) this.syncLocks.add("m.room.power_levels") - axios.get(`https://${this.ircUser.homeserver}/_matrix/client/v3/rooms/${this.roomId}/event/m.room.power_levels?access_token=${this.ircUser.accessToken}`).then(response => { + axios.get(`https://${this.ircUser.homeserver}/_matrix/client/v3/rooms/${this.roomId}/state/m.room.power_levels?access_token=${this.ircUser.accessToken}`).then(response => { this.syncLocks.delete("m.room.power_levels") - const users = response.data["content"]?.["users"]; + const users = response.data["users"]; if (!users) return; for (const [mxid, pl] of Object.entries(users)) { @@ -84,6 +91,9 @@ export class Channel { this.powerLevels.set(nextMatrixUser.nick, numPl); } }).catch(e => { + const errcode = e.response?.data?.errcode; + if (errcode !== "M_NOT_FOUND") + console.log(e); this.syncLocks.delete("m.room.power_levels") }) }