add mentions
This commit is contained in:
parent
62a5bb4c0c
commit
3036de0f03
4 changed files with 48 additions and 6 deletions
|
@ -5,14 +5,37 @@ import initDb from "../db.js";
|
||||||
let db = await initDb();
|
let db = await initDb();
|
||||||
|
|
||||||
let main = new Route([auth], async function (req, res, input) {
|
let main = new Route([auth], async function (req, res, input) {
|
||||||
let {route} = req.params;
|
let { route } = req.params;
|
||||||
let {id} = req.query;
|
let { id } = req.query;
|
||||||
|
|
||||||
let comments = await db.all('SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC', [
|
let comments = await db.all('SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC', [
|
||||||
route,
|
route,
|
||||||
id
|
id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
for (let comment of comments) {
|
||||||
|
let { content } = comment;
|
||||||
|
content = content.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, ''');
|
||||||
|
|
||||||
|
content = content.split(' ');
|
||||||
|
|
||||||
|
for (let elem in content) {
|
||||||
|
let e = content[elem];
|
||||||
|
if (e.startsWith('@')) {
|
||||||
|
let f = e.slice(1);
|
||||||
|
content[elem] = `<a class='link' href='/client/user?id=${f}'>${e}</a>`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
content = content.join(' ');
|
||||||
|
|
||||||
|
comment.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...input,
|
...input,
|
||||||
route,
|
route,
|
||||||
|
|
|
@ -14,6 +14,9 @@ let main = new Route([auth], async function (req, res, input) {
|
||||||
if (!targetType || !targetId || !content || username == '!nobody')
|
if (!targetType || !targetId || !content || username == '!nobody')
|
||||||
return { 'success': false, 'message': 'Some fields are missing' }; // probably should not re-use these strings
|
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 (?,?,?,?,?,?)', [
|
await db.run('INSERT INTO comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)', [
|
||||||
username,
|
username,
|
||||||
targetType,
|
targetType,
|
||||||
|
@ -25,6 +28,23 @@ let main = new Route([auth], async function (req, res, input) {
|
||||||
|
|
||||||
let u = `/client/${targetType}?id=${targetId}`;
|
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') {
|
if (targetType == 'user') {
|
||||||
await db.run('INSERT INTO message (username, targetType, targetId, date, content, read) VALUES (?,?,?,?,?,?)', [
|
await db.run('INSERT INTO message (username, targetType, targetId, date, content, read) VALUES (?,?,?,?,?,?)', [
|
||||||
targetId,
|
targetId,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<%- include('form_bare.ejs', { data: [ { label: "" , type: "text" , name: "targetId" , hidden: id }, { label: "" ,
|
<%- include('form_bare.ejs', { data: [ { label: "" , type: "text" , name: "targetId" , hidden: id }, { label: "" ,
|
||||||
type: "text" , name: "targetType" , hidden: route }, { label: "Your thoughts..." , type: "textarea" ,
|
type: "text" , name: "targetType" , hidden: route }, { label: "Your thoughts..." , type: "textarea" ,
|
||||||
name: "content" , hidden: route }, ], 'route' : '/api/form/comment' , 'title' : 'Comments' , noCaptcha: true })
|
name: "content" , hidden: route }, ], 'route' : '/api/form/comment' , 'title' : 'Comments' , noCaptcha: true }) -%>
|
||||||
-%>
|
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<% for (let comment of comments) { %>
|
<% for (let comment of comments) { %>
|
||||||
|
@ -17,7 +16,7 @@
|
||||||
<div><b>
|
<div><b>
|
||||||
<%= (new Date(comment.date)+'').split(/(GMT|UTC)/g)[0] %>
|
<%= (new Date(comment.date)+'').split(/(GMT|UTC)/g)[0] %>
|
||||||
</b></div>
|
</b></div>
|
||||||
<pre><%= comment.content %></pre>
|
<pre><%- comment.content %></pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<% } %>
|
<% } %>
|
||||||
<a class='form-button' href="/client/tou">Terms of Use</a>
|
<a class='form-button' href="/client/tou">Terms of Use</a>
|
||||||
<a class='form-button' href="https://dervland.net/">More Projects</a>
|
<a class='form-button' href="https://dervland.net/">More Projects</a>
|
||||||
<a class='form-button' href="https://git.dervlnd.net/core/bigly-chat">Developer Portal</a>
|
<a class='form-button' href="https://git.dervland.net/core/bigly-chat">Developer Portal</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h1 class='content-header'>Follow Feed</h1>
|
<h1 class='content-header'>Follow Feed</h1>
|
||||||
|
|
Loading…
Reference in a new issue