add notifs
This commit is contained in:
parent
8c00723e16
commit
729a7b8c56
9 changed files with 158 additions and 5 deletions
|
@ -49,6 +49,29 @@ router.post('/', async (req, res, next) => {
|
|||
(+new Date)
|
||||
]);
|
||||
|
||||
if (type == 'users') {
|
||||
await db.run('INSERT INTO messages (username, date, content, link, status) VALUES(?,?,?,?,?)', [
|
||||
id,
|
||||
(+new Date),
|
||||
`A user responded to your wall.`,
|
||||
`/walls/get/users/${id}/0`,
|
||||
'unread'
|
||||
]);
|
||||
} else if (type == 'comment') {
|
||||
let commenter = await db.all('SELECT * FROM comment WHERE id = ?', [
|
||||
id
|
||||
]);
|
||||
if (commenter[0]) {
|
||||
await db.run('INSERT INTO messages (username, date, content, link, status) VALUES(?,?,?,?,?)', [
|
||||
commenter[0].username,
|
||||
(+new Date),
|
||||
`A user responded to your post.`,
|
||||
`/walls/get/comment/${id}/0`,
|
||||
'unread'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
apiStat(res, next, `Comment submitted.`, '/comment/' + token)
|
||||
})
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ function initr(req, res, next) {
|
|||
{ link: '/walls/get/hub/main/0', icon: '/icon.svg', name: 'DervNet' },
|
||||
{ link: '/walls/list', icon: '/walls.svg', name: 'Explore' },
|
||||
{ link: '/users/' + (res.auth ? res.auth.username : ''), icon: '/login.svg', name: 'You' },
|
||||
{ link: '/info/tou', icon: '/icon.svg', name: 'Rules' },
|
||||
{ link: '/you/messages', icon: '/mail.svg', name: 'Messages' },
|
||||
{ link: '/you/logout', icon: '/logout.svg', name: 'Leave' }
|
||||
];
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import { Router } from "express";
|
||||
import { initDb } from "../db.js";
|
||||
|
||||
let db = await initDb();
|
||||
const router = Router();
|
||||
|
||||
//todo: fix jank
|
||||
|
@ -38,7 +41,6 @@ router.get('/logout', (req, res, next) => {
|
|||
next();
|
||||
})
|
||||
|
||||
|
||||
router.get('/new', (req, res, next) => {
|
||||
res.ctx.mainPage = 'form'
|
||||
res.ctx.mainCtx = {
|
||||
|
@ -69,4 +71,30 @@ router.get('/new', (req, res, next) => {
|
|||
next();
|
||||
})
|
||||
|
||||
router.get('/messages', async (req, res, next) => {
|
||||
let {username, valid} = res.auth;
|
||||
|
||||
if (!valid) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
let messages = await db.all('SELECT * FROM messages WHERE username = ? ORDER BY date DESC LIMIT ? OFFSET ?', [
|
||||
username,
|
||||
10,
|
||||
0
|
||||
]);
|
||||
|
||||
await db.run('UPDATE messages SET status = ? WHERE username = ?', [
|
||||
'read',
|
||||
username
|
||||
]);
|
||||
|
||||
res.ctx.mainPage = 'messages'
|
||||
res.ctx.mainCtx = {
|
||||
messages
|
||||
}
|
||||
next();
|
||||
})
|
||||
|
||||
export default router;
|
Loading…
Add table
Add a link
Reference in a new issue