feat: record remote Announce(Note)

This commit is contained in:
Julian Lam
2024-02-07 12:28:27 -05:00
parent ec2b375ae9
commit 6508287db5

View File

@@ -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) => {