mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: rebroadcasting logic should only execute for local tids if the remote cid is not addressed already
This commit is contained in:
@@ -23,7 +23,8 @@ Feps.announce = async function announce(id, activity) {
|
||||
const tid = await posts.getPostField(localId || id, 'tid');
|
||||
const cid = await topics.getTopicField(tid, 'cid');
|
||||
const localCid = utils.isNumber(cid) && cid > 0;
|
||||
const shouldAnnounce = localCid || utils.isNumber(tid);
|
||||
const addressed = activitypub.helpers.addressed(cid, activity);
|
||||
const shouldAnnounce = localCid || (utils.isNumber(tid) && !addressed);
|
||||
if (!shouldAnnounce) { // inverse conditionals can kiss my ass.
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -526,3 +526,20 @@ Helpers.generateDigest = (set) => {
|
||||
return result.toString('hex');
|
||||
});
|
||||
};
|
||||
|
||||
Helpers.addressed = (id, activity) => {
|
||||
// Returns Boolean for if id is found in addressing fields (to, cc, etc.)
|
||||
if (!id || !activity || typeof activity !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const combined = new Set([
|
||||
...(activity.to || []),
|
||||
...(activity.cc || []),
|
||||
...(activity.bto || []),
|
||||
...(activity.bcc || []),
|
||||
...(activity.audience || []),
|
||||
]);
|
||||
|
||||
return combined.has(id);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user