mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 01:15:28 +00:00
sed replacement in message box.
This commit is contained in:
@@ -106,6 +106,9 @@ const Action = styled.div`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// For sed replacement
|
||||||
|
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;
|
||||||
|
|
||||||
@@ -198,9 +201,34 @@ export default observer(({ channel }: Props) => {
|
|||||||
stopTyping();
|
stopTyping();
|
||||||
setMessage();
|
setMessage();
|
||||||
setReplies([]);
|
setReplies([]);
|
||||||
|
const nonce = ulid();
|
||||||
|
|
||||||
|
// sed style message editing.
|
||||||
|
// If the user types for example `s/abc/def`, the string "abc"
|
||||||
|
// will be replaced with "def" in their last sent message.
|
||||||
|
if (SED_REGEX.test(content)) {
|
||||||
|
renderer.messages.reverse();
|
||||||
|
const msg = renderer.messages.find(
|
||||||
|
(msg) => msg.author_id === client.user!._id,
|
||||||
|
);
|
||||||
|
renderer.messages.reverse();
|
||||||
|
|
||||||
|
if (msg) {
|
||||||
|
const [_, toReplace, newText, flags] =
|
||||||
|
content.split(/(?<!\\)\//);
|
||||||
|
const newContent = msg.content
|
||||||
|
.toString()
|
||||||
|
.replace(new RegExp(toReplace, flags), newText);
|
||||||
|
|
||||||
|
if (newContent != msg.content) {
|
||||||
|
msg.edit({
|
||||||
|
content: newContent.substr(0, 2000),
|
||||||
|
}).catch(console.warn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
playSound("outbound");
|
playSound("outbound");
|
||||||
|
|
||||||
const nonce = ulid();
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: "QUEUE_ADD",
|
type: "QUEUE_ADD",
|
||||||
nonce,
|
nonce,
|
||||||
@@ -231,6 +259,7 @@ export default observer(({ channel }: Props) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function sendFile(content: string) {
|
async function sendFile(content: string) {
|
||||||
if (uploadState.type !== "attached") return;
|
if (uploadState.type !== "attached") return;
|
||||||
|
|||||||
Reference in New Issue
Block a user