11use components:: theme:: ActiveTheme ;
2- use gpui:: { div, img, px, AnyElement , InteractiveElement , IntoElement , ParentElement , RenderOnce , Rgba , StatefulInteractiveElement , Styled , WindowContext } ;
32use gpui:: prelude:: FluentBuilder ;
3+ use gpui:: { div, img, px, AnyElement , App , IntoElement , ParentElement , RenderOnce , Rgba , Styled } ;
44use scope_chat:: reaction:: MessageReactionType :: Normal ;
55use scope_chat:: reaction:: { MessageReaction , MessageReactionType , ReactionEmoji } ;
66use serenity:: all:: ReactionType ;
7+ use std:: fmt:: Debug ;
78use MessageReactionType :: Burst ;
89
910#[ derive( Clone , Debug ) ]
@@ -46,7 +47,7 @@ impl DiscordMessageReaction {
4647 }
4748 }
4849
49- fn use_local ( & mut self ) {
50+ fn swap_to_local ( & mut self ) {
5051 let ( count_normal, count_burst) = match & self . data {
5152 ReactionData :: Message ( reaction) => ( reaction. count_details . normal , reaction. count_details . burst ) ,
5253 ReactionData :: Local {
@@ -64,6 +65,12 @@ impl DiscordMessageReaction {
6465 burst_colours,
6566 }
6667 }
68+ fn render_emoji ( emoji : & ReactionEmoji ) -> AnyElement {
69+ match emoji {
70+ ReactionEmoji :: Simple ( character) => div ( ) . text_size ( px ( 12f32 ) ) . child ( character. clone ( ) ) . into_any_element ( ) ,
71+ ReactionEmoji :: Custom { url, .. } => img ( url. clone ( ) ) . w ( px ( 16f32 ) ) . h ( px ( 16f32 ) ) . into_any_element ( ) ,
72+ }
73+ }
6774}
6875
6976impl MessageReaction for DiscordMessageReaction {
@@ -114,7 +121,7 @@ impl MessageReaction for DiscordMessageReaction {
114121 }
115122
116123 fn increment ( & mut self , kind : MessageReactionType , user_is_self : bool , by : isize ) {
117- self . use_local ( ) ;
124+ self . swap_to_local ( ) ;
118125 match kind {
119126 Burst => {
120127 if let ReactionData :: Local { count_burst, .. } = & mut self . data {
@@ -140,47 +147,34 @@ impl MessageReaction for DiscordMessageReaction {
140147 }
141148}
142149
143- impl DiscordMessageReaction {
144- fn render_emoji ( emoji : & ReactionEmoji ) -> AnyElement {
145- match emoji {
146- ReactionEmoji :: Simple ( character) => div ( ) . text_size ( px ( 12f32 ) ) . child ( character. clone ( ) ) . into_any_element ( ) ,
147- ReactionEmoji :: Custom { url, .. } => img ( url. clone ( ) ) . w ( px ( 16f32 ) ) . h ( px ( 16f32 ) ) . into_any_element ( ) ,
148- }
149- }
150- }
151-
152150impl RenderOnce for DiscordMessageReaction {
153- fn render ( self , cx : & mut WindowContext ) -> impl IntoElement {
151+ fn render ( self , _ : & mut gpui :: Window , cx : & mut App ) -> impl IntoElement {
154152 let emoji = self . get_emoji ( ) ;
155- let async_emoji = emoji. clone ( ) ;
156153 let theme = cx. theme ( ) ;
157154 div ( )
158- . px_1 ( )
159- . py_px ( )
160- . border_1 ( )
161- . border_color ( theme. border )
162- . when ( self . get_self_reaction ( ) . is_some ( ) , |s| s. border_color ( theme. accent ) )
163- . bg ( theme. panel )
164- . rounded_md ( )
165- . flex ( )
166- . id ( "reaction" )
167- . on_click ( move |_, _| {
168- eprintln ! ( "Reaction {:?} clicked" , async_emoji) ;
169- } )
170- . justify_center ( )
171- . items_center ( )
172- . gap_1 ( )
173- . child ( Self :: render_emoji ( & emoji) )
174- . child ( self . get_count ( None ) . to_string ( ) )
155+ . px_1 ( )
156+ . py_px ( )
157+ . border_1 ( )
158+ . border_color ( theme. border )
159+ . when ( self . get_self_reaction ( ) . is_some ( ) , |s| s. border_color ( theme. accent ) )
160+ . bg ( theme. panel )
161+ . rounded_md ( )
162+ . flex ( )
163+ . justify_center ( )
164+ . items_center ( )
165+ . gap_1 ( )
166+ . child ( Self :: render_emoji ( & emoji) )
167+ . child ( self . get_count ( None ) . to_string ( ) )
175168 }
176169}
177170
178- pub fn discord_reaction_to_emoji ( reaction : & serenity :: all :: ReactionType ) -> ReactionEmoji {
171+ pub fn discord_reaction_to_emoji ( reaction : & ReactionType ) -> ReactionEmoji {
179172 match reaction {
180173 ReactionType :: Custom { animated, id, name } => ReactionEmoji :: Custom {
181174 url : format ! ( "https://cdn.discordapp.com/emojis/{}.png" , id) ,
182175 animated : * animated,
183176 name : name. clone ( ) ,
177+ id : id. get ( ) ,
184178 } ,
185179 ReactionType :: Unicode ( character) => ReactionEmoji :: Simple ( character. clone ( ) ) ,
186180 ty => {
0 commit comments