2021-12-05 18:33:49 -05:00
|
|
|
import { Channel } from "./Channel.js"
|
|
|
|
import { IRCUser } from "./IRCUser.js"
|
|
|
|
import { MatrixUser } from "./MatrixUser.js"
|
|
|
|
|
|
|
|
export class Server {
|
|
|
|
public name: string
|
|
|
|
// <roomId, Channel>
|
|
|
|
public matrixRooms: Map<string, Channel>
|
|
|
|
// <roomAlias (fallback to roomId), Channel>
|
|
|
|
public ircChannels: Map<string, Channel>
|
|
|
|
// <mxid, MatrixUser>
|
|
|
|
public matrixUsers: Map<string, MatrixUser>
|
|
|
|
// <mxid, IRCUser>
|
|
|
|
public ircUsers: Map<string, IRCUser>
|
|
|
|
public nickToMxid: Map<string, string>
|
|
|
|
constructor(public config: any) {
|
|
|
|
this.name = this.config.serverName;
|
|
|
|
this.matrixRooms = new Map();
|
|
|
|
this.ircChannels = new Map();
|
|
|
|
this.matrixUsers = new Map();
|
|
|
|
this.ircUsers = new Map();
|
|
|
|
this.nickToMxid = new Map();
|
|
|
|
}
|
2021-12-05 20:22:28 -05:00
|
|
|
|
|
|
|
getOrCreateMatrixUser(mxid: string): MatrixUser {
|
|
|
|
let maybeMatrixUser = this.matrixUsers.get(mxid);
|
|
|
|
if (maybeMatrixUser) {
|
|
|
|
return maybeMatrixUser;
|
|
|
|
}
|
|
|
|
let potentialNick = mxid.split(":")[0].substr(1);
|
|
|
|
if (!this.nickToMxid.has(potentialNick)) {
|
|
|
|
const newMatrixUser = new MatrixUser(mxid, potentialNick);
|
|
|
|
this.matrixUsers.set(mxid, newMatrixUser);
|
|
|
|
this.nickToMxid.set(potentialNick, mxid);
|
|
|
|
return newMatrixUser;
|
|
|
|
}
|
|
|
|
const homeserverArray = mxid.split(":")[1].split('.');
|
|
|
|
const baseDomainNum = homeserverArray.length - 2;
|
|
|
|
potentialNick = `${potentialNick}-${homeserverArray[baseDomainNum]}`;
|
|
|
|
const newMatrixUser = new MatrixUser(mxid, potentialNick);
|
|
|
|
this.matrixUsers.set(mxid, newMatrixUser);
|
|
|
|
this.nickToMxid.set(potentialNick, mxid);
|
|
|
|
return newMatrixUser;
|
|
|
|
}
|
2021-12-05 18:33:49 -05:00
|
|
|
}
|