add messages
This commit is contained in:
parent
d5daf958cf
commit
a9a0996e77
11 changed files with 220 additions and 10 deletions
18
form/auth.js
18
form/auth.js
|
@ -4,8 +4,8 @@ import initDb from "../db.js";
|
|||
let db = await initDb();
|
||||
|
||||
let main = new Route([], async function (req, res, input) {
|
||||
let {route} = req.params;
|
||||
let {id} = req.query;
|
||||
let { route } = req.params;
|
||||
let { id } = req.query;
|
||||
|
||||
let body = { ...req.cookies, ...req.body };
|
||||
|
||||
|
@ -21,13 +21,25 @@ let main = new Route([], async function (req, res, input) {
|
|||
username
|
||||
]);
|
||||
|
||||
let isRead = false;
|
||||
|
||||
if (username) {
|
||||
let msgs = await db.all('SELECT * FROM message WHERE username = ? AND read = ?', [
|
||||
username,
|
||||
'false'
|
||||
]);
|
||||
|
||||
isRead = msgs.length > 0
|
||||
}
|
||||
|
||||
return {
|
||||
username,
|
||||
valid: valid[0] ? valid[0].valid : 'noexist',
|
||||
url: `${process.env.URL}/client/${route}?id=${id || ''}`,
|
||||
icon: `${process.env.URL}/static/img/logo.png`,
|
||||
rootUrl: process.env.URL,
|
||||
ogType: 'website'
|
||||
ogType: 'website',
|
||||
isRead: isRead ? 'unread' : 'read'
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -23,7 +23,20 @@ let main = new Route([auth], async function (req, res, input) {
|
|||
id
|
||||
]);
|
||||
|
||||
res.send({ 'message': 'Comment sent', redirect: `/client/${targetType}?id=${targetId}` });
|
||||
let u = `/client/${targetType}?id=${targetId}`;
|
||||
|
||||
if (targetType == 'user') {
|
||||
await db.run('INSERT INTO message (username, targetType, targetId, date, content, read) VALUES (?,?,?,?,?,?)', [
|
||||
targetId,
|
||||
'profile comment',
|
||||
u,
|
||||
+new Date(),
|
||||
content,
|
||||
'false'
|
||||
]);
|
||||
}
|
||||
|
||||
res.send({ 'message': 'Comment sent', redirect: u });
|
||||
});
|
||||
|
||||
export default main;
|
Loading…
Add table
Add a link
Reference in a new issue