mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: record remote Announce(Note)
This commit is contained in:
@@ -81,19 +81,28 @@ inbox.announce = async (req) => {
|
|||||||
throw new Error('[[error:activitypub.invalid-id]]');
|
throw new Error('[[error:activitypub.invalid-id]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tid;
|
||||||
|
let pid;
|
||||||
|
|
||||||
if (String(object).startsWith(nconf.get('url'))) {
|
if (String(object).startsWith(nconf.get('url'))) {
|
||||||
const { type, id } = await activitypub.helpers.resolveLocalId(object);
|
const { type, id } = await activitypub.helpers.resolveLocalId(object);
|
||||||
if (type !== 'post' || !(await posts.exists(id))) {
|
if (type !== 'post' || !(await posts.exists(id))) {
|
||||||
throw new Error('[[error:activitypub.invalid-id]]');
|
throw new Error('[[error:activitypub.invalid-id]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
const tid = await posts.getPostField(id, 'tid');
|
pid = id;
|
||||||
|
tid = await posts.getPostField(id, 'tid');
|
||||||
|
} else {
|
||||||
|
pid = object;
|
||||||
|
tid = await activitypub.notes.assertTopic(0, object);
|
||||||
|
await topics.updateLastPostTime(tid, timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
// No double-announce allowed
|
// No double-announce allowed
|
||||||
const existing = await topics.events.find(tid, {
|
const existing = await topics.events.find(tid, {
|
||||||
type: 'announce',
|
type: 'announce',
|
||||||
uid: actor,
|
uid: actor,
|
||||||
pid: id,
|
pid,
|
||||||
});
|
});
|
||||||
if (existing.length) {
|
if (existing.length) {
|
||||||
await topics.events.purge(tid, existing);
|
await topics.events.purge(tid, existing);
|
||||||
@@ -102,14 +111,10 @@ inbox.announce = async (req) => {
|
|||||||
await topics.events.log(tid, {
|
await topics.events.log(tid, {
|
||||||
type: 'announce',
|
type: 'announce',
|
||||||
uid: actor,
|
uid: actor,
|
||||||
href: `/post/${id}`,
|
href: `/post/${pid}`,
|
||||||
pid: id,
|
pid,
|
||||||
timestamp,
|
timestamp,
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
const tid = await activitypub.notes.assertTopic(0, object);
|
|
||||||
await topics.updateLastPostTime(tid, timestamp);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inbox.follow = async (req) => {
|
inbox.follow = async (req) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user