mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-26 00:50:56 -05:00
Merge pull request #66 from janderedev/pr-6
This commit is contained in:
commit
ff9545ba2f
1 changed files with 71 additions and 24 deletions
|
@ -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
|
||||
export const CAN_UPLOAD_AT_ONCE = 4;
|
||||
|
||||
|
@ -198,9 +201,52 @@ export default observer(({ channel }: Props) => {
|
|||
stopTyping();
|
||||
setMessage();
|
||||
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) {
|
||||
// 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,
|
||||
),
|
||||
),
|
||||
)
|
||||
.catch(console.error);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
playSound("outbound");
|
||||
|
||||
const nonce = ulid();
|
||||
dispatch({
|
||||
type: "QUEUE_ADD",
|
||||
nonce,
|
||||
|
@ -231,6 +277,7 @@ export default observer(({ channel }: Props) => {
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function sendFile(content: string) {
|
||||
if (uploadState.type !== "attached") return;
|
||||
|
|
Loading…
Reference in a new issue