mirror of
https://git.sr.ht/~emerson/reflectionircd
synced 2025-04-13 09:59:52 +00:00
Differentiate between channels and rooms, get ready to have good channel names
This commit is contained in:
parent
e83c782284
commit
31a869f04b
4 changed files with 19 additions and 30 deletions
|
@ -8,8 +8,8 @@ import axios from "axios";
|
||||||
|
|
||||||
export class Channel {
|
export class Channel {
|
||||||
public name: string
|
public name: string
|
||||||
private matrixUsers: Map<string, MatrixUser>
|
public matrixUsers: Map<string, MatrixUser>
|
||||||
private ircUsers: Map<string, IRCUser>
|
public ircUsers: Map<string, IRCUser>
|
||||||
private powerLevels: Map<string, number>
|
private powerLevels: Map<string, number>
|
||||||
private topic: Map<string, string>;
|
private topic: Map<string, string>;
|
||||||
private eventIDsSeen: Set<string>;
|
private eventIDsSeen: Set<string>;
|
||||||
|
@ -23,9 +23,9 @@ export class Channel {
|
||||||
this.powerLevels = new Map();
|
this.powerLevels = new Map();
|
||||||
this.topic = new Map([['text', ''], ['timestamp', '0'], ['setter', 'matrix']]);
|
this.topic = new Map([['text', ''], ['timestamp', '0'], ['setter', 'matrix']]);
|
||||||
this.eventIDsSeen = new Set();
|
this.eventIDsSeen = new Set();
|
||||||
this.historyVisibility = "shared";
|
this.historyVisibility = "";
|
||||||
this.guestAccess = "forbidden";
|
this.guestAccess = "";
|
||||||
this.joinRules = "public";
|
this.joinRules = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
getNickPowerLevelMapping(nick: string): string {
|
getNickPowerLevelMapping(nick: string): string {
|
||||||
|
|
|
@ -60,23 +60,15 @@ export class Client {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'MODE': {
|
case 'MODE': {
|
||||||
if (!this.user) {
|
const targetChannel = this.server.ircChannels.get(message.params[0]);
|
||||||
return;
|
if (this.user && targetChannel && targetChannel.ircUsers.get(this.user.nick))
|
||||||
}
|
targetChannel.sendMode(this, message.tags);
|
||||||
const maybeChannel = this.user.channels.get(message.params[0]);
|
|
||||||
if (maybeChannel) {
|
|
||||||
maybeChannel.sendMode(this, message.tags);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'NAMES': {
|
case 'NAMES': {
|
||||||
if (!this.user) {
|
const targetChannel = this.server.ircChannels.get(message.params[0]);
|
||||||
return;
|
if (this.user && targetChannel && targetChannel.ircUsers.get(this.user.nick))
|
||||||
}
|
targetChannel.sendNames(this, message.tags);
|
||||||
const maybeChannel = this.user.channels.get(message.params[0]);
|
|
||||||
if (maybeChannel) {
|
|
||||||
maybeChannel.sendNames(this, message.tags);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'NOTICE': {
|
case 'NOTICE': {
|
||||||
|
@ -96,13 +88,9 @@ export class Client {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'WHO': {
|
case 'WHO': {
|
||||||
if (!this.user) {
|
const targetChannel = this.server.ircChannels.get(message.params[0]);
|
||||||
return;
|
if (this.user && targetChannel && targetChannel.ircUsers.get(this.user.nick))
|
||||||
}
|
targetChannel.sendWho(this, message.tags);
|
||||||
const maybeChannel = this.user.channels.get(message.params[0]);
|
|
||||||
if (maybeChannel) {
|
|
||||||
maybeChannel.sendWho(this, message.tags);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +188,7 @@ export class Client {
|
||||||
if (rooms['join']) {
|
if (rooms['join']) {
|
||||||
for (const roomId of Object.keys(rooms.join)) {
|
for (const roomId of Object.keys(rooms.join)) {
|
||||||
const targetChannel = this.server.getOrCreateIRCChannel(roomId);
|
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));
|
rooms.join[roomId].state.events.forEach((nextEvent: any) => targetChannel.routeMatrixEvent(nextEvent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { Server } from "./Server.js";
|
||||||
|
|
||||||
export class IRCUser {
|
export class IRCUser {
|
||||||
private clients: Set<Client>
|
private clients: Set<Client>
|
||||||
public channels: Map<string, Channel>
|
public channels: Set<Channel>
|
||||||
public nick: string
|
public nick: string
|
||||||
private ident: string
|
private ident: string
|
||||||
private hostname: string
|
private hostname: string
|
||||||
|
@ -19,7 +19,7 @@ export class IRCUser {
|
||||||
private syncIntervalID: NodeJS.Timeout;
|
private syncIntervalID: NodeJS.Timeout;
|
||||||
constructor(public mxid: string, private accessToken: string, private server: Server) {
|
constructor(public mxid: string, private accessToken: string, private server: Server) {
|
||||||
this.clients = new Set();
|
this.clients = new Set();
|
||||||
this.channels = new Map();
|
this.channels = new Set();
|
||||||
const mxidSplit = mxid.split(':')
|
const mxidSplit = mxid.split(':')
|
||||||
this.nick = mxidSplit[0].substr(1);
|
this.nick = mxidSplit[0].substr(1);
|
||||||
this.ident = this.nick;
|
this.ident = this.nick;
|
||||||
|
@ -75,7 +75,7 @@ export class IRCUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessageToMatrix(message: IRCMessage, client: Client) {
|
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) {
|
if (!channel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ export class Server {
|
||||||
|
|
||||||
const newChannel = new Channel(roomId, this);
|
const newChannel = new Channel(roomId, this);
|
||||||
this.matrixRooms.set(roomId, newChannel);
|
this.matrixRooms.set(roomId, newChannel);
|
||||||
|
this.ircChannels.set(roomId, newChannel);
|
||||||
return newChannel;
|
return newChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue