fix dming blocked users
This commit is contained in:
parent
e22c5725f3
commit
a78f9e51ca
@ -18,11 +18,13 @@
|
|||||||
|
|
||||||
import { handleMessage, postHandleMessage, route } from "@spacebar/api";
|
import { handleMessage, postHandleMessage, route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
|
ApiError,
|
||||||
Attachment,
|
Attachment,
|
||||||
AutomodRule,
|
AutomodRule,
|
||||||
AutomodTriggerTypes,
|
AutomodTriggerTypes,
|
||||||
Channel,
|
Channel,
|
||||||
Config,
|
Config,
|
||||||
|
DiscordApiErrors,
|
||||||
DmChannelDTO,
|
DmChannelDTO,
|
||||||
emitEvent,
|
emitEvent,
|
||||||
FieldErrors,
|
FieldErrors,
|
||||||
@ -34,6 +36,7 @@ import {
|
|||||||
NewUrlSignatureData,
|
NewUrlSignatureData,
|
||||||
NewUrlUserSignatureData,
|
NewUrlUserSignatureData,
|
||||||
ReadState,
|
ReadState,
|
||||||
|
Relationship,
|
||||||
Rights,
|
Rights,
|
||||||
Snowflake,
|
Snowflake,
|
||||||
uploadFile,
|
uploadFile,
|
||||||
@ -53,6 +56,7 @@ import {
|
|||||||
MessageCreateCloudAttachment,
|
MessageCreateCloudAttachment,
|
||||||
MessageCreateSchema,
|
MessageCreateSchema,
|
||||||
Reaction,
|
Reaction,
|
||||||
|
RelationshipType,
|
||||||
} from "@spacebar/schemas";
|
} from "@spacebar/schemas";
|
||||||
|
|
||||||
const router: Router = Router({ mergeParams: true });
|
const router: Router = Router({ mergeParams: true });
|
||||||
@ -319,6 +323,24 @@ router.post(
|
|||||||
throw new HTTPError(`Cannot send messages to channel of type ${channel.type}`, 400);
|
throw new HTTPError(`Cannot send messages to channel of type ${channel.type}`, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle blocked users in dms
|
||||||
|
if(channel.recipients?.length == 2) {
|
||||||
|
const otherUser = channel.recipients.find((r) => r.user_id != req.user_id)?.user;
|
||||||
|
if (otherUser) {
|
||||||
|
const relationship = await Relationship.findOne({
|
||||||
|
where: [
|
||||||
|
{ from_id: req.user_id, to_id: otherUser.id },
|
||||||
|
{ from_id: otherUser.id, to_id: req.user_id },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (relationship?.type === RelationshipType.blocked) {
|
||||||
|
throw DiscordApiErrors.CANNOT_MESSAGE_USER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (body.nonce) {
|
if (body.nonce) {
|
||||||
const existing = await Message.findOne({
|
const existing = await Message.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
Reference in New Issue
Block a user