summary refs log tree commit diff
path: root/api/src
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-21 17:35:04 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-21 17:35:04 +1000
commit60c8f3e6b2e7fc3b802d51222b4b0f5ae61ddd8c (patch)
tree748c4722dcd29ffb034de6ace75c861cf585bbfc /api/src
parentadd more default rights (diff)
downloadserver-60c8f3e6b2e7fc3b802d51222b4b0f5ae61ddd8c.tar.xz
fosscord-server/pulls/858
Diffstat (limited to 'api/src')
-rw-r--r--api/src/routes/channels/#channel_id/messages/#message_id/index.ts2
-rw-r--r--api/src/routes/channels/#channel_id/messages/index.ts23
-rw-r--r--api/src/routes/users/@me/settings.ts8
-rw-r--r--api/src/util/handlers/Message.ts5
4 files changed, 26 insertions, 12 deletions
diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/index.ts b/api/src/routes/channels/#channel_id/messages/#message_id/index.ts
index 63fee9b9..37734397 100644
--- a/api/src/routes/channels/#channel_id/messages/#message_id/index.ts
+++ b/api/src/routes/channels/#channel_id/messages/#message_id/index.ts
@@ -135,7 +135,7 @@ router.put(
 			embeds,
 			channel_id,
 			attachments,
-			edited_timestamp: undefined,
+			edited_timestamp: null,
 			timestamp: new Date(snowflake.timestamp),
 		});
 
diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/api/src/routes/channels/#channel_id/messages/index.ts
index 849968f9..f3c3503f 100644
--- a/api/src/routes/channels/#channel_id/messages/index.ts
+++ b/api/src/routes/channels/#channel_id/messages/index.ts
@@ -13,7 +13,8 @@ import {
 	MessageCreateEvent,
 	Snowflake,
 	uploadFile,
-	Member
+	Member,
+	Role,
 } from "@fosscord/util";
 import { HTTPError } from "lambert-server";
 import { handleMessage, postHandleMessage, route } from "@fosscord/api";
@@ -146,11 +147,11 @@ router.get("/", async (req: Request, res: Response) => {
 			Some clients ( discord.js ) only check if a property exists within the response,
 			which causes erorrs when, say, the `application` property is `null`.
 			**/
-			
-			for (var curr in x) {
-				if (x[curr] === null)
-					delete x[curr];
-			}
+
+			// for (var curr in x) {
+			// 	if (x[curr] === null)
+			// 		delete x[curr];
+			// }
 
 			return x;
 		})
@@ -217,7 +218,7 @@ router.post(
 			embeds,
 			channel_id,
 			attachments,
-			edited_timestamp: undefined,
+			edited_timestamp: null,
 			timestamp: new Date()
 		});
 
@@ -244,8 +245,12 @@ router.post(
 			);
 		}
 	
-		//Fix for the client bug
-		delete message.member
+		const member = await Member.findOneOrFail({ where: { id: req.user_id }, relations: ["roles"] });
+		member.roles = member.roles.filter((role: Role) => {
+			return role.id !== role.guild_id;
+		}).map((role: Role) => {
+			return role.id;
+		}) as any;
 		
 		await Promise.all([
 			message.save(),
diff --git a/api/src/routes/users/@me/settings.ts b/api/src/routes/users/@me/settings.ts
index b22b72fb..50a00cac 100644
--- a/api/src/routes/users/@me/settings.ts
+++ b/api/src/routes/users/@me/settings.ts
@@ -6,6 +6,14 @@ const router = Router();
 
 export interface UserSettingsSchema extends Partial<UserSettings> {}
 
+router.get("/", route({}), async (req: Request, res: Response) => {
+	const user = await User.findOneOrFail(
+		{ id: req.user_id },
+		{ relations: ["settings"] }
+	)
+	return res.json(user.settings);
+});
+
 router.patch("/", route({ body: "UserSettingsSchema" }), async (req: Request, res: Response) => {
 	const body = req.body as UserSettings;
 	if (body.locale === "en") body.locale = "en-US"; // fix discord client crash on unkown locale
diff --git a/api/src/util/handlers/Message.ts b/api/src/util/handlers/Message.ts
index a6754bd1..8980b4cc 100644
--- a/api/src/util/handlers/Message.ts
+++ b/api/src/util/handlers/Message.ts
@@ -55,7 +55,8 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
 		attachments: opts.attachments || [],
 		embeds: opts.embeds || [],
 		reactions: /*opts.reactions ||*/[],
-		type: opts.type ?? 0
+		type: opts.type ?? 0,
+		edited_timestamp: null
 	});
 
 	if (message.content && message.content.length > Config.get().limits.message.maxCharacters) {
@@ -278,6 +279,6 @@ interface MessageOptions extends MessageCreateSchema {
 	embeds?: Embed[];
 	channel_id?: string;
 	attachments?: Attachment[];
-	edited_timestamp?: Date;
+	edited_timestamp: Date | null;
 	timestamp?: Date;
 }