Add State.createServer

This commit is contained in:
Simon Ser 2021-06-10 10:54:33 +02:00
parent 5fcbfa446c
commit bf76eaa669
2 changed files with 18 additions and 12 deletions

View file

@ -118,8 +118,6 @@ export default class App extends Component {
receipts = new Map(); receipts = new Map();
buffer = createRef(); buffer = createRef();
composer = createRef(); composer = createRef();
lastServerID = 0;
lastBufferID = 0;
switchToChannel = null; switchToChannel = null;
constructor(props) { constructor(props) {
@ -413,22 +411,17 @@ export default class App extends Component {
} }
connect(params) { connect(params) {
this.lastServerID++; var serverID = null;
var serverID = this.lastServerID;
this.setState((state) => { this.setState((state) => {
var servers = new Map(state.servers); var update;
servers.set(serverID, { [serverID, update] = State.createServer(state);
id: serverID, return update;
status: ServerStatus.CONNECTING,
isupport: new Map(),
});
return { servers };
}); });
this.setState({ connectParams: params }); this.setState({ connectParams: params });
var client = new Client(fillConnectParams(params)); var client = new Client(fillConnectParams(params));
this.clients.set(serverID, client); this.clients.set(serverID, client);
this.setServerState(serverID, { status: client.status });
client.addEventListener("status", () => { client.addEventListener("status", () => {
this.setServerState(serverID, { status: client.status }); this.setServerState(serverID, { status: client.status });

View file

@ -134,6 +134,7 @@ function insertMessage(list, msg) {
return list; return list;
} }
var lastServerID = 0;
var lastBufferID = 0; var lastBufferID = 0;
export const State = { export const State = {
@ -208,6 +209,18 @@ export const State = {
throw new Error("Invalid buffer ID type: " + (typeof id)); throw new Error("Invalid buffer ID type: " + (typeof id));
} }
}, },
createServer(state) {
lastServerID++;
var id = lastServerID;
var servers = new Map(state.servers);
servers.set(id, {
id,
status: ServerStatus.DISCONNECTED,
isupport: new Map(),
});
return [id, { servers }];
},
createBuffer(state, name, serverID, client) { createBuffer(state, name, serverID, client) {
var buf = State.getBuffer(state, { server: serverID, name }); var buf = State.getBuffer(state, { server: serverID, name });
if (buf) { if (buf) {