From 63bf00394d9b2334c0fc467eacdb170a39f8004b Mon Sep 17 00:00:00 2001 From: emerson Date: Fri, 8 Apr 2022 12:35:38 -0400 Subject: [PATCH] initial batch work --- src/Batch.ts | 12 ++++++++++++ src/Client.ts | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/Batch.ts diff --git a/src/Batch.ts b/src/Batch.ts new file mode 100644 index 0000000..dce919f --- /dev/null +++ b/src/Batch.ts @@ -0,0 +1,12 @@ +import { IRCMessage } from "./Message"; + +export class Batch { + public messages: Set + 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; + } +} \ No newline at end of file diff --git a/src/Client.ts b/src/Client.ts index bbad7b0..16973ad 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1,6 +1,7 @@ import { Axios } from 'axios'; import { randomUUID } from 'crypto'; import { Socket } from 'net'; +import { Batch } from './Batch.js'; import { Channel } from './Channel.js'; import { MatrixUser } from './MatrixUser.js'; import { IRCMessage, parseIRCMessage } from './Message.js'; @@ -12,7 +13,8 @@ export class Client { allCaps: Map user: MatrixUser isRegistered: boolean - apiCall: Axios; + apiCall: Axios + batchesInProgress: Map constructor(private socket: Socket, public server: Server) { this.capVersion = '301'; this.enabledCaps = new Map(); @@ -33,6 +35,7 @@ export class Client { this.user = this.server.ourMatrixUser; this.isRegistered = false; this.apiCall = this.server.apiCall; + this.batchesInProgress = new Map(); this.server.doLog("New client connected"); this.socket.on('data', (data) => this.receiveData(data)); //this.socket.on('close', (e) => {if (this.user) this.user.handleClientClose(this, e)}); @@ -100,6 +103,14 @@ export class Client { routeMessage(data: string) { 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()) { case 'AUTHENTICATE': 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) { switch (message.params[0]) { case 'LS': { @@ -326,6 +357,10 @@ export class Client { } } + doMultiline(batch: Batch) { + + } + doMSG(message: IRCMessage) { if (!this.checkIfRegistered() || !this.checkMinParams(message, 2)) return;