fix: handle Announce(Create(Note))

This commit is contained in:
Julian Lam
2024-04-17 12:55:15 -04:00
parent dce334461a
commit a9a7fd1ecd

View File

@@ -109,6 +109,12 @@ inbox.announce = async (req) => {
let tid; let tid;
let pid; let pid;
const { cids } = await activitypub.actors.getLocalFollowers(actor);
let cid = null;
if (cids.size > 0) {
cid = Array.from(cids)[0];
}
if (String(object.id).startsWith(nconf.get('url'))) { if (String(object.id).startsWith(nconf.get('url'))) {
// Local object // Local object
const { type, id } = await activitypub.helpers.resolveLocalId(object.id); const { type, id } = await activitypub.helpers.resolveLocalId(object.id);
@@ -129,18 +135,18 @@ inbox.announce = async (req) => {
return; return;
} }
pid = object.id; // Handle case where Announce(Create(Note)) is received
if (object.type === 'Create' && object.object.type === 'Note') {
pid = object.object.id;
} else {
pid = object.id;
}
pid = await activitypub.resolveId(0, pid); // in case wrong id is passed-in; unlikely, but still. pid = await activitypub.resolveId(0, pid); // in case wrong id is passed-in; unlikely, but still.
if (!pid) { if (!pid) {
return; return;
} }
const { cids } = await activitypub.actors.getLocalFollowers(actor);
let cid = null;
if (cids.size > 0) {
cid = Array.from(cids)[0];
}
({ tid } = await activitypub.notes.assert(0, pid, { cid, skipChecks: true })); // checks skipped; done above. ({ tid } = await activitypub.notes.assert(0, pid, { cid, skipChecks: true })); // checks skipped; done above.
if (!tid) { if (!tid) {
return; return;
@@ -153,23 +159,25 @@ inbox.announce = async (req) => {
winston.info(`[activitypub/inbox/announce] Parsing id ${pid}`); winston.info(`[activitypub/inbox/announce] Parsing id ${pid}`);
// No double-announce allowed if (!cid) { // Topic events from actors followed by users only
const existing = await topics.events.find(tid, { // No double-announce allowed
type: 'announce', const existing = await topics.events.find(tid, {
uid: actor, type: 'announce',
pid, uid: actor,
}); pid,
if (existing.length) { });
await topics.events.purge(tid, existing); if (existing.length) {
} await topics.events.purge(tid, existing);
}
await topics.events.log(tid, { await topics.events.log(tid, {
type: 'announce', type: 'announce',
uid: actor, uid: actor,
href: `/post/${encodeURIComponent(pid)}`, href: `/post/${encodeURIComponent(pid)}`,
pid, pid,
timestamp, timestamp,
}); });
}
}; };
inbox.follow = async (req) => { inbox.follow = async (req) => {