diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-09-29 21:27:33 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-09-29 21:29:54 +1000 |
commit | 835a5ab3a339bebd916d72487cddc4c344121e7b (patch) | |
tree | a457fdfa1567de2c95cc83053896da8268078c1e /src/api/routes/channels | |
parent | Prevent URL embedding and mentions when in codeblock (diff) | |
download | server-835a5ab3a339bebd916d72487cddc4c344121e7b.tar.xz |
Fix fetching members for roles in POST message
Diffstat (limited to 'src/api/routes/channels')
-rw-r--r-- | src/api/routes/channels/#channel_id/messages/index.ts | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts index 8598d1f8..747701db 100644 --- a/src/api/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts @@ -255,17 +255,22 @@ router.post( ); } - const member = await Member.findOneOrFail({ - where: { id: req.user_id }, - relations: ["roles"], - }); - member.roles = member.roles - .filter((role: Role) => { - return role.id !== role.guild_id; - }) - .map((role: Role) => { - return role.id; - }) as any; + if (message.guild_id) { + // handleMessage will fetch the Member, but only if they are not guild owner. + // have to fetch ourselves otherwise. + if (!message.member) { + message.member = await Member.findOneOrFail({ + where: { id: req.user_id, guild_id: message.guild_id }, + relations: ["roles"] + }); + } + + //@ts-ignore + message.member.roles = + message.member.roles. + filter(x => x.id != x.guild_id) + .map(x => x.id); + } let read_state = await ReadState.findOne({ where: { user_id: req.user_id, channel_id } |