Skip to content

Node.js based forum software built for the modern web

feat: native parsing of title for topics

Julian Lam981b4f146dae
diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js
index 30930a0156..fad3f12f4e 100644
--- a/src/activitypub/mocks.js
+++ b/src/activitypub/mocks.js
@@ -74,7 +74,8 @@ Mocks.post = async (objects) => {
}
const posts = await Promise.all(objects.map(async (object) => {
- if (object.type !== 'Note') {
+ const acceptedTypes = ['Note', 'Page', 'Article'];
+ if (!acceptedTypes.includes(object.type)) {
return null;
}
@@ -84,6 +85,7 @@ Mocks.post = async (objects) => {
updated,
attributedTo: uid,
// conversation,
+ name,
content,
sourceContent,
inReplyTo: toPid,
@@ -96,7 +98,8 @@ Mocks.post = async (objects) => {
const payload = {
uid,
pid,
- // tid,
+ // tid, --> purposely omitted
+ name,
content,
sourceContent,
timestamp,
diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js
index c57ae3ed9a..7264d5855d 100644
--- a/src/activitypub/notes.js
+++ b/src/activitypub/notes.js
@@ -5,6 +5,7 @@ const winston = require('winston');
const db = require('../database');
const topics = require('../topics');
const posts = require('../posts');
+const utils = require('../utils');
const activitypub = module.parent.exports;
const Notes = module.exports;
@@ -91,7 +92,7 @@ Notes.assertTopic = async (uid, id) => {
*/
const chain = Array.from(await Notes.getParentChain(uid, id));
- const { pid: tid, uid: authorId, timestamp } = chain[chain.length - 1];
+ const { pid: tid, uid: authorId, timestamp, name, content } = chain[chain.length - 1];
const members = await db.isSortedSetMembers(`tidRemote:${tid}:posts`, chain.map(p => p.pid));
if (members.every(Boolean)) {
@@ -100,6 +101,11 @@ Notes.assertTopic = async (uid, id) => {
return tid;
}
+ let title = name || utils.stripHTMLTags(content);
+ if (title.length > 256) {
+ title = `${title.slice(0, 256)}...`;
+ }
+
const cid = await topics.getTopicField(tid, 'cid');
const unprocessed = chain.filter((p, idx) => !members[idx]);
@@ -116,7 +122,7 @@ Notes.assertTopic = async (uid, id) => {
uid: authorId,
cid: cid || -1,
mainPid: tid,
- title: 'TBD',
+ title,
slug: `remote?resource=${encodeURIComponent(tid)}`,
timestamp,
}),