Differentiate between channels and rooms, get ready to have good channel names

This commit is contained in:
emerson 2021-12-07 14:22:18 -05:00
parent e83c782284
commit 31a869f04b
No known key found for this signature in database
GPG key ID: 270669502DA603E3
4 changed files with 19 additions and 30 deletions

View file

@ -8,8 +8,8 @@ import axios from "axios";
export class Channel {
public name: string
private matrixUsers: Map<string, MatrixUser>
private ircUsers: Map<string, IRCUser>
public matrixUsers: Map<string, MatrixUser>
public ircUsers: Map<string, IRCUser>
private powerLevels: Map<string, number>
private topic: Map<string, string>;
private eventIDsSeen: Set<string>;
@ -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 {

View file

@ -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));
}
}

View file

@ -7,7 +7,7 @@ import { Server } from "./Server.js";
export class IRCUser {
private clients: Set<Client>
public channels: Map<string, Channel>
public channels: Set<Channel>
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;
}

View file

@ -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;
}