mirror of
https://git.sr.ht/~emerson/reflectionircd
synced 2025-04-13 09:59:52 +00:00
fix initial channel syncing
This commit is contained in:
parent
038d04ad96
commit
e0c19d55fc
1 changed files with 21 additions and 11 deletions
|
@ -36,27 +36,31 @@ export class Channel {
|
||||||
|
|
||||||
doInitialSync() {
|
doInitialSync() {
|
||||||
this.syncLocks.add("m.room.canonical_alias");
|
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 => {
|
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["content"]?.["alias"];
|
const canonical_alias = response.data["alias"];
|
||||||
if (canonical_alias) {
|
if (canonical_alias) {
|
||||||
this.name = canonical_alias;
|
this.name = canonical_alias;
|
||||||
}
|
}
|
||||||
this.syncLocks.delete("m.room.canonical_alias")
|
this.syncLocks.delete("m.room.canonical_alias")
|
||||||
}).catch(e => {
|
}).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.delete("m.room.canonical_alias")
|
||||||
})
|
})
|
||||||
this.syncLocks.add("m.room.topic");
|
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")
|
this.syncLocks.delete("m.room.topic")
|
||||||
const topicText = response.data["content"]?.["topic"];
|
const topicText = response.data["topic"];
|
||||||
if (!topicText)
|
if (!topicText || this.topic.get("text") !== "")
|
||||||
return;
|
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("text", topicText);
|
||||||
this.topic.set("timestamp", topicTS.substring(0,10))
|
this.topic.set("timestamp", Date.now().toString(10).substring(0, 10));
|
||||||
this.topic.set('setter', topicSetter.nick);
|
this.topic.set('setter', "matrix");
|
||||||
}).catch(e => {
|
}).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.delete("m.room.topic")
|
||||||
})
|
})
|
||||||
this.syncLocks.add("m.room.members");
|
this.syncLocks.add("m.room.members");
|
||||||
|
@ -68,12 +72,15 @@ export class Channel {
|
||||||
}
|
}
|
||||||
this.syncLocks.delete("m.room.members")
|
this.syncLocks.delete("m.room.members")
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
|
const errcode = e.response?.data?.errcode;
|
||||||
|
if (errcode !== "M_NOT_FOUND")
|
||||||
|
console.log(e);
|
||||||
this.syncLocks.delete("m.room.members")
|
this.syncLocks.delete("m.room.members")
|
||||||
})
|
})
|
||||||
this.syncLocks.add("m.room.power_levels")
|
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")
|
this.syncLocks.delete("m.room.power_levels")
|
||||||
const users = response.data["content"]?.["users"];
|
const users = response.data["users"];
|
||||||
if (!users)
|
if (!users)
|
||||||
return;
|
return;
|
||||||
for (const [mxid, pl] of Object.entries(users)) {
|
for (const [mxid, pl] of Object.entries(users)) {
|
||||||
|
@ -84,6 +91,9 @@ export class Channel {
|
||||||
this.powerLevels.set(nextMatrixUser.nick, numPl);
|
this.powerLevels.set(nextMatrixUser.nick, numPl);
|
||||||
}
|
}
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
|
const errcode = e.response?.data?.errcode;
|
||||||
|
if (errcode !== "M_NOT_FOUND")
|
||||||
|
console.log(e);
|
||||||
this.syncLocks.delete("m.room.power_levels")
|
this.syncLocks.delete("m.room.power_levels")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue