add notifs

This commit is contained in:
biglyderv 2025-03-02 04:09:17 -05:00
parent 8c00723e16
commit 729a7b8c56
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
9 changed files with 158 additions and 5 deletions

3
db.js
View file

@ -6,7 +6,8 @@ let db;
const sql = `CREATE TABLE IF NOT EXISTS auth (username TEXT, password TEXT);
CREATE TABLE IF NOT EXISTS token (username TEXT, token TEXT);
CREATE TABLE IF NOT EXISTS feeder (parentType TEXT, parentId TEXT, childType text, childId TEXT, sortId REAL);
CREATE TABLE IF NOT EXISTS comment (username TEXT, date REAL, content TEXT, id TEXT);`
CREATE TABLE IF NOT EXISTS comment (username TEXT, date REAL, content TEXT, id TEXT);
CREATE TABLE IF NOT EXISTS messages (username TEXT, date REAL, content TEXT, link TEXT, status TEXT)`
async function initDb() {
if (db) return db;

2
lib.js
View file

@ -55,4 +55,4 @@ async function replyIterator(replies, db) {
return replies;
}
export { importRouters, apiStat, replyIterator };
export { importRouters, apiStat, replyIterator, splitUp };

View file

@ -139,7 +139,8 @@ body {
margin: 0;
padding-left: 0;
height: 4em;
object-fit: cover;
width: 4em;
object-fit: contain;
display: flex;
flex-direction: column;
align-items: center;

85
public/mail.svg Normal file
View file

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="46.070927"
height="35.089081"
viewBox="0 0 46.070927 35.089082"
version="1.1"
id="svg1"
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
sodipodi:docname="mail.svg"
xml:space="preserve"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="px"
showguides="false"
inkscape:zoom="7.9999996"
inkscape:cx="19.125001"
inkscape:cy="21.562501"
inkscape:window-width="1918"
inkscape:window-height="1056"
inkscape:window-x="0"
inkscape:window-y="22"
inkscape:window-maximized="1"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:lockguides="true" /><defs
id="defs1" /><g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-60.927941,-65.880288)"><rect
style="fill:#ab88aa;fill-opacity:1;stroke:#0d0c11;stroke-width:3.40158;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
id="rect1"
width="42.669346"
height="31.687502"
x="62.628731"
y="67.581078" /><path
id="rect2"
style="fill:#2f2835;fill-opacity:1;stroke:#0d0c11;stroke-width:3.40158;stroke-linecap:round;stroke-linejoin:round;paint-order:stroke fill markers"
d="m 62.628731,67.581078 h 42.669349 l -21.000001,16.125 z"
sodipodi:nodetypes="cccc" /><g
id="g4"
style="stroke-width:10;stroke-dasharray:none"
transform="matrix(0.472384,-0.27273103,0.27273103,0.472384,19.883398,76.726014)"><g
id="g11"
transform="rotate(30,85.351954,98.307072)"><path
id="path1"
style="fill:#ab88aa;fill-opacity:1;stroke:#0d0c11;stroke-width:3.56524;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
d="m 81.016571,58.516151 a 8.939758,8.939758 0 0 0 -8.939583,8.93959 8.939758,8.939758 0 0 0 2.080659,5.716912 l -4.001855,6.47455 9.009917,-3.468429 a 8.939758,8.939758 0 0 0 1.850862,0.217242 8.939758,8.939758 0 0 0 8.940282,-8.940275 8.939758,8.939758 0 0 0 -8.940282,-8.93959 z" /><circle
style="fill:#2f2835;fill-opacity:1;stroke:none;stroke-width:4.465;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
id="circle3"
cy="67.455902"
cx="81.016754"
r="5.9711423" /><circle
style="fill:#f8e0f5;fill-opacity:1;stroke:none;stroke-width:3.92901;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
id="path5"
cx="81.378105"
cy="64.079811"
r="1.0672917" /><circle
style="fill:#f8e0f5;fill-opacity:1;stroke:none;stroke-width:3.92901;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
id="circle5"
cx="81.037964"
cy="67.393112"
r="1.90881" /><circle
style="fill:#f8e0f5;fill-opacity:1;stroke:none;stroke-width:3.92901;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
id="circle6"
cx="84.374725"
cy="67.856392"
r="0.65679485" /><circle
style="fill:#f8e0f5;fill-opacity:1;stroke:none;stroke-width:3.92901;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
id="circle7"
cx="77.847824"
cy="70.36042"
r="0.49259618" /></g></g></g></svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

@ -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)
})

View file

@ -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' }
];

View file

@ -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;

11
views/message.ejs Normal file
View file

@ -0,0 +1,11 @@
<div class='main'>
<h1 class="header-big">
Message
</h1>
<div>
<span class='commentbox'><a class='link' href='<%= link %>'><%= content %></a> </span>
</div>
<% if (!isNaN(date * 1)) { %>
<div class='sub'><b>Sent on</b> <%= new Date(date).toISOString() %> </div>
<% } %>
</div>

4
views/messages.ejs Normal file
View file

@ -0,0 +1,4 @@
<% for (let reply of messages) { %>
<%- include ('message.ejs', reply || {}) %>
<% } %>