diff --git a/src/Channel.ts b/src/Channel.ts index 5caa4eb..6a6658c 100644 --- a/src/Channel.ts +++ b/src/Channel.ts @@ -12,17 +12,20 @@ export class Channel { private ircUsers: Map private powerLevels: Map private topic: Map; - private modes: Map private eventIDsSeen: Set; + private historyVisibility: string + private guestAccess: string + private joinRules: string constructor(public roomId: string, private server: Server) { this.name = roomId; this.matrixUsers = new Map(); this.ircUsers = new Map(); this.powerLevels = new Map(); this.topic = new Map([['text', ''], ['timestamp', '0'], ['setter', 'matrix']]); - this.modes = new Map(); - this.modes.set('n', ''); this.eventIDsSeen = new Set(); + this.historyVisibility = "shared"; + this.guestAccess = "forbidden"; + this.joinRules = "public"; } getNickPowerLevelMapping(nick: string): string { @@ -82,11 +85,7 @@ export class Channel { sendMode(client: Client, passedTags: Map) { if (!client.user) return; - const chanModes = []; - for (let m of this.modes.keys()) { - chanModes.push(m); - } - client.sendMessage(client.server.name, "324", numerics["324"](client.user.nick, this.name, `+${chanModes.join("")}`), passedTags); + client.sendMessage(client.server.name, "324", numerics["324"](client.user.nick, this.name, `+n`), passedTags); } sendTopic(client: Client, passedTags: Map) { @@ -127,6 +126,12 @@ export class Channel { return; switch (event["type"]) { + case 'm.room.guest_access': + this.handleMatrixGuestAccess(event); + break; + case 'm.room.history_visibility': + this.handleMatrixHistoryVisibility(event); + break; case 'm.room.join_rules': this.handleMatrixJoinRule(event); break; @@ -161,6 +166,9 @@ export class Channel { case 'm.room.bot.options': case 'm.room.pinned_events': case 'm.room.tombstone': + case 'm.room.canonical_alias': + case 'm.room.server_acl': + case 'org.matrix.room.preview_urls': break; default: console.log(event["type"]); @@ -307,20 +315,24 @@ export class Channel { console.log(`Warning: join rule not found in ${event}`); return; } - if (rule === "public") { - if (this.modes.has('i')) { - this.modes.delete('i'); - this.ircUsers.forEach((user) => { - user.sendToAll(this.server.name, 'MODE', [this.name, '-i'], new Map()); - }); - } - } else { - if (!this.modes.has('i')) { - this.modes.set('i', ''); - this.ircUsers.forEach((user) => { - user.sendToAll(this.server.name, 'MODE', [this.name, '+i'], new Map()); - }); - } + this.joinRules = rule; + } + + handleMatrixHistoryVisibility(event: any) { + const rule = event["content"]?.["history_visibility"]; + if (!rule) { + console.log(`Warning: history visibility not found in ${event}`); + return; } + this.historyVisibility = rule; + } + + handleMatrixGuestAccess(event: any) { + const rule = event["content"]?.["guest_access"]; + if (!rule) { + console.log(`Warning: Guest access not found in ${event}`); + return; + } + this.guestAccess = rule; } } \ No newline at end of file