11use std:: collections:: HashSet ;
22
33use futures:: { StreamExt , stream} ;
4+ use teloxide:: types:: ChatAction ;
45
56use crate :: {
67 bot_handler:: { BotHandlerError , BotHandlerResult , CommandState , commands:: Context } ,
78 storage:: RepoEntity ,
89} ;
910
11+ /// A struct to hold the summary of the add operation.
12+ #[ derive( Default , Debug , Clone , PartialEq , Eq ) ]
13+ pub struct AddSummary {
14+ /// Repositories that were successfully added.
15+ pub successfully_added : HashSet < String > ,
16+ /// Repositories that were already tracked.
17+ pub already_tracked : HashSet < String > ,
18+ /// Repositories that were not found on GitHub.
19+ pub not_found : HashSet < String > ,
20+ /// URLs that were invalid.
21+ pub invalid_urls : HashSet < String > ,
22+ /// Repositories that failed to be added due to an error.
23+ pub errors : HashSet < ( String , String ) > ,
24+ }
25+
1026pub async fn handle ( ctx : Context < ' _ > ) -> BotHandlerResult < ( ) > {
1127 ctx. handler . messaging_service . prompt_for_repo_input ( ctx. message . chat . id ) . await ?;
1228 ctx. dialogue
@@ -25,16 +41,6 @@ enum AddRepoResult {
2541 Error ( String , String ) ,
2642}
2743
28- // A struct to hold the summary of the add operation.
29- #[ derive( Default ) ]
30- struct AddSummary {
31- successfully_added : HashSet < String > ,
32- already_tracked : HashSet < String > ,
33- not_found : HashSet < String > ,
34- invalid_urls : HashSet < String > ,
35- errors : HashSet < ( String , String ) > ,
36- }
37-
3844/// Handle the reply message when we're waiting for repository input.
3945/// It processes the input, checks each URL, and adds the repositories
4046/// accordingly.
@@ -54,6 +60,14 @@ pub async fn handle_reply(ctx: Context<'_>, text: &str) -> BotHandlerResult<()>
5460 return Ok ( ( ) ) ;
5561 }
5662
63+ ctx. handler . messaging_service . send_chat_action ( ctx. message . chat . id , ChatAction :: Typing ) . await ?;
64+
65+ let status_msg = ctx
66+ . handler
67+ . messaging_service
68+ . send_text_message ( ctx. message . chat . id , "Processing... ⏳" )
69+ . await ?;
70+
5771 let summary = stream:: iter ( urls)
5872 . map ( |url| async move {
5973 let repo = match RepoEntity :: from_url ( & url) {
@@ -101,14 +115,7 @@ pub async fn handle_reply(ctx: Context<'_>, text: &str) -> BotHandlerResult<()>
101115
102116 ctx. handler
103117 . messaging_service
104- . send_add_summary_msg (
105- ctx. message . chat . id ,
106- summary. successfully_added ,
107- summary. already_tracked ,
108- summary. not_found ,
109- summary. invalid_urls ,
110- summary. errors ,
111- )
118+ . edit_add_summary_msg ( ctx. message . chat . id , status_msg. id , & summary)
112119 . await ?;
113120
114121 Ok ( ( ) )
0 commit comments