diff --git a/src/Channel.ts b/src/Channel.ts index 6a6658c..c1f0755 100644 --- a/src/Channel.ts +++ b/src/Channel.ts @@ -8,8 +8,8 @@ import axios from "axios"; export class Channel { public name: string - private matrixUsers: Map - private ircUsers: Map + public matrixUsers: Map + public ircUsers: Map private powerLevels: Map private topic: Map; private eventIDsSeen: Set; @@ -23,9 +23,9 @@ export class Channel { this.powerLevels = new Map(); this.topic = new Map([['text', ''], ['timestamp', '0'], ['setter', 'matrix']]); this.eventIDsSeen = new Set(); - this.historyVisibility = "shared"; - this.guestAccess = "forbidden"; - this.joinRules = "public"; + this.historyVisibility = ""; + this.guestAccess = ""; + this.joinRules = ""; } getNickPowerLevelMapping(nick: string): string { diff --git a/src/Client.ts b/src/Client.ts index 44d7d66..6d03c8c 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -60,23 +60,15 @@ export class Client { break; } case 'MODE': { - if (!this.user) { - return; - } - const maybeChannel = this.user.channels.get(message.params[0]); - if (maybeChannel) { - maybeChannel.sendMode(this, message.tags); - } + const targetChannel = this.server.ircChannels.get(message.params[0]); + if (this.user && targetChannel && targetChannel.ircUsers.get(this.user.nick)) + targetChannel.sendMode(this, message.tags); break; } case 'NAMES': { - if (!this.user) { - return; - } - const maybeChannel = this.user.channels.get(message.params[0]); - if (maybeChannel) { - maybeChannel.sendNames(this, message.tags); - } + const targetChannel = this.server.ircChannels.get(message.params[0]); + if (this.user && targetChannel && targetChannel.ircUsers.get(this.user.nick)) + targetChannel.sendNames(this, message.tags); break; } case 'NOTICE': { @@ -96,13 +88,9 @@ export class Client { break; } case 'WHO': { - if (!this.user) { - return; - } - const maybeChannel = this.user.channels.get(message.params[0]); - if (maybeChannel) { - maybeChannel.sendWho(this, message.tags); - } + const targetChannel = this.server.ircChannels.get(message.params[0]); + if (this.user && targetChannel && targetChannel.ircUsers.get(this.user.nick)) + targetChannel.sendWho(this, message.tags); break; } } @@ -200,7 +188,7 @@ export class Client { if (rooms['join']) { for (const roomId of Object.keys(rooms.join)) { const targetChannel = this.server.getOrCreateIRCChannel(roomId); - this.user.channels.set(targetChannel.name, targetChannel); + this.user.channels.add(targetChannel); rooms.join[roomId].state.events.forEach((nextEvent: any) => targetChannel.routeMatrixEvent(nextEvent)); } } diff --git a/src/IRCUser.ts b/src/IRCUser.ts index e23a9b7..03f5ef3 100644 --- a/src/IRCUser.ts +++ b/src/IRCUser.ts @@ -7,7 +7,7 @@ import { Server } from "./Server.js"; export class IRCUser { private clients: Set - public channels: Map + public channels: Set public nick: string private ident: string private hostname: string @@ -19,7 +19,7 @@ export class IRCUser { private syncIntervalID: NodeJS.Timeout; constructor(public mxid: string, private accessToken: string, private server: Server) { this.clients = new Set(); - this.channels = new Map(); + this.channels = new Set(); const mxidSplit = mxid.split(':') this.nick = mxidSplit[0].substr(1); this.ident = this.nick; @@ -75,7 +75,7 @@ export class IRCUser { } sendMessageToMatrix(message: IRCMessage, client: Client) { - const channel = this.server.matrixRooms.get(message.params[0]); + const channel = this.server.ircChannels.get(message.params[0]); if (!channel) { return; } diff --git a/src/Server.ts b/src/Server.ts index e7555d1..f56cba3 100644 --- a/src/Server.ts +++ b/src/Server.ts @@ -37,6 +37,7 @@ export class Server { const newChannel = new Channel(roomId, this); this.matrixRooms.set(roomId, newChannel); + this.ircChannels.set(roomId, newChannel); return newChannel; }