reflectionircd/src/Channel.ts

56 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-12-05 18:33:49 -05:00
import { Server } from "./Server.js";
import { MatrixUser } from "./MatrixUser.js";
import { IRCUser } from "./IRCUser.js";
import { IRCMessage } from "./Message.js";
export class Channel {
private server: Server
2021-12-05 18:33:49 -05:00
public name: string
private matrixUsers: Map<string, MatrixUser>
private ircUsers: Map<string, IRCUser>
private nickToMXid: Map<string, string>
private powerLevels: Map<string, number>
private topic: Map<string, string>;
private modes: Map<string, string>
private messages: Map<string, IRCMessage>;
private tsToEventId: Map<number, string>;
constructor(public roomId: string, initialIRCUser: IRCUser) {
this.server = initialIRCUser.server
2021-12-05 18:33:49 -05:00
this.name = roomId;
this.matrixUsers = new Map();
this.ircUsers = new Map();
this.ircUsers.set(initialIRCUser.nick, initialIRCUser);
this.nickToMXid = new Map();
this.powerLevels = new Map();
this.topic = new Map([['text', ''], ['timestamp', '0']]);
2021-12-05 18:33:49 -05:00
this.modes = new Map();
this.modes.set('n', '');
this.messages = new Map();
this.tsToEventId = new Map();
}
handleMatrixEvent(event: any) {
if (!event["type"])
return;
if (event["type"] === "m.room.member") {
const thisMatrixUser = this.server.getOrCreateMatrixUser(event["sender"]);
this.matrixUsers.set(thisMatrixUser.nick, thisMatrixUser);
}
else if (event["type"] === "m.room.topic") {
this.topic.set("text", event["content"]["topic"]);
this.topic.set("timestamp", event["origin_server_ts"].toString())
}
else if (event["type"] === "m.room.power_levels") {
const allUsers = event["content"]["users"];
for (const [mxid, pl] of Object.entries(allUsers)) {
const thisMatrixUser = this.server.getOrCreateMatrixUser(event["sender"]);
this.matrixUsers.set(thisMatrixUser.nick, thisMatrixUser);
this.powerLevels.set(thisMatrixUser.nick, Number(pl));
}
}
else {
console.log(event);
}
}
2021-12-05 18:33:49 -05:00
}