mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(federation): ♻️ Refactor User federation code
This commit is contained in:
parent
d638610361
commit
9ff9b90f6b
9 changed files with 152 additions and 180 deletions
|
|
@ -353,8 +353,7 @@ export default apiRoute((app) =>
|
|||
);
|
||||
}
|
||||
|
||||
await User.fromDataLocal({
|
||||
username,
|
||||
await User.register(username, {
|
||||
password,
|
||||
email,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -176,6 +176,15 @@ export default apiRoute((app) =>
|
|||
} = context.req.valid("json");
|
||||
|
||||
const self = user.data;
|
||||
if (!self.source) {
|
||||
self.source = {
|
||||
fields: [],
|
||||
privacy: "public",
|
||||
language: "en",
|
||||
sensitive: false,
|
||||
note: "",
|
||||
};
|
||||
}
|
||||
|
||||
const sanitizedDisplayName = await sanitizedHtmlStrip(
|
||||
display_name ?? "",
|
||||
|
|
@ -185,7 +194,7 @@ export default apiRoute((app) =>
|
|||
self.displayName = sanitizedDisplayName;
|
||||
}
|
||||
|
||||
if (note && self.source) {
|
||||
if (note) {
|
||||
self.source.note = note;
|
||||
self.note = await contentToHtml(
|
||||
new VersiaEntities.TextContentFormat({
|
||||
|
|
@ -197,16 +206,13 @@ export default apiRoute((app) =>
|
|||
);
|
||||
}
|
||||
|
||||
if (source?.privacy) {
|
||||
self.source.privacy = source.privacy;
|
||||
}
|
||||
|
||||
if (source?.sensitive) {
|
||||
self.source.sensitive = source.sensitive;
|
||||
}
|
||||
|
||||
if (source?.language) {
|
||||
self.source.language = source.language;
|
||||
if (source) {
|
||||
self.source = {
|
||||
...self.source,
|
||||
privacy: source.privacy ?? self.source.privacy,
|
||||
sensitive: source.sensitive ?? self.source.sensitive,
|
||||
language: source.language ?? self.source.language,
|
||||
};
|
||||
}
|
||||
|
||||
if (username) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ describe("/api/v1/accounts/verify_credentials", () => {
|
|||
expect(data.id).toBe(users[0].id);
|
||||
expect(data.username).toBe(users[0].data.username);
|
||||
expect(data.acct).toBe(users[0].data.username);
|
||||
expect(data.display_name).toBe(users[0].data.displayName);
|
||||
expect(data.display_name).toBe(users[0].data.displayName ?? "");
|
||||
expect(data.note).toBe(users[0].data.note);
|
||||
expect(data.url).toBe(
|
||||
new URL(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue