mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-22 10:22:39 +01:00
Merge pull request #1023 from Rainb0wCodes/master
properly track reactions
This commit is contained in:
commit
80c7eaa70f
@ -28,6 +28,7 @@ import {
|
||||
MessageReactionRemoveEmojiEvent,
|
||||
MessageReactionRemoveEvent,
|
||||
PartialEmoji,
|
||||
PublicMemberProjection,
|
||||
PublicUserProjection,
|
||||
User,
|
||||
} from "@spacebar/util";
|
||||
@ -180,6 +181,7 @@ router.put(
|
||||
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
|
||||
already_added.count++;
|
||||
already_added.user_ids.push(req.user_id);
|
||||
} else
|
||||
message.reactions.push({
|
||||
count: 1,
|
||||
@ -191,7 +193,12 @@ router.put(
|
||||
|
||||
const member =
|
||||
channel.guild_id &&
|
||||
(await Member.findOneOrFail({ where: { id: req.user_id } }));
|
||||
(
|
||||
await Member.findOneOrFail({
|
||||
where: { id: req.user_id },
|
||||
select: PublicMemberProjection,
|
||||
})
|
||||
).toPublicMember();
|
||||
|
||||
await emitEvent({
|
||||
event: "MESSAGE_REACTION_ADD",
|
||||
@ -247,6 +254,11 @@ router.delete(
|
||||
already_added.count--;
|
||||
|
||||
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();
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user