mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
feat(federation): ✨ Federate user profile changes to other instances
This commit is contained in:
parent
f8196f72f9
commit
4c22b0edcc
|
|
@ -14,6 +14,7 @@ import {
|
||||||
gte,
|
gte,
|
||||||
inArray,
|
inArray,
|
||||||
isNull,
|
isNull,
|
||||||
|
sql,
|
||||||
} from "drizzle-orm";
|
} from "drizzle-orm";
|
||||||
import { htmlToText } from "html-to-text";
|
import { htmlToText } from "html-to-text";
|
||||||
import {
|
import {
|
||||||
|
|
@ -21,6 +22,7 @@ import {
|
||||||
emojiToLysand,
|
emojiToLysand,
|
||||||
fetchEmoji,
|
fetchEmoji,
|
||||||
} from "~/database/entities/Emoji";
|
} from "~/database/entities/Emoji";
|
||||||
|
import { objectToInboxRequest } from "~/database/entities/Federation";
|
||||||
import { addInstanceIfNotExists } from "~/database/entities/Instance";
|
import { addInstanceIfNotExists } from "~/database/entities/Instance";
|
||||||
import {
|
import {
|
||||||
type UserWithRelations,
|
type UserWithRelations,
|
||||||
|
|
@ -202,7 +204,9 @@ export class User {
|
||||||
|
|
||||||
async updateFromRemote() {
|
async updateFromRemote() {
|
||||||
if (!this.isRemote()) {
|
if (!this.isRemote()) {
|
||||||
throw new Error("Cannot update local user from remote");
|
throw new Error(
|
||||||
|
"Cannot refetch a local user (they are not remote)",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const updated = await User.saveFromRemote(this.getUri());
|
const updated = await User.saveFromRemote(this.getUri());
|
||||||
|
|
@ -500,6 +504,38 @@ export class User {
|
||||||
|
|
||||||
this.user = newUser.getUser();
|
this.user = newUser.getUser();
|
||||||
|
|
||||||
|
// If something important is updated, federate it
|
||||||
|
if (
|
||||||
|
data.username ||
|
||||||
|
data.displayName ||
|
||||||
|
data.note ||
|
||||||
|
data.avatar ||
|
||||||
|
data.header ||
|
||||||
|
data.fields ||
|
||||||
|
data.publicKey ||
|
||||||
|
data.isAdmin ||
|
||||||
|
data.isBot ||
|
||||||
|
data.isLocked ||
|
||||||
|
data.endpoints ||
|
||||||
|
data.isDiscoverable
|
||||||
|
) {
|
||||||
|
// Get followers
|
||||||
|
const followers = await User.manyFromSql(
|
||||||
|
sql`EXISTS (SELECT 1 FROM "Relationships" WHERE "Relationships"."subjectId" = ${Users.id} AND "Relationships"."ownerId" = ${this.id} AND "Relationships"."following" = true)`,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const follower of followers) {
|
||||||
|
const federationRequest = await objectToInboxRequest(
|
||||||
|
this.toLysand(),
|
||||||
|
this,
|
||||||
|
follower,
|
||||||
|
);
|
||||||
|
|
||||||
|
// FIXME: Add to new queue system when it's implemented
|
||||||
|
fetch(federationRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue