mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
feat: handle Announce(Note) when Note is a piece of remote content
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
|
const nconf = require('nconf');
|
||||||
|
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
@@ -75,35 +76,40 @@ inbox.announce = async (req) => {
|
|||||||
// ok to fail
|
// ok to fail
|
||||||
}
|
}
|
||||||
|
|
||||||
const { type, id } = await activitypub.helpers.resolveLocalId(object);
|
|
||||||
if (type !== 'post' || !(await posts.exists(id))) {
|
|
||||||
throw new Error('[[error:activitypub.invalid-id]]');
|
|
||||||
}
|
|
||||||
|
|
||||||
const assertion = await activitypub.actors.assert(actor);
|
const assertion = await activitypub.actors.assert(actor);
|
||||||
if (!assertion) {
|
if (!assertion) {
|
||||||
throw new Error('[[error:activitypub.invalid-id]]');
|
throw new Error('[[error:activitypub.invalid-id]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
const tid = await posts.getPostField(id, 'tid');
|
if (String(object).startsWith(nconf.get('url'))) {
|
||||||
|
const { type, id } = await activitypub.helpers.resolveLocalId(object);
|
||||||
|
if (type !== 'post' || !(await posts.exists(id))) {
|
||||||
|
throw new Error('[[error:activitypub.invalid-id]]');
|
||||||
|
}
|
||||||
|
|
||||||
// No double-announce allowed
|
const tid = await posts.getPostField(id, 'tid');
|
||||||
const existing = await topics.events.find(tid, {
|
|
||||||
type: 'announce',
|
// No double-announce allowed
|
||||||
uid: actor,
|
const existing = await topics.events.find(tid, {
|
||||||
pid: id,
|
type: 'announce',
|
||||||
});
|
uid: actor,
|
||||||
if (existing.length) {
|
pid: id,
|
||||||
await topics.events.purge(tid, existing);
|
});
|
||||||
|
if (existing.length) {
|
||||||
|
await topics.events.purge(tid, existing);
|
||||||
|
}
|
||||||
|
|
||||||
|
await topics.events.log(tid, {
|
||||||
|
type: 'announce',
|
||||||
|
uid: actor,
|
||||||
|
href: `/post/${id}`,
|
||||||
|
pid: id,
|
||||||
|
timestamp,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const tid = await activitypub.notes.assertTopic(0, object);
|
||||||
|
await topics.updateLastPostTime(tid, timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
await topics.events.log(tid, {
|
|
||||||
type: 'announce',
|
|
||||||
uid: actor,
|
|
||||||
href: `/post/${id}`,
|
|
||||||
pid: id,
|
|
||||||
timestamp,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inbox.follow = async (req) => {
|
inbox.follow = async (req) => {
|
||||||
|
|||||||
@@ -237,15 +237,3 @@ ActivityPub.send = async (type, id, targets, payload) => {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
setTimeout(async () => {
|
|
||||||
await ActivityPub.send('uid', 1, 'https://localhost/uid/1', {
|
|
||||||
// type: 'Undo',
|
|
||||||
// object: {
|
|
||||||
type: 'Announce',
|
|
||||||
actor: `https://localhost/uid/1`,
|
|
||||||
object: 'https://localhost/post/1',
|
|
||||||
published: new Date().toISOString(),
|
|
||||||
// },
|
|
||||||
});
|
|
||||||
}, 2000);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user