add mentions
This commit is contained in:
parent
62a5bb4c0c
commit
3036de0f03
4 changed files with 48 additions and 6 deletions
|
@ -13,6 +13,29 @@ let main = new Route([auth], async function (req, res, input) {
|
|||
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 {
|
||||
...input,
|
||||
route,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<%- include('form_bare.ejs', { data: [ { label: "" , type: "text" , name: "targetId" , hidden: id }, { label: "" ,
|
||||
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">
|
||||
<% for (let comment of comments) { %>
|
||||
|
@ -17,7 +16,7 @@
|
|||
<div><b>
|
||||
<%= (new Date(comment.date)+'').split(/(GMT|UTC)/g)[0] %>
|
||||
</b></div>
|
||||
<pre><%= comment.content %></pre>
|
||||
<pre><%- comment.content %></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<% } %>
|
||||
<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://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>
|
||||
<h1 class='content-header'>Follow Feed</h1>
|
||||
|
|
Loading…
Reference in a new issue