summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-15 00:03:05 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-15 00:03:05 +0200
commit0ccc478c54f6e6ae8c8e6574e24ab6796738c83a (patch)
tree5c00a5469e3e3a1c2be788b1138707065bb302bd
parent:sparkles: sticker upload (diff)
downloadserver-0ccc478c54f6e6ae8c8e6574e24ab6796738c83a.tar.xz
:bug: fix message sticker sending
-rw-r--r--api/client_test/index.html4
-rw-r--r--api/src/routes/channels/#channel_id/messages/index.ts1
-rw-r--r--api/src/routes/guilds/#guild_id/premium.ts10
-rw-r--r--api/src/util/Message.ts5
-rw-r--r--util/src/entities/Message.ts2
5 files changed, 18 insertions, 4 deletions
diff --git a/api/client_test/index.html b/api/client_test/index.html
index 20b431b8..5a795253 100644
--- a/api/client_test/index.html
+++ b/api/client_test/index.html
@@ -37,6 +37,7 @@
 				HTML_TIMESTAMP: Date.now(),
 				ALGOLIA_KEY: "aca0d7082e4e63af5ba5917d5e96bed0"
 			};
+			GLOBAL_ENV.MEDIA_PROXY_ENDPOINT = location.protocol + "//" + GLOBAL_ENV.CDN_HOST;
 			const localStorage = window.localStorage;
 			// TODO: remote auth
 			// window.GLOBAL_ENV.REMOTE_AUTH_ENDPOINT = window.GLOBAL_ENV.GATEWAY_ENDPOINT.replace(/wss?:/, "");
@@ -105,7 +106,8 @@
 			}
 
 			const settings = JSON.parse(localStorage.getItem("UserSettingsStore"));
-			if (settings && settings.locale === "en") {
+			if (settings && settings.locale.length <= 2) {
+				// fix client locale wrong and client not loading at all
 				settings.locale = "en-US";
 				localStorage.setItem("UserSettingsStore", JSON.stringify(settings));
 			}
diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/api/src/routes/channels/#channel_id/messages/index.ts
index 26bb9e5d..20c102ef 100644
--- a/api/src/routes/channels/#channel_id/messages/index.ts
+++ b/api/src/routes/channels/#channel_id/messages/index.ts
@@ -63,6 +63,7 @@ export interface MessageCreateSchema {
 	payload_json?: string;
 	file?: any;
 	attachments?: any[]; //TODO we should create an interface for attachments
+	sticker_ids?: string[];
 }
 
 // https://discord.com/developers/docs/resources/channel#create-message
diff --git a/api/src/routes/guilds/#guild_id/premium.ts b/api/src/routes/guilds/#guild_id/premium.ts
new file mode 100644
index 00000000..75361ac6
--- /dev/null
+++ b/api/src/routes/guilds/#guild_id/premium.ts
@@ -0,0 +1,10 @@
+import { Router, Request, Response } from "express";
+import { route } from "@fosscord/api";
+const router = Router();
+
+router.get("/subscriptions", route({}), async (req: Request, res: Response) => {
+	// TODO:
+	res.json([]);
+});
+
+export default router;
diff --git a/api/src/util/Message.ts b/api/src/util/Message.ts
index 40d96b42..d14d3aa2 100644
--- a/api/src/util/Message.ts
+++ b/api/src/util/Message.ts
@@ -24,7 +24,7 @@ import fetch from "node-fetch";
 import cheerio from "cheerio";
 import { MessageCreateSchema } from "../routes/channels/#channel_id/messages";
 
-// TODO: check webhook, application, system author
+// TODO: check webhook, application, system author, stickers
 // TODO: embed gifs/videos/images
 
 const LINK_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g;
@@ -46,6 +46,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
 
 	const message = new Message({
 		...opts,
+		sticker_items: opts.sticker_ids?.map((x) => ({ id: x })),
 		guild_id: channel.guild_id,
 		channel_id: opts.channel_id,
 		attachments: opts.attachments || [],
@@ -82,7 +83,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
 	}
 
 	// TODO: stickers/activity
-	if (!opts.content && !opts.embeds?.length && !opts.attachments?.length) {
+	if (!opts.content && !opts.embeds?.length && !opts.attachments?.length && !opts.sticker_ids?.length) {
 		throw new HTTPError("Empty messages are not allowed", 50006);
 	}
 
diff --git a/util/src/entities/Message.ts b/util/src/entities/Message.ts
index 63cd6ad3..a4d38315 100644
--- a/util/src/entities/Message.ts
+++ b/util/src/entities/Message.ts
@@ -127,7 +127,7 @@ export class Message extends BaseClass {
 	mention_channels: Channel[];
 
 	@JoinTable({ name: "message_stickers" })
-	@ManyToMany(() => Sticker)
+	@ManyToMany(() => Sticker, { cascade: true, onDelete: "CASCADE" })
 	sticker_items?: Sticker[];
 
 	@OneToMany(() => Attachment, (attachment: Attachment) => attachment.message, {