@@ -22,7 +22,7 @@ use crate::gateway::ShardMessenger;
2222#[ cfg( feature = "model" ) ]
2323use crate :: http:: { CacheHttp , Http } ;
2424use crate :: model:: prelude:: * ;
25- use crate :: model:: utils:: { deserialize_val , discord_colours, StrOrInt } ;
25+ use crate :: model:: utils:: { deserialize_components , discord_colours, StrOrInt } ;
2626#[ cfg( all( feature = "model" , feature = "cache" ) ) ]
2727use crate :: utils;
2828
@@ -151,54 +151,6 @@ pub struct Message {
151151 pub poll : Option < Box < Poll > > ,
152152}
153153
154- // Custom deserialize function to deserialize components safely without knocking the whole message
155- // out when new components are found but not supported.
156- fn deserialize_components < ' de , D > ( deserializer : D ) -> Result < Vec < ActionRow > , D :: Error >
157- where
158- D : Deserializer < ' de > ,
159- {
160- struct ComponentsVisitor ;
161-
162- impl < ' de > Visitor < ' de > for ComponentsVisitor {
163- type Value = Vec < ActionRow > ;
164-
165- fn expecting ( & self , formatter : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
166- formatter. write_str ( "a sequence of ActionRow elements" )
167- }
168-
169- fn visit_seq < A > ( self , mut seq : A ) -> Result < Self :: Value , A :: Error >
170- where
171- A : serde:: de:: SeqAccess < ' de > ,
172- {
173- let mut components = Vec :: with_capacity ( seq. size_hint ( ) . unwrap_or_default ( ) ) ;
174-
175- while let Some ( map) = seq. next_element :: < JsonMap > ( ) ? {
176- // We deserialize only the `kind` field to determine the component type.
177- // We later use this to check if its a supported component before deserializing the
178- // entire payload.
179- let raw_kind =
180- map. get ( "type" ) . ok_or_else ( || DeError :: missing_field ( "type" ) ) ?. clone ( ) ;
181- let kind: i64 = deserialize_val ( raw_kind) ?;
182-
183- // Action rows are the only top level component supported in serenity at this time.
184- if kind == 1 {
185- let value = Value :: from ( map) ;
186- components
187- . push ( ActionRow :: deserialize ( value) . map_err ( serde:: de:: Error :: custom) ?) ;
188- } else {
189- // Top level component is not an action row and cannot be supported on
190- // serenity@current without breaking changes, so we skip them.
191- tracing:: debug!( "Skipping component with unsupported kind: {kind}" ) ;
192- }
193- }
194-
195- Ok ( components)
196- }
197- }
198-
199- deserializer. deserialize_seq ( ComponentsVisitor )
200- }
201-
202154#[ cfg( feature = "model" ) ]
203155impl Message {
204156 /// Crossposts this message.
0 commit comments