1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-10 04:32:35 +01:00

Fix user settings not saving properly and guild folders

This commit is contained in:
Madeline 2022-10-28 19:23:02 +11:00
parent a75af3d9ff
commit 4c58a8bc24
No known key found for this signature in database
GPG Key ID: 1958E017C36F2E47
6 changed files with 2953 additions and 2057 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,9 +3,6 @@
{ {
"path": "src" "path": "src"
}, },
{
"path": "src-slowcord"
},
{ {
"path": "assets" "path": "assets"
}, },

View File

@ -1,5 +1,5 @@
import { Router, Response, Request } from "express"; import { Router, Response, Request } from "express";
import { User, UserSettings } from "@fosscord/util"; import { OrmUtils, User, UserSettingsSchema } from "@fosscord/util";
import { route } from "@fosscord/api"; import { route } from "@fosscord/api";
const router = Router(); const router = Router();
@ -16,14 +16,15 @@ router.patch(
"/", "/",
route({ body: "UserSettingsSchema" }), route({ body: "UserSettingsSchema" }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const body = req.body as UserSettings; const body = req.body as UserSettingsSchema;
if (body.locale === "en") body.locale = "en-US"; // fix discord client crash on unkown locale if (body.locale === "en") body.locale = "en-US"; // fix discord client crash on unkown locale
const user = await User.findOneOrFail({ const user = await User.findOneOrFail({
where: { id: req.user_id, bot: false }, where: { id: req.user_id, bot: false },
select: ["settings"]
}); });
user.settings = { ...user.settings, ...body }; user.settings = OrmUtils.mergeDeep(user.settings, body);
await user.save(); User.update({ id: user.id }, { settings: user.settings });
res.json(user.settings); res.json(user.settings);
}, },

View File

@ -453,10 +453,10 @@ export interface UserSettings {
gif_auto_play: boolean; gif_auto_play: boolean;
// every top guild is displayed as a "folder" // every top guild is displayed as a "folder"
guild_folders: { guild_folders: {
color: number; color?: number;
guild_ids: string[]; guild_ids: string[];
id: number; id?: number;
name: string; name?: string;
}[]; }[];
guild_positions: string[]; // guild ids ordered by position guild_positions: string[]; // guild ids ordered by position
inline_attachment_media: boolean; inline_attachment_media: boolean;

View File

@ -3,7 +3,7 @@ import { UserGuildSettings, ChannelOverride } from "@fosscord/util";
// This sucks. I would use a DeepPartial, my own or typeorms, but they both generate inncorect schema // This sucks. I would use a DeepPartial, my own or typeorms, but they both generate inncorect schema
export interface UserGuildSettingsSchema export interface UserGuildSettingsSchema
extends Partial<Omit<UserGuildSettings, "channel_overrides">> { extends Partial<Omit<UserGuildSettings, "channel_overrides">> {
channel_overrides: { channel_overrides?: {
[channel_id: string]: Partial<ChannelOverride>; [channel_id: string]: Partial<ChannelOverride>;
}; };
} }

View File

@ -44,4 +44,5 @@ export * from "./ChannelPermissionOverwriteSchema";
export * from "./UserGuildSettingsSchema"; export * from "./UserGuildSettingsSchema";
export * from "./GatewayPayloadSchema"; export * from "./GatewayPayloadSchema";
export * from "./RolePositionUpdateSchema"; export * from "./RolePositionUpdateSchema";
export * from "./ChannelReorderSchema"; export * from "./ChannelReorderSchema";
export * from "./UserSettingsSchema";