add mentions
This commit is contained in:
parent
a97bded7f5
commit
d4ed9e48cf
4 changed files with 48 additions and 6 deletions
|
@ -14,6 +14,9 @@ let main = new Route([auth], async function (req, res, input) {
|
|||
if (!targetType || !targetId || !content || username == '!nobody')
|
||||
return { 'success': false, 'message': 'Some fields are missing' }; // probably should not re-use these strings
|
||||
|
||||
if (content.length > 8192)
|
||||
return { 'success': false, 'message': 'Comment is too long' };
|
||||
|
||||
await db.run('INSERT INTO comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)', [
|
||||
username,
|
||||
targetType,
|
||||
|
@ -25,6 +28,23 @@ let main = new Route([auth], async function (req, res, input) {
|
|||
|
||||
let u = `/client/${targetType}?id=${targetId}`;
|
||||
|
||||
let a = content.split(' ');
|
||||
|
||||
for (let b of a) {
|
||||
if (b.startsWith('@')) {
|
||||
let f = b.slice(1);
|
||||
|
||||
await db.run('INSERT INTO message (username, targetType, targetId, date, content, read) VALUES (?,?,?,?,?,?)', [
|
||||
f,
|
||||
'mention',
|
||||
u,
|
||||
+new Date(),
|
||||
content,
|
||||
'false'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (targetType == 'user') {
|
||||
await db.run('INSERT INTO message (username, targetType, targetId, date, content, read) VALUES (?,?,?,?,?,?)', [
|
||||
targetId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue