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 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'))) {
// Local object
const { type, id } = await activitypub.helpers.resolveLocalId(object.id);
@@ -129,18 +135,18 @@ inbox.announce = async (req) => {
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 = await activitypub.resolveId(0, pid); // in case wrong id is passed-in; unlikely, but still.
if (!pid) {
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.
if (!tid) {
return;
@@ -153,6 +159,7 @@ inbox.announce = async (req) => {
winston.info(`[activitypub/inbox/announce] Parsing id ${pid}`);
if (!cid) { // Topic events from actors followed by users only
// No double-announce allowed
const existing = await topics.events.find(tid, {
type: 'announce',
@@ -170,6 +177,7 @@ inbox.announce = async (req) => {
pid,
timestamp,
});
}
};
inbox.follow = async (req) => {