mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: a bunch of broken things, added test for Create(Note)
This commit is contained in:
@@ -30,7 +30,7 @@ Actors.assert = async (ids, options = {}) => {
|
|||||||
|
|
||||||
const actors = await Promise.all(ids.map(async (id) => {
|
const actors = await Promise.all(ids.map(async (id) => {
|
||||||
try {
|
try {
|
||||||
const actor = (typeof id === 'object' && id.hasOwnProperty('id')) ? await activitypub.get(0, id) : id;
|
const actor = (typeof id === 'object' && id.hasOwnProperty('id')) ? id : await activitypub.get(0, id);
|
||||||
|
|
||||||
// Follow counts
|
// Follow counts
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ ActivityPub.actors = require('./actors');
|
|||||||
ActivityPub.resolveInboxes = async (ids) => {
|
ActivityPub.resolveInboxes = async (ids) => {
|
||||||
const inboxes = new Set();
|
const inboxes = new Set();
|
||||||
|
|
||||||
|
await ActivityPub.actors.assert(ids);
|
||||||
await Promise.all(ids.map(async (id) => {
|
await Promise.all(ids.map(async (id) => {
|
||||||
const { inbox, sharedInbox } = await user.getUserFields(id, ['inbox', 'sharedInbox']);
|
const { inbox, sharedInbox } = await user.getUserFields(id, ['inbox', 'sharedInbox']);
|
||||||
if (sharedInbox || inbox) {
|
if (sharedInbox || inbox) {
|
||||||
@@ -190,7 +191,7 @@ ActivityPub.send = async (uid, targets, payload) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const userslug = await user.getUserField(uid, 'userslug');
|
const userslug = await user.getUserField(uid, 'userslug');
|
||||||
const inboxes = await ActivityPub.resolveInboxes(uid, targets);
|
const inboxes = await ActivityPub.resolveInboxes(targets);
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const mime = require('mime');
|
|||||||
|
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
const posts = require('../posts');
|
const posts = require('../posts');
|
||||||
|
const topics = require('../topics');
|
||||||
|
|
||||||
const activitypub = module.parent.exports;
|
const activitypub = module.parent.exports;
|
||||||
const Mocks = module.exports;
|
const Mocks = module.exports;
|
||||||
@@ -53,7 +54,7 @@ Mocks.profile = async (actors) => {
|
|||||||
followingCount,
|
followingCount,
|
||||||
|
|
||||||
inbox,
|
inbox,
|
||||||
sharedInbox: endpoints.sharedInbox,
|
sharedInbox: endpoints ? endpoints.sharedInbox : null,
|
||||||
};
|
};
|
||||||
|
|
||||||
return payload;
|
return payload;
|
||||||
@@ -174,13 +175,16 @@ Mocks.note = async (post) => {
|
|||||||
const cc = [`${nconf.get('url')}/user/${userslug}/followers`];
|
const cc = [`${nconf.get('url')}/user/${userslug}/followers`];
|
||||||
|
|
||||||
let inReplyTo = null;
|
let inReplyTo = null;
|
||||||
if (post.toPid) {
|
let name = null;
|
||||||
|
if (post.toPid) { // direct reply
|
||||||
inReplyTo = activitypub.helpers.isUri(post.toPid) ? post.toPid : `${nconf.get('url')}/post/${post.toPid}`;
|
inReplyTo = activitypub.helpers.isUri(post.toPid) ? post.toPid : `${nconf.get('url')}/post/${post.toPid}`;
|
||||||
const parentId = await posts.getPostField(post.toPid, 'uid');
|
const parentId = await posts.getPostField(post.toPid, 'uid');
|
||||||
to.unshift(activitypub.helpers.isUri(parentId) ? parentId : `${nconf.get('url')}/uid/${parentId}`);
|
to.unshift(activitypub.helpers.isUri(parentId) ? parentId : `${nconf.get('url')}/uid/${parentId}`);
|
||||||
} else if (!post.isMainPost) {
|
} else if (!post.isMainPost) { // reply to OP
|
||||||
inReplyTo = `${nconf.get('url')}/post/${post.topic.mainPid}`;
|
inReplyTo = `${nconf.get('url')}/post/${post.topic.mainPid}`;
|
||||||
to.unshift(activitypub.helpers.isUri(post.topic.uid) ? post.topic.uid : `${nconf.get('url')}/uid/${post.topic.uid}`);
|
to.unshift(activitypub.helpers.isUri(post.topic.uid) ? post.topic.uid : `${nconf.get('url')}/uid/${post.topic.uid}`);
|
||||||
|
} else { // new topic
|
||||||
|
name = await topics.getTitleByPid(post.pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
const object = {
|
const object = {
|
||||||
@@ -194,6 +198,7 @@ Mocks.note = async (post) => {
|
|||||||
attributedTo: `${nconf.get('url')}/uid/${post.user.uid}`,
|
attributedTo: `${nconf.get('url')}/uid/${post.user.uid}`,
|
||||||
sensitive: false, // todo
|
sensitive: false, // todo
|
||||||
summary: null,
|
summary: null,
|
||||||
|
name,
|
||||||
content: post.content,
|
content: post.content,
|
||||||
source: {
|
source: {
|
||||||
content: raw,
|
content: raw,
|
||||||
|
|||||||
@@ -99,4 +99,6 @@ Controller.postInbox = async (req, res) => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.sendStatus(200);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ function modifyTopic(topic, fields) {
|
|||||||
if (validator.isUUID(String(topic.tid))) {
|
if (validator.isUUID(String(topic.tid))) {
|
||||||
intFields.splice(intFields.indexOf('uid'), 1);
|
intFields.splice(intFields.indexOf('uid'), 1);
|
||||||
intFields.splice(intFields.indexOf('tid'), 1);
|
intFields.splice(intFields.indexOf('tid'), 1);
|
||||||
|
intFields.splice(intFields.indexOf('mainPid'), 1);
|
||||||
}
|
}
|
||||||
db.parseIntFields(topic, intFields, fields);
|
db.parseIntFields(topic, intFields, fields);
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ const request = require('../src/request');
|
|||||||
|
|
||||||
const meta = require('../src/meta');
|
const meta = require('../src/meta');
|
||||||
const user = require('../src/user');
|
const user = require('../src/user');
|
||||||
|
const categories = require('../src/categories');
|
||||||
|
const topics = require('../src/topics');
|
||||||
|
const posts = require('../src/posts');
|
||||||
const privileges = require('../src/privileges');
|
const privileges = require('../src/privileges');
|
||||||
const activitypub = require('../src/activitypub');
|
const activitypub = require('../src/activitypub');
|
||||||
|
|
||||||
@@ -389,4 +392,57 @@ describe('ActivityPub integration', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe.only('Receipt of ActivityPub events to inboxes (federating IN)', () => {
|
||||||
|
describe('Create', () => {
|
||||||
|
describe('Note', () => {
|
||||||
|
let category;
|
||||||
|
let uid;
|
||||||
|
let note;
|
||||||
|
let topic;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
category = await categories.create({ name: 'test' });
|
||||||
|
const slug = slugify(utils.generateUUID().slice(0, 8));
|
||||||
|
uid = await user.create({ username: slug });
|
||||||
|
|
||||||
|
const { postData, topicData } = await topics.post({
|
||||||
|
uid,
|
||||||
|
cid: category.cid,
|
||||||
|
title: 'Lipsum title',
|
||||||
|
content: 'Lorem ipsum dolor sit amet',
|
||||||
|
});
|
||||||
|
|
||||||
|
const post = (await posts.getPostSummaryByPids([postData.pid], uid, { stripTags: false })).pop();
|
||||||
|
note = await activitypub.mocks.note(post);
|
||||||
|
|
||||||
|
await activitypub.send(uid, [`${nconf.get('url')}/uid/${uid}`], {
|
||||||
|
type: 'Create',
|
||||||
|
object: note,
|
||||||
|
});
|
||||||
|
|
||||||
|
const tid = await posts.getPostField(note.id, 'tid');
|
||||||
|
topic = await topics.getTopicData(tid);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a new topic if Note is at root-level or its parent has not been seen before', async () => {
|
||||||
|
const saved = await db.getObject(`post:${note.id}`);
|
||||||
|
|
||||||
|
assert(saved);
|
||||||
|
assert(topic);
|
||||||
|
assert.strictEqual(saved.uid, `${nconf.get('url')}/uid/${uid}`);
|
||||||
|
assert.strictEqual(saved.content, 'Lorem ipsum dolor sit amet');
|
||||||
|
assert(saved.tid);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should properly save the topic title in the topic hash', async () => {
|
||||||
|
assert.strictEqual(topic.title, 'Lipsum title');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should properly save the mainPid in the topic hash', async () => {
|
||||||
|
assert.strictEqual(topic.mainPid, note.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user