fix: bring back auto-categorization if group and object are same-origin, handle Peertube putting channel names in attributedTo

This commit is contained in:
Julian Lam
2025-05-15 15:38:57 -04:00
parent 3674fa5783
commit a460a55064
2 changed files with 24 additions and 4 deletions

View File

@@ -42,7 +42,7 @@ const sanitizeConfig = {
Mocks._normalize = async (object) => { Mocks._normalize = async (object) => {
// Normalized incoming AP objects into expected types for easier mocking // Normalized incoming AP objects into expected types for easier mocking
let { type, attributedTo, url, image, mediaType, content, source, attachment } = object; let { type, attributedTo, url, image, mediaType, content, source, attachment, cc } = object;
switch (true) { // non-string attributedTo handling switch (true) { // non-string attributedTo handling
case Array.isArray(attributedTo): { case Array.isArray(attributedTo): {
@@ -52,6 +52,10 @@ Mocks._normalize = async (object) => {
} else if (typeof cur === 'object') { } else if (typeof cur === 'object') {
if (cur.type === 'Person' && cur.id) { if (cur.type === 'Person' && cur.id) {
valid.push(cur.id); valid.push(cur.id);
} else if (cur.type === 'Group' && cur.id) {
// Add any groups found to cc where it is expected
cc = Array.isArray(cc) ? cc : [cc];
cc.push(cur.id);
} }
} }
@@ -148,6 +152,7 @@ Mocks._normalize = async (object) => {
return { return {
...object, ...object,
cc,
attributedTo, attributedTo,
content, content,
sourceContent, sourceContent,

View File

@@ -115,18 +115,33 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
if (hasTid) { if (hasTid) {
mainPid = await topics.getTopicField(tid, 'mainPid'); mainPid = await topics.getTopicField(tid, 'mainPid');
} else { } else {
// Check recipients/audience for local category // Check recipients/audience for category (local or remote)
const set = activitypub.helpers.makeSet(_activitypub, ['to', 'cc', 'audience']); const set = activitypub.helpers.makeSet(_activitypub, ['to', 'cc', 'audience']);
await activitypub.actors.assert(Array.from(set)); await activitypub.actors.assert(Array.from(set));
// Local
const resolved = await Promise.all(Array.from(set).map(async id => await activitypub.helpers.resolveLocalId(id))); const resolved = await Promise.all(Array.from(set).map(async id => await activitypub.helpers.resolveLocalId(id)));
const recipientCids = resolved const recipientCids = resolved
.filter(Boolean) .filter(Boolean)
.filter(({ type }) => type === 'category') .filter(({ type }) => type === 'category')
.map(obj => obj.id); .map(obj => obj.id);
if (recipientCids.length) { // Remote
let remoteCid;
const assertedGroups = await categories.exists(Array.from(set));
try {
const { hostname } = new URL(mainPid);
remoteCid = Array.from(set).filter((id, idx) => {
const { hostname: cidHostname } = new URL(id);
return assertedGroups[idx] && cidHostname === hostname;
}).shift();
} catch (e) {
// noop
}
if (remoteCid || recipientCids.length) {
// Overrides passed-in value, respect addressing from main post over booster // Overrides passed-in value, respect addressing from main post over booster
options.cid = recipientCids.shift(); options.cid = remoteCid || recipientCids.shift();
} }
// mainPid ok to leave as-is // mainPid ok to leave as-is