From 48eea8abe780196d77d3b329d742d8843e6c281b Mon Sep 17 00:00:00 2001 From: biglyderv Date: Mon, 3 Mar 2025 13:51:06 -0500 Subject: [PATCH] add message count --- routes/init.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/routes/init.js b/routes/init.js index 7bfd198..5dd5da7 100644 --- a/routes/init.js +++ b/routes/init.js @@ -88,12 +88,23 @@ async function auther(req, res, next) { next(); } -function initr(req, res, next) { +async function initr(req, res, next) { + let msgCount = 0; + + if (res.auth.valid) { + let messages = await db.all('SELECT count(*) FROM messages WHERE username = ? AND status = ?', [ + res.auth.username, + 'unread' + ]); + + msgCount = messages[0]['count(*)']; + } + let headerCtx = [ { 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: '/you/messages', icon: '/mail.svg', name: 'Messages' }, + { link: '/you/messages', icon: '/mail.svg', name: `Messages [${msgCount}]` }, { link: '/you/logout', icon: '/logout.svg', name: 'Leave' } ];