mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-23 00:40:23 +01:00
feat: native parsing of title for topics
This commit is contained in:
@@ -74,7 +74,8 @@ Mocks.post = async (objects) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const posts = await Promise.all(objects.map(async (object) => {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +85,7 @@ Mocks.post = async (objects) => {
|
|||||||
updated,
|
updated,
|
||||||
attributedTo: uid,
|
attributedTo: uid,
|
||||||
// conversation,
|
// conversation,
|
||||||
|
name,
|
||||||
content,
|
content,
|
||||||
sourceContent,
|
sourceContent,
|
||||||
inReplyTo: toPid,
|
inReplyTo: toPid,
|
||||||
@@ -96,7 +98,8 @@ Mocks.post = async (objects) => {
|
|||||||
const payload = {
|
const payload = {
|
||||||
uid,
|
uid,
|
||||||
pid,
|
pid,
|
||||||
// tid,
|
// tid, --> purposely omitted
|
||||||
|
name,
|
||||||
content,
|
content,
|
||||||
sourceContent,
|
sourceContent,
|
||||||
timestamp,
|
timestamp,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const winston = require('winston');
|
|||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const topics = require('../topics');
|
const topics = require('../topics');
|
||||||
const posts = require('../posts');
|
const posts = require('../posts');
|
||||||
|
const utils = require('../utils');
|
||||||
|
|
||||||
const activitypub = module.parent.exports;
|
const activitypub = module.parent.exports;
|
||||||
const Notes = module.exports;
|
const Notes = module.exports;
|
||||||
@@ -91,7 +92,7 @@ Notes.assertTopic = async (uid, id) => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const chain = Array.from(await Notes.getParentChain(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));
|
const members = await db.isSortedSetMembers(`tidRemote:${tid}:posts`, chain.map(p => p.pid));
|
||||||
if (members.every(Boolean)) {
|
if (members.every(Boolean)) {
|
||||||
@@ -100,6 +101,11 @@ Notes.assertTopic = async (uid, id) => {
|
|||||||
return tid;
|
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 cid = await topics.getTopicField(tid, 'cid');
|
||||||
|
|
||||||
const unprocessed = chain.filter((p, idx) => !members[idx]);
|
const unprocessed = chain.filter((p, idx) => !members[idx]);
|
||||||
@@ -116,7 +122,7 @@ Notes.assertTopic = async (uid, id) => {
|
|||||||
uid: authorId,
|
uid: authorId,
|
||||||
cid: cid || -1,
|
cid: cid || -1,
|
||||||
mainPid: tid,
|
mainPid: tid,
|
||||||
title: 'TBD',
|
title,
|
||||||
slug: `remote?resource=${encodeURIComponent(tid)}`,
|
slug: `remote?resource=${encodeURIComponent(tid)}`,
|
||||||
timestamp,
|
timestamp,
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user