mirror of
https://git.sr.ht/~emerson/reflectionircd
synced 2025-04-13 09:59:52 +00:00
initial batch work
This commit is contained in:
parent
8be16f12c6
commit
63bf00394d
2 changed files with 48 additions and 1 deletions
12
src/Batch.ts
Normal file
12
src/Batch.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { IRCMessage } from "./Message";
|
||||||
|
|
||||||
|
export class Batch {
|
||||||
|
public messages: Set<IRCMessage>
|
||||||
|
public batchType: string
|
||||||
|
public finished: boolean
|
||||||
|
constructor(public referenceTag: string, public openingBatch: IRCMessage) {
|
||||||
|
this.messages = new Set();
|
||||||
|
this.batchType = openingBatch.params[1];
|
||||||
|
this.finished = false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
import { Axios } from 'axios';
|
import { Axios } from 'axios';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { Socket } from 'net';
|
import { Socket } from 'net';
|
||||||
|
import { Batch } from './Batch.js';
|
||||||
import { Channel } from './Channel.js';
|
import { Channel } from './Channel.js';
|
||||||
import { MatrixUser } from './MatrixUser.js';
|
import { MatrixUser } from './MatrixUser.js';
|
||||||
import { IRCMessage, parseIRCMessage } from './Message.js';
|
import { IRCMessage, parseIRCMessage } from './Message.js';
|
||||||
|
@ -12,7 +13,8 @@ export class Client {
|
||||||
allCaps: Map<string, string>
|
allCaps: Map<string, string>
|
||||||
user: MatrixUser
|
user: MatrixUser
|
||||||
isRegistered: boolean
|
isRegistered: boolean
|
||||||
apiCall: Axios;
|
apiCall: Axios
|
||||||
|
batchesInProgress: Map<string, Batch>
|
||||||
constructor(private socket: Socket, public server: Server) {
|
constructor(private socket: Socket, public server: Server) {
|
||||||
this.capVersion = '301';
|
this.capVersion = '301';
|
||||||
this.enabledCaps = new Map();
|
this.enabledCaps = new Map();
|
||||||
|
@ -33,6 +35,7 @@ export class Client {
|
||||||
this.user = this.server.ourMatrixUser;
|
this.user = this.server.ourMatrixUser;
|
||||||
this.isRegistered = false;
|
this.isRegistered = false;
|
||||||
this.apiCall = this.server.apiCall;
|
this.apiCall = this.server.apiCall;
|
||||||
|
this.batchesInProgress = new Map();
|
||||||
this.server.doLog("New client connected");
|
this.server.doLog("New client connected");
|
||||||
this.socket.on('data', (data) => this.receiveData(data));
|
this.socket.on('data', (data) => this.receiveData(data));
|
||||||
//this.socket.on('close', (e) => {if (this.user) this.user.handleClientClose(this, e)});
|
//this.socket.on('close', (e) => {if (this.user) this.user.handleClientClose(this, e)});
|
||||||
|
@ -100,6 +103,14 @@ export class Client {
|
||||||
|
|
||||||
routeMessage(data: string) {
|
routeMessage(data: string) {
|
||||||
const message = parseIRCMessage(data);
|
const message = parseIRCMessage(data);
|
||||||
|
const maybeBatchRef = message.tags.get('batch');
|
||||||
|
if (maybeBatchRef) {
|
||||||
|
const maybeBatch = this.batchesInProgress.get(maybeBatchRef);
|
||||||
|
if (maybeBatch) {
|
||||||
|
maybeBatch.messages.add(message);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (message.command.toUpperCase()) {
|
switch (message.command.toUpperCase()) {
|
||||||
case 'AUTHENTICATE':
|
case 'AUTHENTICATE':
|
||||||
this.doAUTHENTICATE(message);
|
this.doAUTHENTICATE(message);
|
||||||
|
@ -164,6 +175,26 @@ export class Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doBATCH(message: IRCMessage) {
|
||||||
|
const referenceTag = message.params[0].substring(1);
|
||||||
|
if (message.params[0].startsWith('+')) {
|
||||||
|
this.batchesInProgress.set(referenceTag, new Batch(referenceTag, message))
|
||||||
|
} else if (message.params[0].startsWith('-')) {
|
||||||
|
const readyBatch = this.batchesInProgress.get(referenceTag);
|
||||||
|
if (readyBatch) {
|
||||||
|
switch (readyBatch.batchType) {
|
||||||
|
case 'draft/multiline':
|
||||||
|
case 'multiline':
|
||||||
|
this.doMultiline(readyBatch);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.batchesInProgress.delete(referenceTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
doCAP(message: IRCMessage) {
|
doCAP(message: IRCMessage) {
|
||||||
switch (message.params[0]) {
|
switch (message.params[0]) {
|
||||||
case 'LS': {
|
case 'LS': {
|
||||||
|
@ -326,6 +357,10 @@ export class Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doMultiline(batch: Batch) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
doMSG(message: IRCMessage) {
|
doMSG(message: IRCMessage) {
|
||||||
if (!this.checkIfRegistered() || !this.checkMinParams(message, 2))
|
if (!this.checkIfRegistered() || !this.checkMinParams(message, 2))
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue