From bb010234e56be5164bceef39469788db564908dd Mon Sep 17 00:00:00 2001 From: HF Date: Sun, 24 Jul 2022 00:35:44 +0200 Subject: [PATCH] split matrix sent textwalls into individual messages for ppfun --- ppfun-bridge/src/ppfunMatrixBridge.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ppfun-bridge/src/ppfunMatrixBridge.js b/ppfun-bridge/src/ppfunMatrixBridge.js index d3612db..5388afc 100644 --- a/ppfun-bridge/src/ppfunMatrixBridge.js +++ b/ppfun-bridge/src/ppfunMatrixBridge.js @@ -188,7 +188,15 @@ class PPfunMatrixBridge { name = await this.getDisplayName(userId); } console.log(`MATRIX ${name}: ${msg}`); - this.sendPPfun(name, parseInt(uid, 10), msg, cid); + msg.split('\n').forEach((part) => { + let msgLine = part; + while (msgLine.length > 190) { + const msgPart = msgLine.slice(0, 190); + msgLine = msgLine.slice(190); + this.sendPPfun(name, parseInt(uid, 10), msgPart, cid); + } + this.sendPPfun(name, parseInt(uid, 10), msgLine, cid); + }) return; } @@ -221,11 +229,15 @@ class PPfunMatrixBridge { * uid needs to be a number */ sendPPfun(name, uid, msg, cid) { + const msgString = msg.trim(); + if (!msgString.length) { + return; + } this.ppfunSocket.emit( 'sendChatMessage', (uid) ? name : `[mx] ${name}`, uid || null, - msg, + msgString, cid, ); }