async fn handle_message(
    cx: UpdateWithCx<AutoSend<Bot>, Message>,
    db_shared: Arc<Mutex<RedisConnection>>,
) {
    let mut db_con: tokio::sync::MutexGuard<RedisConnection> = db_shared.lock().await;

    // Obtain dialogue from database
    let chat_id = cx.update.chat_id();
    let from_id = cx.update.from().map(|u| u.id);
    let dialogue: Dialogue = match db_con
        .get_dialogue(chat_id, from_id)
        .await
        .map(Option::unwrap_or_default)
    {
        Ok(d) => d,
        Err(e) => {
            log::error!(
                "{}",
                format_log_chat(
                    &format!(
                        "Could not get dialogue (from {f:?}): {e:?}",
                        f = from_id,
                        e = e
                    ),
                    chat_id
                )
            );
            return;
        }
    };
    drop(db_con);

    // Handle the dialogue and receive results.
    let stage = match handle_dialogue(cx, dialogue, db_shared.clone()).await {
        Ok(a) => a,
        Err(e) => {
            log::error!(
                "{}",
                format_log_chat(
                    &format!(
                        "Could not handle dialogue (from {f:?}): {e:?}",
                        f = from_id,
                        e = e
                    ),
                    chat_id
                )
            );
            return;
        }
    };

    let mut db_con: tokio::sync::MutexGuard<RedisConnection> = db_shared.lock().await;
    // Update the dialogue state in database.
    match stage {
        DialogueStage::Next(new_dialogue) => {
            if let Err(e) = db_con.update_dialogue(chat_id, from_id, new_dialogue).await {
                log::error!("Storage::update_dialogue failed: {:?}", e);
            }
        }
        DialogueStage::Exit => {
            if let Err(e) = db_con.remove_dialogue(chat_id, from_id).await {
                log::error!("Storage::remove_dialogue failed: {:?}", e);
            }
        }
    }
}
/// Handle message update.
///
/// Find `Dialogue` for `handle_dialogue` from db. Use the function
/// result to update dialogue state in database.
Handle message update.
Find `Dialogue` for `handle_dialogue` from db. Use the function
result to update dialogue state in database.
Handle message update . Find ` Dialogue ` for ` handle_dialogue ` from db . Use the function result to update dialogue state in database .
async fn handle_message(
    cx: UpdateWithCx<AutoSend<Bot>, Message>,
    db_shared: Arc<Mutex<RedisConnection>>,
) {
    let mut db_con: tokio::sync::MutexGuard<RedisConnection> = db_shared.lock().await;
    // Obtain dialogue from database
    let chat_id = cx.update.chat_id();
    let from_id = cx.update.from().map(|u| u.id);
    let dialogue: Dialogue = match db_con
        .get_dialogue(chat_id, from_id)
        .await
        .map(Option::unwrap_or_default)
    {
        Ok(d) => d,
        Err(e) => {
            log::error!(
                "{}",
                format_log_chat(
                    &format!(
                        "Could not get dialogue (from {f:?}): {e:?}",
                        f = from_id,
                        e = e
                    ),
                    chat_id
                )
            );
            return;
        }
    };
    drop(db_con);
    // Handle the dialogue and receive results.
    let stage = match handle_dialogue(cx, dialogue, db_shared.clone()).await {
        Ok(a) => a,
        Err(e) => {
            log::error!(
                "{}",
                format_log_chat(
                    &format!(
                        "Could not handle dialogue (from {f:?}): {e:?}",
                        f = from_id,
                        e = e
                    ),
                    chat_id
                )
            );
            return;
        }
    };
    let mut db_con: tokio::sync::MutexGuard<RedisConnection> = db_shared.lock().await;
    // Update the dialogue state in database.
    match stage {
        DialogueStage::Next(new_dialogue) => {
            if let Err(e) = db_con.update_dialogue(chat_id, from_id, new_dialogue).await {
                log::error!("Storage::update_dialogue failed: {:?}", e);
            }
        }
        DialogueStage::Exit => {
            if let Err(e) = db_con.remove_dialogue(chat_id, from_id).await {
                log::error!("Storage::remove_dialogue failed: {:?}", e);
            }
        }
    }
}
async fn handle_message ( cx : UpdateWithCx < AutoSend < Bot > , Message > , db_shared : Arc < Mutex < RedisConnection > > , ) { let mut db_con : tokio :: sync :: MutexGuard < RedisConnection > = db_shared . lock ( ) . await ; // Obtain dialogue from database let chat_id = cx . update . chat_id ( ) ; let from_id = cx . update . from ( ) . map ( | u | u . id ) ; let dialogue : Dialogue = match db_con . get_dialogue ( chat_id , from_id ) . await . map ( Option :: unwrap_or_default ) { Ok ( d ) => d , Err ( e ) => { log :: error ! ( " " format_log_chat ( format ( " " f from_id e e ) chat_id ) ) ; return ; } } ; drop ( db_con ) ; // Handle the dialogue and receive results. let stage = match handle_dialogue ( cx , dialogue , db_shared . clone ( ) ) . await { Ok ( a ) => a , Err ( e ) => { log :: error ! ( " " format_log_chat ( format ( " " f from_id e e ) chat_id ) ) ; return ; } } ; let mut db_con : tokio :: sync :: MutexGuard < RedisConnection > = db_shared . lock ( ) . await ; // Update the dialogue state in database. match stage { DialogueStage :: Next ( new_dialogue ) => { if let Err ( e ) = db_con . update_dialogue ( chat_id , from_id , new_dialogue ) . await { log :: error ! ( " " e ) ; } } DialogueStage :: Exit => { if let Err ( e ) = db_con . remove_dialogue ( chat_id , from_id ) . await { log :: error ! ( " " e ) ; } } } }
Handle message update.
Handle message update .
cx
UpdateWithCx<AutoSend<Bot>, Message>
db_shared
Arc<Mutex<RedisConnection>>