mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-14 16:15:18 +00:00
feat: add message forwards (normal messages only)
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -232,7 +232,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
|
||||
if (!opts.message_reference.guild_id) opts.message_reference.guild_id = channel.guild_id;
|
||||
if (!opts.message_reference.channel_id) opts.message_reference.channel_id = opts.channel_id;
|
||||
|
||||
if (!guild.features.includes("CROSS_CHANNEL_REPLIES")) {
|
||||
if (opts.message_reference.type != 1) {
|
||||
if (opts.message_reference.guild_id !== channel.guild_id) throw new HTTPError("You can only reference messages from this guild");
|
||||
if (opts.message_reference.channel_id !== opts.channel_id) throw new HTTPError("You can only reference messages from this channel");
|
||||
}
|
||||
@@ -257,7 +257,16 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
|
||||
}
|
||||
|
||||
// TODO: stickers/activity
|
||||
if (!allow_empty && !opts.content && !opts.embeds?.length && !opts.attachments?.length && !opts.sticker_ids?.length && !opts.poll && !opts.components?.length) {
|
||||
if (
|
||||
!allow_empty &&
|
||||
!opts.content &&
|
||||
!opts.embeds?.length &&
|
||||
!opts.attachments?.length &&
|
||||
!opts.sticker_ids?.length &&
|
||||
!opts.poll &&
|
||||
!opts.components?.length &&
|
||||
opts.message_reference?.type != 1
|
||||
) {
|
||||
console.log("[Message] Rejecting empty message:", opts, message);
|
||||
throw new HTTPError("Empty messages are not allowed", 50006);
|
||||
}
|
||||
@@ -314,6 +323,33 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// FORWARD
|
||||
if (message.message_reference.type === 1) {
|
||||
message.type = MessageType.DEFAULT;
|
||||
|
||||
if (message.referenced_message) {
|
||||
const mention_roles: string[] = [];
|
||||
const mentions: string[] = [];
|
||||
|
||||
message.message_snapshots = [
|
||||
{
|
||||
message: {
|
||||
attachments: message.referenced_message.attachments,
|
||||
components: message.referenced_message.components,
|
||||
content: message.referenced_message.content!,
|
||||
edited_timestamp: message.referenced_message.edited_timestamp,
|
||||
embeds: message.referenced_message.embeds,
|
||||
flags: message.referenced_message.flags,
|
||||
mention_roles,
|
||||
mentions,
|
||||
timestamp: message.referenced_message.timestamp,
|
||||
type: message.referenced_message.type,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// root@Rory - 20/02/2023 - This breaks channel mentions in test client. We're not sure this was used in older clients.
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { PartialUser, Snowflake } from "@spacebar/schemas";
|
||||
import { Attachment, Sticker } from "@spacebar/util";
|
||||
import { Embed, MessageComponent, PartialUser, Snowflake } from "@spacebar/schemas";
|
||||
|
||||
export enum MessageType {
|
||||
DEFAULT = 0,
|
||||
@@ -94,3 +95,21 @@ export interface AllowedMentions {
|
||||
users?: Snowflake[];
|
||||
replied_user?: boolean;
|
||||
}
|
||||
|
||||
export interface MessageSnapshot {
|
||||
message: {
|
||||
content: string;
|
||||
timestamp: Date;
|
||||
edited_timestamp?: Date | null;
|
||||
mentions: Snowflake[];
|
||||
mention_roles: Snowflake[];
|
||||
attachments?: Attachment[];
|
||||
embeds: Embed[];
|
||||
type: MessageType;
|
||||
flags: number;
|
||||
components?: MessageComponent[];
|
||||
resolved?: object[];
|
||||
sticker_items?: Sticker[];
|
||||
// soundboard_sounds?: object[]; // TODO: when soundboard is done
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ export interface MessageCreateSchema {
|
||||
channel_id?: string;
|
||||
guild_id?: string;
|
||||
fail_if_not_exists?: boolean;
|
||||
type?: number;
|
||||
};
|
||||
payload_json?: string;
|
||||
file?: { filename: string };
|
||||
|
||||
@@ -29,7 +29,7 @@ import { Webhook } from "./Webhook";
|
||||
import { Sticker } from "./Sticker";
|
||||
import { Attachment } from "./Attachment";
|
||||
import { NewUrlUserSignatureData } from "../Signing";
|
||||
import { ActionRowComponent, ApplicationCommandType, Embed, MessageType, PartialMessage, Poll, Reaction } from "@spacebar/schemas";
|
||||
import { ActionRowComponent, ApplicationCommandType, Embed, MessageSnapshot, MessageType, PartialMessage, Poll, Reaction } from "@spacebar/schemas";
|
||||
import { MessageFlags } from "@spacebar/util";
|
||||
|
||||
@Entity({
|
||||
@@ -202,6 +202,9 @@ export class Message extends BaseClass {
|
||||
@Column({ nullable: true })
|
||||
avatar?: string;
|
||||
|
||||
@Column({ default: "[]", type: "simple-json" })
|
||||
message_snapshots: MessageSnapshot[];
|
||||
|
||||
toJSON(): Message {
|
||||
return {
|
||||
...this,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class MessageSnapshots1765185286988 implements MigrationInterface {
|
||||
name = "MessageSnapshots1765185286988";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "messages" ADD "message_snapshots" text NOT NULL DEFAULT '[]'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "messages" DROP COLUMN "message_snapshots"`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user