mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-29 09:49:13 +00:00
initial recipients work
This commit is contained in:
@@ -35,7 +35,7 @@ import { Request, Response, Router } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import multer from "multer";
|
||||
import { handleMessage, postHandleMessage, route } from "../../../../../util";
|
||||
import { MessageCreateAttachment, MessageCreateCloudAttachment, MessageCreateSchema, MessageEditSchema } from "@spacebar/schemas";
|
||||
import { MessageCreateAttachment, MessageCreateCloudAttachment, MessageCreateSchema, MessageEditSchema, ChannelType } from "@spacebar/schemas";
|
||||
|
||||
const router = Router({ mergeParams: true });
|
||||
// TODO: message content/embed string length limit
|
||||
@@ -293,6 +293,10 @@ router.delete(
|
||||
const channel = await Channel.findOneOrFail({
|
||||
where: { id: channel_id },
|
||||
});
|
||||
if (channel.type === ChannelType.GUILD_PUBLIC_THREAD) {
|
||||
if (channel.message_count !== undefined) channel.message_count--;
|
||||
channel.save(); //Save async, it's fine
|
||||
}
|
||||
const message = await Message.findOneOrFail({
|
||||
where: { id: message_id },
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
import { route, sendMessage } from "@spacebar/api";
|
||||
import { Message, Channel, emitEvent, User, MessageUpdateEvent } from "@spacebar/util";
|
||||
import { Message, Channel, emitEvent, User, MessageUpdateEvent, Recipient } from "@spacebar/util";
|
||||
import { MessageThreadCreationSchema, ChannelType, MessageType } from "@spacebar/schemas";
|
||||
|
||||
import { Request, Response, Router } from "express";
|
||||
@@ -48,6 +48,8 @@ router.post(
|
||||
where: { id: channel_id },
|
||||
});
|
||||
const user = await User.findOneOrFail({ where: { id: req.user_id } });
|
||||
const recipient = Recipient.create({ channel_id: message.id, user });
|
||||
|
||||
const thread = await Channel.createChannel(
|
||||
{
|
||||
id: message.id,
|
||||
@@ -61,6 +63,7 @@ router.post(
|
||||
guild_id: channel.guild_id,
|
||||
rate_limit_per_user: body.rate_limit_per_user,
|
||||
type: ChannelType.GUILD_PUBLIC_THREAD,
|
||||
recipients: [],
|
||||
thread_metadata: {
|
||||
archived: false,
|
||||
auto_archive_duration: body.auto_archive_duration || channel.default_auto_archive_duration || 4320,
|
||||
@@ -72,6 +75,9 @@ router.post(
|
||||
void 0,
|
||||
{ skipPermissionCheck: true, keepId: true, skipEventEmit: true },
|
||||
);
|
||||
|
||||
recipient.save();
|
||||
|
||||
message.thread = thread;
|
||||
message.flags ||= 1 << 5;
|
||||
await sendMessage({
|
||||
|
||||
@@ -137,7 +137,11 @@ router.get(
|
||||
sticker_items: true,
|
||||
attachments: true,
|
||||
},
|
||||
thread: true,
|
||||
thread: {
|
||||
recipients: {
|
||||
user: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -247,6 +251,7 @@ router.get(
|
||||
|
||||
return x;
|
||||
});
|
||||
//console.log(ret);
|
||||
|
||||
await Promise.all(
|
||||
ret
|
||||
@@ -410,8 +415,6 @@ router.post(
|
||||
//@ts-ignore dont care2
|
||||
message.edited_timestamp = null;
|
||||
|
||||
channel.last_message_id = message.id;
|
||||
|
||||
if (channel.isDm()) {
|
||||
const channel_dto = await DmChannelDTO.from(channel);
|
||||
|
||||
@@ -465,7 +468,6 @@ router.post(
|
||||
data: message,
|
||||
} as MessageCreateEvent),
|
||||
message.guild_id ? Member.update({ id: req.user_id, guild_id: message.guild_id }, { last_message_id: message.id }) : null,
|
||||
channel.save(),
|
||||
]);
|
||||
|
||||
// no await as it shouldnt block the message send function and silently catch error
|
||||
|
||||
@@ -106,6 +106,15 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
|
||||
components: opts.components ?? undefined, // Fix Discord-Go?
|
||||
});
|
||||
const ephermal = (message.flags & (1 << 6)) !== 0;
|
||||
if (!ephermal && channel.type === ChannelType.GUILD_PUBLIC_THREAD) {
|
||||
const rep = Channel.getRepository();
|
||||
console.log(channel.id);
|
||||
await rep.increment({ id: channel.id }, "message_count", 1);
|
||||
await rep.increment({ id: channel.id }, "total_message_sent", 1);
|
||||
}
|
||||
if (!ephermal) {
|
||||
channel.last_message_id = message.id;
|
||||
}
|
||||
|
||||
if (cloudAttachments && cloudAttachments.length > 0) {
|
||||
console.log("[Message] Processing attachments for message", message.id, ":", message.attachments);
|
||||
|
||||
@@ -533,6 +533,7 @@ export class Channel extends BaseClass {
|
||||
user_limit: this.user_limit || undefined,
|
||||
rate_limit_per_user: this.rate_limit_per_user || undefined,
|
||||
owner_id: this.owner_id || undefined,
|
||||
...(this.type === ChannelType.GUILD_PUBLIC_THREAD && this.recipients ? { member_ids_preview: this.recipients.map((_) => _.user.id) } : {}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,6 +244,7 @@ export class Message extends BaseClass {
|
||||
poll: this.poll ?? undefined,
|
||||
content: this.content ?? "",
|
||||
pinned: this.pinned,
|
||||
thread: this.thread ? this.thread.toJSON() : this.thread,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user