forked from shadowfacts/shadowfacts.net
Deduplicate inboxes when federating activities
This commit is contained in:
parent
d0663a17e7
commit
63c679d859
|
@ -130,16 +130,19 @@ export async function signAndSend(activity: Activity, inbox: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendToFollowers(activity: Create, db: Database) {
|
async function sendToFollowers(activity: Create, db: Database) {
|
||||||
// TODO: only send to unique inboxes
|
db.all("SELECT inbox FROM followers", (err, results) => {
|
||||||
db.each("SELECT inbox FROM followers", (err, result) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("Error getting followers: ", err);
|
console.log("Error getting followers: ", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const inbox = "https://" + new URL(result.inbox).host + "/inbox";
|
const inboxes = results.map(it => "https://" + new URL(it.inbox).host + "/inbox");
|
||||||
|
// convert to a Set to deduplicate inboxes
|
||||||
|
(new Set(inboxes))
|
||||||
|
.forEach(inbox => {
|
||||||
console.log(`Federating ${activity.object.id} to ${inbox}`);
|
console.log(`Federating ${activity.object.id} to ${inbox}`);
|
||||||
signAndSend(activity, inbox);
|
signAndSend(activity, inbox);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function federate(toFederate: [string, Article][], db: Database) {
|
export default function federate(toFederate: [string, Article][], db: Database) {
|
||||||
|
|
Loading…
Reference in New Issue