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

Mostly working user guild settings

This commit is contained in:
Madeline 2022-09-25 11:10:27 +10:00
parent 170d048db2
commit 544ded68a3
4 changed files with 16284 additions and 1297 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,15 @@
import { Router, Response, Request } from "express";
import { Member, UserGuildSettings } from "@fosscord/util";
import { Channel, ChannelOverride, Member, UserGuildSettings } from "@fosscord/util";
import { route } from "@fosscord/api";
const router = Router();
export interface UserGuildSettingsSchema extends Partial<UserGuildSettings> { }
// This sucks. I would use a DeepPartial, my own or typeorms, but they both generate inncorect schema
export interface UserGuildSettingsSchema extends Partial<Omit<UserGuildSettings, 'channel_overrides'>> {
channel_overrides: {
[channel_id: string]: Partial<ChannelOverride>;
},
}
// GET doesn't exist on discord.com
router.get("/", route({}), async (req: Request, res: Response) => {
@ -15,9 +20,15 @@ router.get("/", route({}), async (req: Request, res: Response) => {
return res.json(user.settings);
});
router.patch("/", route({ body: "UserSettingsSchema" }), async (req: Request, res: Response) => {
router.patch("/", route({ body: "UserGuildSettingsSchema" }), async (req: Request, res: Response) => {
const body = req.body as UserGuildSettings;
if (body.channel_overrides) {
for (var channel in body.channel_overrides) {
Channel.findOneOrFail({ where: { id: channel } });
}
}
const user = await Member.findOneOrFail({ where: { id: req.user_id, guild_id: req.params.guild_id } });
user.settings = { ...user.settings, ...body };
await user.save();

View File

@ -18,6 +18,8 @@ import {
PrivateSessionProjection,
MemberPrivateProjection,
PresenceUpdateEvent,
DefaultUserGuildSettings,
UserGuildSettings,
} from "@fosscord/util";
import { Send } from "../util/Send";
import { CLOSECODES, OPCODES } from "../util/Constants";
@ -151,7 +153,16 @@ export async function onIdentify(this: WebSocket, data: Payload) {
return guild;
});
const user_guild_settings_entries = members.map((x) => x.settings);
const user_guild_settings_entries = members.map((x) => ({
...DefaultUserGuildSettings,
...x.settings,
guild_id: x.guild.id,
// disgusting
channel_overrides: Object.entries(x.settings.channel_overrides ?? {}).map(y => ({
...y[1],
channel_id: y[0],
}))
})) as any as UserGuildSettings[]; // VERY disgusting. don't care.
const channels = recipients.map((x) => {
// @ts-ignore

View File

@ -80,7 +80,7 @@ export class Member extends BaseClassWithoutId {
val = val.split("\t").join("");
if (BannedWords.find(val)) throw FieldErrors({ nick: { message: "Bad nickname", code: "INVALID_NICKNAME" } });
}
this.nick = val;
}
@ -339,20 +339,52 @@ export class Member extends BaseClassWithoutId {
}
}
export interface ChannelOverride {
message_notifications: number;
mute_config: MuteConfig;
muted: boolean;
channel_id: string | null;
}
export interface UserGuildSettings {
// channel_overrides: {
// channel_id: string;
// message_notifications: number;
// mute_config: MuteConfig;
// muted: boolean;
// }[];
channel_overrides: {
channel_id: string;
message_notifications: number;
mute_config: MuteConfig;
muted: boolean;
}[];
[channel_id: string]: ChannelOverride;
} | null,
message_notifications: number;
mobile_push: boolean;
mute_config: MuteConfig;
mute_config: MuteConfig | null;
muted: boolean;
suppress_everyone: boolean;
suppress_roles: boolean;
version: number;
guild_id: string | null;
flags: number;
mute_scheduled_events: boolean;
hide_muted_channels: boolean;
notify_highlights: 0;
}
export const DefaultUserGuildSettings: UserGuildSettings = {
channel_overrides: null,
message_notifications: 1,
flags: 0,
hide_muted_channels: false,
mobile_push: true,
mute_config: null,
mute_scheduled_events: false,
muted: false,
notify_highlights: 0,
suppress_everyone: false,
suppress_roles: false,
version: 453, // ?
guild_id: null,
}
export interface MuteConfig {