generated from lucien/api-template
Compare commits
No commits in common. "8f77a271e1aecd34b83c6a5ac00b5f9328f82b43" and "d38c963babc50c088a4dff1604fc5755e8420ef7" have entirely different histories.
8f77a271e1
...
d38c963bab
2 changed files with 9 additions and 1 deletions
|
@ -126,11 +126,19 @@ router.post('/:message_id/delete', checkAuth, async (req, res) => {
|
|||
}
|
||||
|
||||
const channel = await getChannel(connection, message[0].channel_name);
|
||||
|
||||
if (user.id !== channel[0].owner_id && user.id !== message[0].user_id && user.admin !== 1) {
|
||||
connection.end();
|
||||
return res.status(401).send({ error: 'Unauthorized' });
|
||||
}
|
||||
|
||||
if (message[0].reply_to_id) {
|
||||
const replies = await getMessageReplies(connection, message[0].reply_to_id);
|
||||
if (replies.length === 1) {
|
||||
await setHasReplies(connection, replyToId, false);
|
||||
}
|
||||
}
|
||||
|
||||
await deleteMessage(connection, message_id);
|
||||
connection.end();
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ export default function ChannelPage({socket}: {socket: WebSocket}) {
|
|||
const data = JSON.parse(event.data);
|
||||
if ((data.type === "new_message" || data.type === "delete_message" || data.type === "purge_channel") && data.channel_id === channel?.id) {
|
||||
axios
|
||||
.get(`/api/channels/${name}/messages?limit=${maxMessageToShown}`).then((res) => {
|
||||
.get(`/api/channels/${name}/messages`).then((res) => {
|
||||
setMessages(res.data)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue