summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2024-07-09 15:29:31 +1000
committerGitHub <noreply@github.com>2024-07-09 15:29:31 +1000
commit71b07b9ba2d0375c5c0fcafc89dbb7dabca2ee81 (patch)
tree49339bcc61fe0e6ae3749a21f388c460c1dcc90e /src
parentadd email verification page (diff)
parentMerge branch 'master' into feat/new-msg-props (diff)
downloadserver-ts-71b07b9ba2d0375c5c0fcafc89dbb7dabca2ee81.tar.xz
Merge pull request #1135 from DEVTomatoCake/feat/new-msg-props
Diffstat (limited to 'src')
-rw-r--r--src/api/routes/channels/#channel_id/messages/#message_id/crosspost.ts7
-rw-r--r--src/api/routes/guilds/#guild_id/messages/search.ts7
-rw-r--r--src/api/util/handlers/Message.ts33
-rw-r--r--src/util/entities/Message.ts40
-rw-r--r--src/util/migration/mariadb/1720157926878-messagePollObject.ts13
-rw-r--r--src/util/migration/mysql/1720157926878-messagePollObject.ts13
-rw-r--r--src/util/migration/postgres/1720157926878-messagePollObject.ts13
-rw-r--r--src/util/schemas/MessageCreateSchema.ts27
-rw-r--r--src/util/schemas/responses/GuildMessagesSearchResponse.ts11
9 files changed, 129 insertions, 35 deletions
diff --git a/src/api/routes/channels/#channel_id/messages/#message_id/crosspost.ts b/src/api/routes/channels/#channel_id/messages/#message_id/crosspost.ts

index 5ca645c00..6362941c6 100644 --- a/src/api/routes/channels/#channel_id/messages/#message_id/crosspost.ts +++ b/src/api/routes/channels/#channel_id/messages/#message_id/crosspost.ts
@@ -1,17 +1,17 @@ /* Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Copyright (C) 2023 Spacebar and Spacebar Contributors - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ @@ -56,6 +56,7 @@ router.post( edited_timestamp: null, flags: 1, components: [], + poll: {}, }).status(200); }, ); diff --git a/src/api/routes/guilds/#guild_id/messages/search.ts b/src/api/routes/guilds/#guild_id/messages/search.ts
index 637d1e438..94adf9c6a 100644 --- a/src/api/routes/guilds/#guild_id/messages/search.ts +++ b/src/api/routes/guilds/#guild_id/messages/search.ts
@@ -1,17 +1,17 @@ /* Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Copyright (C) 2023 Spacebar and Spacebar Contributors - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ @@ -162,6 +162,7 @@ router.get( edited_timestamp: x.edited_timestamp, flags: x.flags, components: x.components, + poll: x.poll, hit: true, }, ]); diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts
index 85db26b27..64bcdd567 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts
@@ -16,36 +16,36 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import * as Sentry from "@sentry/node"; +import { EmbedHandlers } from "@spacebar/api"; import { + Application, + Attachment, Channel, + Config, Embed, + EmbedCache, emitEvent, + EVERYONE_MENTION, + getPermission, + getRights, Guild, + HERE_MENTION, Message, MessageCreateEvent, + MessageCreateSchema, + MessageType, MessageUpdateEvent, - getPermission, - getRights, - //CHANNEL_MENTION, - USER_MENTION, - ROLE_MENTION, Role, - EVERYONE_MENTION, - HERE_MENTION, - MessageType, + ROLE_MENTION, + Sticker, User, - Application, + //CHANNEL_MENTION, + USER_MENTION, Webhook, - Attachment, - Config, - Sticker, - MessageCreateSchema, - EmbedCache, } from "@spacebar/util"; import { HTTPError } from "lambert-server"; import { In } from "typeorm"; -import { EmbedHandlers } from "@spacebar/api"; -import * as Sentry from "@sentry/node"; const allow_empty = false; // TODO: check webhook, application, system author, stickers // TODO: embed gifs/videos/images @@ -66,6 +66,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { : undefined; const message = Message.create({ ...opts, + poll: opts.poll ? [opts.poll] : undefined, sticker_items: stickers, guild_id: channel.guild_id, channel_id: opts.channel_id, diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts
index 4a9cff4ab..a76ebb1f9 100644 --- a/src/util/entities/Message.ts +++ b/src/util/entities/Message.ts
@@ -1,17 +1,17 @@ /* Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Copyright (C) 2023 Spacebar and Spacebar Contributors - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ @@ -218,6 +218,9 @@ export class Message extends BaseClass { @Column({ type: "simple-json", nullable: true }) components?: MessageComponent[]; + @Column({ type: "simple-json", nullable: true }) + poll?: Poll[]; + toJSON(): Message { return { ...this, @@ -238,6 +241,7 @@ export class Message extends BaseClass { activity: this.activity ?? undefined, application: this.application ?? undefined, components: this.components ?? undefined, + poll: this.poll ?? undefined, content: this.content ?? "", }; } @@ -249,6 +253,7 @@ export interface MessageComponent { label?: string; emoji?: PartialEmoji; custom_id?: string; + sku_id?: string; url?: string; disabled?: boolean; components: MessageComponent[]; @@ -327,3 +332,32 @@ export interface AllowedMentions { users?: string[]; replied_user?: boolean; } + +export interface Poll { + question: PollMedia; + answers: PollAnswer[]; + expiry: Date; + allow_multiselect: boolean; + results?: PollResult; +} + +export interface PollMedia { + text?: string; + emoji?: PartialEmoji; +} + +export interface PollAnswer { + answer_id?: string; + poll_media: PollMedia; +} + +export interface PollResult { + is_finalized: boolean; + answer_counts: PollAnswerCount[]; +} + +export interface PollAnswerCount { + id: string; + count: number; + me_voted: boolean; +} diff --git a/src/util/migration/mariadb/1720157926878-messagePollObject.ts b/src/util/migration/mariadb/1720157926878-messagePollObject.ts new file mode 100644
index 000000000..c08664264 --- /dev/null +++ b/src/util/migration/mariadb/1720157926878-messagePollObject.ts
@@ -0,0 +1,13 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class MessagePollObject1720157926878 implements MigrationInterface { + name = "MessagePollObject1720157926878"; + + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query("ALTER TABLE `messages` ADD `poll` text NULL"); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query("ALTER TABLE `messages` DROP COLUMN `poll`"); + } +} diff --git a/src/util/migration/mysql/1720157926878-messagePollObject.ts b/src/util/migration/mysql/1720157926878-messagePollObject.ts new file mode 100644
index 000000000..c08664264 --- /dev/null +++ b/src/util/migration/mysql/1720157926878-messagePollObject.ts
@@ -0,0 +1,13 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class MessagePollObject1720157926878 implements MigrationInterface { + name = "MessagePollObject1720157926878"; + + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query("ALTER TABLE `messages` ADD `poll` text NULL"); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query("ALTER TABLE `messages` DROP COLUMN `poll`"); + } +} diff --git a/src/util/migration/postgres/1720157926878-messagePollObject.ts b/src/util/migration/postgres/1720157926878-messagePollObject.ts new file mode 100644
index 000000000..7c3c95a0f --- /dev/null +++ b/src/util/migration/postgres/1720157926878-messagePollObject.ts
@@ -0,0 +1,13 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class MessagePollObject1720157926878 implements MigrationInterface { + name = "MessagePollObject1720157926878"; + + public async up(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query("ALTER TABLE messages ADD poll text NULL"); + } + + public async down(queryRunner: QueryRunner): Promise<void> { + await queryRunner.query("ALTER TABLE messages DROP COLUMN poll"); + } +} diff --git a/src/util/schemas/MessageCreateSchema.ts b/src/util/schemas/MessageCreateSchema.ts
index 57abf62f9..495e2ebd6 100644 --- a/src/util/schemas/MessageCreateSchema.ts +++ b/src/util/schemas/MessageCreateSchema.ts
@@ -1,22 +1,22 @@ /* Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Copyright (C) 2023 Spacebar and Spacebar Contributors - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { Embed } from "@spacebar/util"; +import { Embed, MessageComponent, PollAnswer, PollMedia } from "@spacebar/util"; type Attachment = { id: string; @@ -54,6 +54,21 @@ export interface MessageCreateSchema { **/ attachments?: Attachment[]; sticker_ids?: string[]; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - components?: any[]; + components?: MessageComponent[]; + // TODO: Fix TypeScript errors in src\api\util\handlers\Message.ts once this is enabled + poll?: PollCreationSchema; + enforce_nonce?: boolean; // For Discord compatibility, it's the default behavior here + applied_tags?: string[]; // Not implemented yet, for webhooks in forums + thread_name?: string; // Not implemented yet, for webhooks + avatar_url?: string; // Not implemented yet, for webhooks +} + +// TypeScript complains once this is used above +// eslint-disable-next-line @typescript-eslint/no-unused-vars +interface PollCreationSchema { + question: PollMedia; + answers: PollAnswer[]; + duration?: number; + allow_multiselect?: boolean; + layout_type?: number; } diff --git a/src/util/schemas/responses/GuildMessagesSearchResponse.ts b/src/util/schemas/responses/GuildMessagesSearchResponse.ts
index b42aafd3c..6121983e0 100644 --- a/src/util/schemas/responses/GuildMessagesSearchResponse.ts +++ b/src/util/schemas/responses/GuildMessagesSearchResponse.ts
@@ -1,17 +1,17 @@ /* Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Copyright (C) 2023 Spacebar and Spacebar Contributors - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ @@ -19,7 +19,9 @@ import { Attachment, Embed, + MessageComponent, MessageType, + Poll, PublicUser, Role, } from "../../entities"; @@ -40,7 +42,8 @@ export interface GuildMessagesSearchMessage { timestamp: string; edited_timestamp: string | null; flags: number; - components: unknown[]; + components: MessageComponent[]; + poll: Poll; hit: true; }