From dfed9515d186ac127096ab2653d4e0710d3ec199 Mon Sep 17 00:00:00 2001 From: janderedev Date: Thu, 12 Aug 2021 23:17:52 +0200 Subject: [PATCH] fix regex, add * and empty text matchers --- .../common/messaging/MessageBox.tsx | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/components/common/messaging/MessageBox.tsx b/src/components/common/messaging/MessageBox.tsx index 69c6bcab..d058bcff 100644 --- a/src/components/common/messaging/MessageBox.tsx +++ b/src/components/common/messaging/MessageBox.tsx @@ -107,7 +107,7 @@ const Action = styled.div` `; // For sed replacement -const SED_REGEX = new RegExp("^s/([^])+/([^])+$"); +const SED_REGEX = new RegExp("^s/([^])*/([^])*$"); // ! FIXME: add to app config and load from app config export const CAN_UPLOAD_AT_ONCE = 4; @@ -214,22 +214,34 @@ export default observer(({ channel }: Props) => { renderer.messages.reverse(); if (msg) { - const [_, toReplace, newText, flags] = - content.split(/(? - defer(() => - renderer.jumpToBottom(SMOOTH_SCROLL_ON_RECEIVE), - ), - ) - .catch(console.warn); + if (newContent.length == 0) { + msg.delete().catch(console.error); + } else { + msg.edit({ + content: newContent.substr(0, 2000), + }) + .then(() => + defer(() => + renderer.jumpToBottom( + SMOOTH_SCROLL_ON_RECEIVE, + ), + ), + ) + .catch(console.error); + } } } } else {