1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-12 21:52:40 +01:00

Merge pull request #1023 from Rainb0wCodes/master

properly track reactions
This commit is contained in:
Madeline 2023-04-11 13:48:08 +10:00 committed by GitHub
commit 80c7eaa70f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -28,6 +28,7 @@ import {
MessageReactionRemoveEmojiEvent, MessageReactionRemoveEmojiEvent,
MessageReactionRemoveEvent, MessageReactionRemoveEvent,
PartialEmoji, PartialEmoji,
PublicMemberProjection,
PublicUserProjection, PublicUserProjection,
User, User,
} from "@spacebar/util"; } from "@spacebar/util";
@ -180,6 +181,7 @@ router.put(
if (already_added.user_ids.includes(req.user_id)) if (already_added.user_ids.includes(req.user_id))
return res.sendStatus(204); // Do not throw an error ¯\_(ツ)_/¯ as discord also doesn't throw any error return res.sendStatus(204); // Do not throw an error ¯\_(ツ)_/¯ as discord also doesn't throw any error
already_added.count++; already_added.count++;
already_added.user_ids.push(req.user_id);
} else } else
message.reactions.push({ message.reactions.push({
count: 1, count: 1,
@ -191,7 +193,12 @@ router.put(
const member = const member =
channel.guild_id && channel.guild_id &&
(await Member.findOneOrFail({ where: { id: req.user_id } })); (
await Member.findOneOrFail({
where: { id: req.user_id },
select: PublicMemberProjection,
})
).toPublicMember();
await emitEvent({ await emitEvent({
event: "MESSAGE_REACTION_ADD", event: "MESSAGE_REACTION_ADD",
@ -247,6 +254,11 @@ router.delete(
already_added.count--; already_added.count--;
if (already_added.count <= 0) message.reactions.remove(already_added); if (already_added.count <= 0) message.reactions.remove(already_added);
else
already_added.user_ids.splice(
already_added.user_ids.indexOf(user_id),
1,
);
await message.save(); await message.save();

View File

@ -440,6 +440,15 @@ export class Member extends BaseClassWithoutId {
]); ]);
} }
} }
toPublicMember() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const member: any = {};
PublicMemberProjection.forEach((x) => {
member[x] = this[x];
});
return member as PublicMember;
}
} }
export interface ChannelOverride { export interface ChannelOverride {