Skip to content

Commit c9e8013

Browse files
feat(model, http)!: Add support for super reaction types (#2347)
Refs: - discord/discord-api-docs#6375 - discord/discord-api-docs#6377 This PR renames the old `ReactionType` to `EmojiReactionType` as the concept of a reaction type now exists in the API.
1 parent 0063af4 commit c9e8013

File tree

15 files changed

+191
-70
lines changed

15 files changed

+191
-70
lines changed

twilight-cache-inmemory/src/event/reaction.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
CacheableModels, InMemoryCache, UpdateCache,
55
};
66
use twilight_model::{
7-
channel::message::{Reaction, ReactionCountDetails, ReactionType},
7+
channel::message::{EmojiReactionType, Reaction, ReactionCountDetails},
88
gateway::payload::incoming::{
99
ReactionAdd, ReactionRemove, ReactionRemoveAll, ReactionRemoveEmoji,
1010
},
@@ -124,14 +124,16 @@ impl<CacheModels: CacheableModels> UpdateCache<CacheModels> for ReactionRemoveEm
124124
}
125125
}
126126

127-
fn reactions_eq(a: &ReactionType, b: &ReactionType) -> bool {
127+
fn reactions_eq(a: &EmojiReactionType, b: &EmojiReactionType) -> bool {
128128
match (a, b) {
129-
(ReactionType::Custom { id: id_a, .. }, ReactionType::Custom { id: id_b, .. }) => {
130-
id_a == id_b
131-
}
132-
(ReactionType::Unicode { name: name_a }, ReactionType::Unicode { name: name_b }) => {
133-
name_a == name_b
134-
}
129+
(
130+
EmojiReactionType::Custom { id: id_a, .. },
131+
EmojiReactionType::Custom { id: id_b, .. },
132+
) => id_a == id_b,
133+
(
134+
EmojiReactionType::Unicode { name: name_a },
135+
EmojiReactionType::Unicode { name: name_b },
136+
) => name_a == name_b,
135137
_ => false,
136138
}
137139
}
@@ -141,7 +143,7 @@ mod tests {
141143
use super::reactions_eq;
142144
use crate::{model::CachedMessage, test};
143145
use twilight_model::{
144-
channel::message::{Reaction, ReactionType},
146+
channel::message::{EmojiReactionType, Reaction},
145147
gateway::{
146148
payload::incoming::{ReactionRemove, ReactionRemoveAll, ReactionRemoveEmoji},
147149
GatewayReaction,
@@ -153,7 +155,7 @@ mod tests {
153155
msg.reactions.iter().find(|&r| {
154156
reactions_eq(
155157
&r.emoji,
156-
&ReactionType::Custom {
158+
&EmojiReactionType::Custom {
157159
animated: false,
158160
id: Id::new(6),
159161
name: None,
@@ -172,11 +174,11 @@ mod tests {
172174
let world_react = msg
173175
.reactions
174176
.iter()
175-
.find(|&r| matches!(&r.emoji, ReactionType::Unicode {name} if name == "🗺️"));
177+
.find(|&r| matches!(&r.emoji, EmojiReactionType::Unicode {name} if name == "🗺️"));
176178
let smiley_react = msg
177179
.reactions
178180
.iter()
179-
.find(|&r| matches!(&r.emoji, ReactionType::Unicode {name} if name == "😀"));
181+
.find(|&r| matches!(&r.emoji, EmojiReactionType::Unicode {name} if name == "😀"));
180182
let custom_react = find_custom_react(&msg);
181183

182184
assert!(world_react.is_some());
@@ -191,8 +193,10 @@ mod tests {
191193
fn reaction_remove() {
192194
let cache = test::cache_with_message_and_reactions();
193195
cache.update(&ReactionRemove(GatewayReaction {
196+
burst: false,
197+
burst_colors: Vec::new(),
194198
channel_id: Id::new(2),
195-
emoji: ReactionType::Unicode {
199+
emoji: EmojiReactionType::Unicode {
196200
name: "😀".to_owned(),
197201
},
198202
guild_id: Some(Id::new(1)),
@@ -202,8 +206,10 @@ mod tests {
202206
user_id: Id::new(5),
203207
}));
204208
cache.update(&ReactionRemove(GatewayReaction {
209+
burst: false,
210+
burst_colors: Vec::new(),
205211
channel_id: Id::new(2),
206-
emoji: ReactionType::Custom {
212+
emoji: EmojiReactionType::Custom {
207213
animated: false,
208214
id: Id::new(6),
209215
name: None,
@@ -222,11 +228,11 @@ mod tests {
222228
let world_react = msg
223229
.reactions
224230
.iter()
225-
.find(|&r| matches!(&r.emoji, ReactionType::Unicode {name} if name == "🗺️"));
231+
.find(|&r| matches!(&r.emoji, EmojiReactionType::Unicode {name} if name == "🗺️"));
226232
let smiley_react = msg
227233
.reactions
228234
.iter()
229-
.find(|&r| matches!(&r.emoji, ReactionType::Unicode {name} if name == "😀"));
235+
.find(|&r| matches!(&r.emoji, EmojiReactionType::Unicode {name} if name == "😀"));
230236
let custom_react = find_custom_react(&msg);
231237

232238
assert!(world_react.is_some());
@@ -255,15 +261,15 @@ mod tests {
255261
let cache = test::cache_with_message_and_reactions();
256262
cache.update(&ReactionRemoveEmoji {
257263
channel_id: Id::new(2),
258-
emoji: ReactionType::Unicode {
264+
emoji: EmojiReactionType::Unicode {
259265
name: "😀".to_owned(),
260266
},
261267
guild_id: Id::new(1),
262268
message_id: Id::new(4),
263269
});
264270
cache.update(&ReactionRemoveEmoji {
265271
channel_id: Id::new(2),
266-
emoji: ReactionType::Custom {
272+
emoji: EmojiReactionType::Custom {
267273
animated: false,
268274
id: Id::new(6),
269275
name: None,
@@ -279,11 +285,11 @@ mod tests {
279285
let world_react = msg
280286
.reactions
281287
.iter()
282-
.find(|&r| matches!(&r.emoji, ReactionType::Unicode {name} if name == "🗺️"));
288+
.find(|&r| matches!(&r.emoji, EmojiReactionType::Unicode {name} if name == "🗺️"));
283289
let smiley_react = msg
284290
.reactions
285291
.iter()
286-
.find(|&r| matches!(&r.emoji, ReactionType::Unicode {name} if name == "😀"));
292+
.find(|&r| matches!(&r.emoji, EmojiReactionType::Unicode {name} if name == "😀"));
287293
let custom_react = find_custom_react(&msg);
288294

289295
assert!(world_react.is_some());

twilight-cache-inmemory/src/test.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use twilight_model::{
33
channel::{
44
message::{
55
sticker::{Sticker, StickerFormatType, StickerType},
6-
Message, MessageFlags, MessageType, ReactionType,
6+
EmojiReactionType, Message, MessageFlags, MessageType,
77
},
88
Channel, ChannelType,
99
},
@@ -103,8 +103,10 @@ pub fn cache_with_message_and_reactions() -> DefaultInMemoryCache {
103103
cache.update(&MessageCreate(msg));
104104

105105
let mut reaction = ReactionAdd(GatewayReaction {
106+
burst: false,
107+
burst_colors: Vec::new(),
106108
channel_id: Id::new(2),
107-
emoji: ReactionType::Unicode {
109+
emoji: EmojiReactionType::Unicode {
108110
name: "😀".to_owned(),
109111
},
110112
guild_id: Some(Id::new(1)),
@@ -186,13 +188,13 @@ pub fn cache_with_message_and_reactions() -> DefaultInMemoryCache {
186188

187189
cache.update(&reaction);
188190

189-
reaction.emoji = ReactionType::Unicode {
191+
reaction.emoji = EmojiReactionType::Unicode {
190192
name: "🗺️".to_owned(),
191193
};
192194

193195
cache.update(&reaction);
194196

195-
reaction.emoji = ReactionType::Custom {
197+
reaction.emoji = EmojiReactionType::Custom {
196198
animated: true,
197199
id: Id::new(6),
198200
name: Some("custom".to_owned()),

twilight-http/src/request/channel/reaction/get_reactions.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
};
99
use std::future::IntoFuture;
1010
use twilight_model::{
11+
channel::message::ReactionType,
1112
id::{
1213
marker::{ChannelMarker, MessageMarker, UserMarker},
1314
Id,
@@ -21,6 +22,7 @@ use twilight_validate::request::{
2122
struct GetReactionsFields {
2223
after: Option<Id<UserMarker>>,
2324
limit: Option<u16>,
25+
kind: Option<ReactionType>,
2426
}
2527

2628
/// Get a list of users that reacted to a message with an `emoji`.
@@ -49,6 +51,7 @@ impl<'a> GetReactions<'a> {
4951
fields: Ok(GetReactionsFields {
5052
after: None,
5153
limit: None,
54+
kind: None,
5255
}),
5356
http,
5457
message_id,
@@ -85,6 +88,17 @@ impl<'a> GetReactions<'a> {
8588

8689
self
8790
}
91+
92+
/// Set the kind of reaction to retrieve.
93+
///
94+
/// This can be either a super reaction or a normal reaction.
95+
pub fn kind(mut self, kind: ReactionType) -> Self {
96+
if let Ok(fields) = self.fields.as_mut() {
97+
fields.kind = Some(kind);
98+
}
99+
100+
self
101+
}
88102
}
89103

90104
impl IntoFuture for GetReactions<'_> {
@@ -112,6 +126,7 @@ impl TryIntoRequest for GetReactions<'_> {
112126
emoji: self.emoji,
113127
limit: fields.limit,
114128
message_id: self.message_id.get(),
129+
kind: fields.kind.map(Into::into),
115130
}))
116131
}
117132
}

twilight-http/src/routing.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,8 @@ pub enum Route<'a> {
785785
limit: Option<u16>,
786786
/// The ID of the message.
787787
message_id: u64,
788+
/// The type of reactions to fetch.
789+
kind: Option<u8>,
788790
},
789791
GetSKUs {
790792
/// The ID of the application.
@@ -2735,6 +2737,7 @@ impl Display for Route<'_> {
27352737
emoji,
27362738
limit,
27372739
message_id,
2740+
kind,
27382741
} => {
27392742
f.write_str("channels/")?;
27402743
Display::fmt(channel_id, f)?;
@@ -2746,7 +2749,8 @@ impl Display for Route<'_> {
27462749
let mut query_formatter = QueryStringFormatter::new(f);
27472750

27482751
query_formatter.write_opt_param("after", after.as_ref())?;
2749-
query_formatter.write_opt_param("limit", limit.as_ref())
2752+
query_formatter.write_opt_param("limit", limit.as_ref())?;
2753+
query_formatter.write_opt_param("type", kind.as_ref())
27502754
}
27512755
Route::GetSticker { sticker_id } => {
27522756
f.write_str("stickers/")?;

twilight-model/src/channel/message/component/button.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::channel::message::ReactionType;
1+
use crate::channel::message::EmojiReactionType;
22
use serde::{Deserialize, Serialize};
33

44
/// Clickable [`Component`] below messages.
@@ -20,7 +20,7 @@ pub struct Button {
2020
/// Defaults to `false`.
2121
pub disabled: bool,
2222
/// Visual emoji for clients to display with the button.
23-
pub emoji: Option<ReactionType>,
23+
pub emoji: Option<EmojiReactionType>,
2424
/// Text appearing on the button.
2525
pub label: Option<String>,
2626
/// Style variant of the button.

twilight-model/src/channel/message/component/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub use self::{
1919
text_input::{TextInput, TextInputStyle},
2020
};
2121

22-
use super::ReactionType;
22+
use super::EmojiReactionType;
2323
use crate::channel::ChannelType;
2424
use serde::{
2525
de::{Deserializer, Error as DeError, IgnoredAny, MapAccess, Visitor},
@@ -58,7 +58,7 @@ use std::fmt::{Formatter, Result as FmtResult};
5858
/// use twilight_model::{
5959
/// channel::message::{
6060
/// component::{ActionRow, Component, SelectMenu, SelectMenuOption, SelectMenuType},
61-
/// ReactionType,
61+
/// EmojiReactionType,
6262
/// },
6363
/// id::Id,
6464
/// };
@@ -75,7 +75,7 @@ use std::fmt::{Formatter, Result as FmtResult};
7575
/// options: Some(Vec::from([
7676
/// SelectMenuOption {
7777
/// default: false,
78-
/// emoji: Some(ReactionType::Custom {
78+
/// emoji: Some(EmojiReactionType::Custom {
7979
/// animated: false,
8080
/// id: Id::new(625891304148303894),
8181
/// name: Some("rogue".to_owned()),
@@ -86,7 +86,7 @@ use std::fmt::{Formatter, Result as FmtResult};
8686
/// },
8787
/// SelectMenuOption {
8888
/// default: false,
89-
/// emoji: Some(ReactionType::Custom {
89+
/// emoji: Some(EmojiReactionType::Custom {
9090
/// animated: false,
9191
/// id: Id::new(625891304081063986),
9292
/// name: Some("mage".to_owned()),
@@ -97,7 +97,7 @@ use std::fmt::{Formatter, Result as FmtResult};
9797
/// },
9898
/// SelectMenuOption {
9999
/// default: false,
100-
/// emoji: Some(ReactionType::Custom {
100+
/// emoji: Some(EmojiReactionType::Custom {
101101
/// animated: false,
102102
/// id: Id::new(625891303795982337),
103103
/// name: Some("priest".to_owned()),
@@ -239,7 +239,7 @@ impl<'de> Visitor<'de> for ComponentVisitor {
239239
let mut channel_types: Option<Vec<ChannelType>> = None;
240240
let mut default_values: Option<Vec<SelectDefaultValue>> = None;
241241
let mut disabled: Option<bool> = None;
242-
let mut emoji: Option<Option<ReactionType>> = None;
242+
let mut emoji: Option<Option<EmojiReactionType>> = None;
243243
let mut max_length: Option<Option<u16>> = None;
244244
let mut max_values: Option<Option<u8>> = None;
245245
let mut min_length: Option<Option<u16>> = None;
@@ -899,7 +899,7 @@ mod tests {
899899
let value = Component::Button(Button {
900900
custom_id: Some("test".to_owned()),
901901
disabled: false,
902-
emoji: Some(ReactionType::Unicode {
902+
emoji: Some(EmojiReactionType::Unicode {
903903
name: FLAG.to_owned(),
904904
}),
905905
label: Some("Test".to_owned()),
@@ -922,7 +922,7 @@ mod tests {
922922
Token::String("emoji"),
923923
Token::Some,
924924
Token::Struct {
925-
name: "ReactionType",
925+
name: "EmojiReactionType",
926926
len: 1,
927927
},
928928
Token::String("name"),

twilight-model/src/channel/message/component/select_menu.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::channel::{message::ReactionType, ChannelType};
1+
use crate::channel::{message::EmojiReactionType, ChannelType};
22
use crate::id::marker::{ChannelMarker, RoleMarker, UserMarker};
33
use crate::id::Id;
44
use serde::{Deserialize, Serialize};
@@ -65,7 +65,7 @@ pub struct SelectMenuOption {
6565
/// Emoji associated with the option. Appears left of the label and
6666
/// description.
6767
#[serde(skip_serializing_if = "Option::is_none")]
68-
pub emoji: Option<ReactionType>,
68+
pub emoji: Option<EmojiReactionType>,
6969
/// User-facing name.
7070
pub label: String,
7171
/// Developer defined value.

twilight-model/src/channel/message/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mod interaction;
1313
mod kind;
1414
mod mention;
1515
mod reaction;
16+
mod reaction_type;
1617
mod reference;
1718
mod role_subscription_data;
1819

@@ -26,7 +27,8 @@ pub use self::{
2627
interaction::MessageInteraction,
2728
kind::MessageType,
2829
mention::Mention,
29-
reaction::{Reaction, ReactionCountDetails, ReactionType},
30+
reaction::{EmojiReactionType, Reaction, ReactionCountDetails},
31+
reaction_type::ReactionType,
3032
reference::MessageReference,
3133
role_subscription_data::RoleSubscriptionData,
3234
sticker::Sticker,
@@ -198,8 +200,8 @@ mod tests {
198200
use super::{
199201
reaction::ReactionCountDetails,
200202
sticker::{MessageSticker, StickerFormatType},
201-
Message, MessageActivity, MessageActivityType, MessageApplication, MessageFlags,
202-
MessageReference, MessageType, Reaction, ReactionType,
203+
EmojiReactionType, Message, MessageActivity, MessageActivityType, MessageApplication,
204+
MessageFlags, MessageReference, MessageType, Reaction,
203205
};
204206
use crate::{
205207
channel::{ChannelMention, ChannelType},
@@ -490,7 +492,7 @@ mod tests {
490492
burst: 0,
491493
normal: 7,
492494
},
493-
emoji: ReactionType::Unicode {
495+
emoji: EmojiReactionType::Unicode {
494496
name: "a".to_owned(),
495497
},
496498
me: true,
@@ -687,7 +689,7 @@ mod tests {
687689
Token::StructEnd,
688690
Token::Str("emoji"),
689691
Token::Struct {
690-
name: "ReactionType",
692+
name: "EmojiReactionType",
691693
len: 1,
692694
},
693695
Token::Str("name"),

0 commit comments

Comments
 (0)