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;
} }
// 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 = 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,6 +159,7 @@ inbox.announce = async (req) => {
winston.info(`[activitypub/inbox/announce] Parsing id ${pid}`); winston.info(`[activitypub/inbox/announce] Parsing id ${pid}`);
if (!cid) { // Topic events from actors followed by users only
// 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',
@@ -170,6 +177,7 @@ inbox.announce = async (req) => {
pid, pid,
timestamp, timestamp,
}); });
}
}; };
inbox.follow = async (req) => { inbox.follow = async (req) => {