diff --git a/src/main/java/net/dv8tion/jda/api/entities/MessageReaction.java b/src/main/java/net/dv8tion/jda/api/entities/MessageReaction.java index 537412b13f..6ac7039479 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/MessageReaction.java +++ b/src/main/java/net/dv8tion/jda/api/entities/MessageReaction.java @@ -57,8 +57,8 @@ public class MessageReaction private final MessageChannel channel; private final long channelId; private final long messageId; - private final boolean self; - private final int count; + private final boolean[] self; + private final int[] counts; /** * Creates a new MessageReaction instance @@ -72,11 +72,13 @@ public class MessageReaction * @param messageId * The message id this reaction is attached to * @param self - * Whether we already reacted with this Reaction - * @param count - * The amount of people that reacted with this Reaction + * Whether we already reacted with this Reaction, + * as an array of {@code [normal, super]} + * @param counts + * The amount of people that reacted with this Reaction, + * as an array of {@code [total, normal, super]} */ - public MessageReaction(@Nonnull JDA jda, @Nullable MessageChannel channel, @Nonnull EmojiUnion emoji, long channelId, long messageId, boolean self, int count) + public MessageReaction(@Nonnull JDA jda, @Nullable MessageChannel channel, @Nonnull EmojiUnion emoji, long channelId, long messageId, boolean[] self, int[] counts) { this.jda = jda; this.emoji = emoji; @@ -84,7 +86,7 @@ public MessageReaction(@Nonnull JDA jda, @Nullable MessageChannel channel, @Nonn this.channelId = channelId; this.messageId = messageId; this.self = self; - this.count = count; + this.counts = counts; } /** @@ -99,16 +101,35 @@ public JDA getJDA() } /** - * Whether the currently logged in account has reacted with this reaction + * Whether the currently logged in account has reacted with this reaction at all, including both super and normal. * *

This will always be false for events. Discord does not provide this information for reaction events. * You can use {@link MessageChannel#retrieveMessageById(String)} to get this information on a complete message. * * @return True, if we reacted with this reaction + * + * @see #isSelf(ReactionType) */ public boolean isSelf() { - return self; + return self[0] || self[1]; + } + + /** + * Whether the currently logged in account has reacted with this reaction as specifically a super or normal reaction. + * + *

This will always be false for events. Discord does not provide this information for reaction events. + * You can use {@link MessageChannel#retrieveMessageById(String)} to get this information on a complete message. + * + * @param type + * The specific type of reaction + * + * @return True, if we reacted with this reaction + */ + public boolean isSelf(@Nonnull ReactionType type) + { + Checks.notNull(type, "Type"); + return self[type == ReactionType.NORMAL ? 0 : 1]; } /** @@ -122,7 +143,7 @@ public boolean isSelf() */ public boolean hasCount() { - return count >= 0; + return counts != null; } /** @@ -138,7 +159,7 @@ public boolean hasChannel() } /** - * The amount of users that already reacted with this Reaction + * The total amount of users that already reacted with this Reaction. *
This is not updated, it is a {@code final int} per Reaction instance * *

This value is not available in events such as {@link net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent MessageReactionAddEvent} @@ -149,12 +170,40 @@ public boolean hasChannel() * If this MessageReaction is from an event which does not provide a count * * @return The amount of users that reacted with this Reaction + * + * @see #getCount(ReactionType) */ public int getCount() { if (!hasCount()) throw new IllegalStateException("Cannot retrieve count for this MessageReaction!"); - return count; + return counts[0]; + } + + /** + * The specific amount of users that already reacted with this Reaction. + *
This is not updated, it is a {@code final int} per Reaction instance + * + *

This value is not available in events such as {@link net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent MessageReactionAddEvent} + * and {@link net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent MessageReactionRemoveEvent} in which case an + * {@link java.lang.IllegalStateException IllegalStateException} is thrown! + * + * @param type + * The specific type of reaction + * + * @throws java.lang.IllegalStateException + * If this MessageReaction is from an event which does not provide a count + * + * @return The amount of users that reacted with this Reaction + * + * @see #getCount() + */ + public int getCount(@Nonnull ReactionType type) + { + if (!hasCount()) + throw new IllegalStateException("Cannot retrieve count for this MessageReaction!"); + Checks.notNull(type, "Type"); + return counts[type == ReactionType.NORMAL ? 1 : 2]; } /** @@ -443,7 +492,7 @@ public boolean equals(Object obj) return false; MessageReaction r = (MessageReaction) obj; return r.emoji.equals(emoji) - && r.self == self + && r.isSelf() == this.isSelf() && r.messageId == messageId; } @@ -456,4 +505,12 @@ public String toString() .addMetadata("emoji", emoji) .toString(); } + + /** + * Type of reaction. + */ + public enum ReactionType + { + NORMAL, SUPER + } } diff --git a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java index 05514e2cbf..09b06f2ad8 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java @@ -1908,8 +1908,15 @@ private static MessageActivity createMessageActivity(DataObject jsonObject) public MessageReaction createMessageReaction(MessageChannel chan, long channelId, long messageId, DataObject obj) { DataObject emoji = obj.getObject("emoji"); - final int count = obj.getInt("count", -1); - final boolean me = obj.getBoolean("me"); + final int[] count = new int[]{ + obj.getInt("count", 0), // total + obj.optObject("count_details").map(o -> o.getInt("normal", 0)).orElse(0), + obj.optObject("count_details").map(o -> o.getInt("burst", 0)).orElse(0), + }; + final boolean[] me = new boolean[] { + obj.getBoolean("me"), // normal + obj.getBoolean("me_burst") // super + }; EmojiUnion emojiObj = createEmoji(emoji); return new MessageReaction(api, chan, emojiObj, channelId, messageId, me, count); diff --git a/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionClearEmojiHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionClearEmojiHandler.java index 73572313d6..6f0eafa387 100644 --- a/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionClearEmojiHandler.java +++ b/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionClearEmojiHandler.java @@ -69,7 +69,13 @@ protected Long handleInternally(DataObject content) DataObject emoji = content.getObject("emoji"); EmojiUnion reactionEmoji = EntityBuilder.createEmoji(emoji); - MessageReaction reaction = new MessageReaction(api, channel, reactionEmoji, channelId, messageId, false, 0); + // We don't know if it is a normal or super reaction + boolean[] self = new boolean[] { + false, + false + }; + + MessageReaction reaction = new MessageReaction(api, channel, reactionEmoji, channelId, messageId, self, null); getJDA().handleEvent(new MessageReactionRemoveEmojiEvent(getJDA(), responseNumber, messageId, channel, reaction)); return null; diff --git a/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionHandler.java index afe3a6d6c0..f6388e71bc 100644 --- a/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionHandler.java +++ b/src/main/java/net/dv8tion/jda/internal/handle/MessageReactionHandler.java @@ -158,7 +158,13 @@ protected Long handleInternally(DataObject content) // reaction remove has null name sometimes EmojiUnion rEmoji = EntityBuilder.createEmoji(emoji); - MessageReaction reaction = new MessageReaction(api, channel, rEmoji, channelId, messageId, userId == api.getSelfUser().getIdLong(), -1); + // We don't know if it is a normal or super reaction + boolean[] self = new boolean[] { + false, + false + }; + + MessageReaction reaction = new MessageReaction(api, channel, rEmoji, channelId, messageId, self, null); if (channel.getType() == ChannelType.PRIVATE) {