mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-26 00:50:56 -05:00
fix regex, add * and empty text matchers
This commit is contained in:
parent
82d3dd3c7b
commit
dfed9515d1
1 changed files with 27 additions and 15 deletions
|
@ -107,7 +107,7 @@ const Action = styled.div`
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// For sed replacement
|
// 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
|
// ! FIXME: add to app config and load from app config
|
||||||
export const CAN_UPLOAD_AT_ONCE = 4;
|
export const CAN_UPLOAD_AT_ONCE = 4;
|
||||||
|
@ -214,22 +214,34 @@ export default observer(({ channel }: Props) => {
|
||||||
renderer.messages.reverse();
|
renderer.messages.reverse();
|
||||||
|
|
||||||
if (msg) {
|
if (msg) {
|
||||||
const [_, toReplace, newText, flags] =
|
// eslint-disable-next-line prefer-const
|
||||||
content.split(/(?<!\\)\//);
|
let [_, toReplace, newText, flags] = content.split(/(?<!\\)\//);
|
||||||
const newContent = msg.content
|
|
||||||
|
if (toReplace == "*") toReplace = msg.content.toString();
|
||||||
|
|
||||||
|
const newContent =
|
||||||
|
toReplace == ""
|
||||||
|
? msg.content.toString() + newText
|
||||||
|
: msg.content
|
||||||
.toString()
|
.toString()
|
||||||
.replace(new RegExp(toReplace, flags), newText);
|
.replace(new RegExp(toReplace, flags), newText);
|
||||||
|
|
||||||
if (newContent != msg.content) {
|
if (newContent != msg.content) {
|
||||||
|
if (newContent.length == 0) {
|
||||||
|
msg.delete().catch(console.error);
|
||||||
|
} else {
|
||||||
msg.edit({
|
msg.edit({
|
||||||
content: newContent.substr(0, 2000),
|
content: newContent.substr(0, 2000),
|
||||||
})
|
})
|
||||||
.then(() =>
|
.then(() =>
|
||||||
defer(() =>
|
defer(() =>
|
||||||
renderer.jumpToBottom(SMOOTH_SCROLL_ON_RECEIVE),
|
renderer.jumpToBottom(
|
||||||
|
SMOOTH_SCROLL_ON_RECEIVE,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.catch(console.warn);
|
.catch(console.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue