fix regex, add * and empty text matchers

This commit is contained in:
janderedev 2021-08-12 23:17:52 +02:00
parent 82d3dd3c7b
commit dfed9515d1
No known key found for this signature in database
GPG key ID: 5D5E18ACB990F57A

View file

@ -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(/(?<!\\)\//);
const newContent = msg.content
// eslint-disable-next-line prefer-const
let [_, toReplace, newText, flags] = content.split(/(?<!\\)\//);
if (toReplace == "*") toReplace = msg.content.toString();
const newContent =
toReplace == ""
? msg.content.toString() + newText
: msg.content
.toString()
.replace(new RegExp(toReplace, flags), newText);
if (newContent != msg.content) {
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),
renderer.jumpToBottom(
SMOOTH_SCROLL_ON_RECEIVE,
),
),
)
.catch(console.warn);
.catch(console.error);
}
}
}
} else {