pub async fn update_overview(&self, ctx: &Context) -> Result<()> {
        let msg = match self.overview_message_id {
            Some(m) => m,
            None => return Err(SignupBoardError::OverviewMessageNotSet.into()),
        };
        let chan = match self.overview_channel_id {
            Some(c) => c,
            None => return Err(SignupBoardError::OverviewChannelNotSet.into()),
        };
        let gid = load_guild_id(ctx).await?;

        let active_trainings = db::Training::all_active(ctx).await?;
        let mut trainings: Vec<(db::Training, i64)> = Vec::new();
        for at in active_trainings {
            let count = at.get_signup_count(ctx).await?;
            trainings.push((at, count));
        }

        // Sort by custom names and dates
        trainings.sort_by(|a, b| title_sort_value(&b.0).cmp(&title_sort_value(&a.0)));
        trainings.sort_by(|a, b| a.0.date.date().cmp(&b.0.date.date()));

        // Group by dates
        let mut groups: Vec<(NaiveDate, Vec<(db::Training, i64)>)> = Vec::new();
        for (g, t) in trainings
            .into_iter()
            .group_by(|a| a.0.date.date())
            .into_iter()
        {
            groups.push((g, t.collect::<Vec<_>>()));
        }

        // Get the signup board channels for the dates
        let mut ready: Vec<(
            NaiveDate,
            usize,
            Option<ChannelId>,
            Vec<(db::Training, i64)>,
        )> = Vec::new();
        for (d, t) in groups {
            let chan = db::SignupBoardChannel::by_day(ctx, d)
                .await
                .ok()
                .map(|sbc| sbc.channel());
            //FIXME do this properly without an extra db access
            let mut total_users = db::User::by_signed_up_and_date(ctx, d).await?;
            total_users.sort_by_key(|u| u.id);
            total_users.dedup_by_key(|u| u.id);

            ready.push((d, total_users.len(), chan, t));
        }

        chan.edit_message(ctx, msg, |m| {
            m.content("");
            m.set_embed(embeds::signup_board_overview(ready, gid));
            m.components(|c| c.add_action_row(components::register_list_action_row()))
        })
        .await?;

        Ok(())
    }
// Updates the overview message if available
Updates the overview message if available
Updates the overview message if available
pub async fn update_overview(&self, ctx: &Context) -> Result<()> {
        let msg = match self.overview_message_id {
            Some(m) => m,
            None => return Err(SignupBoardError::OverviewMessageNotSet.into()),
        };
        let chan = match self.overview_channel_id {
            Some(c) => c,
            None => return Err(SignupBoardError::OverviewChannelNotSet.into()),
        };
        let gid = load_guild_id(ctx).await?;
        let active_trainings = db::Training::all_active(ctx).await?;
        let mut trainings: Vec<(db::Training, i64)> = Vec::new();
        for at in active_trainings {
            let count = at.get_signup_count(ctx).await?;
            trainings.push((at, count));
        }
        // Sort by custom names and dates
        trainings.sort_by(|a, b| title_sort_value(&b.0).cmp(&title_sort_value(&a.0)));
        trainings.sort_by(|a, b| a.0.date.date().cmp(&b.0.date.date()));
        // Group by dates
        let mut groups: Vec<(NaiveDate, Vec<(db::Training, i64)>)> = Vec::new();
        for (g, t) in trainings
            .into_iter()
            .group_by(|a| a.0.date.date())
            .into_iter()
        {
            groups.push((g, t.collect::<Vec<_>>()));
        }
        // Get the signup board channels for the dates
        let mut ready: Vec<(
            NaiveDate,
            usize,
            Option<ChannelId>,
            Vec<(db::Training, i64)>,
        )> = Vec::new();
        for (d, t) in groups {
            let chan = db::SignupBoardChannel::by_day(ctx, d)
                .await
                .ok()
                .map(|sbc| sbc.channel());
            //FIXME do this properly without an extra db access
            let mut total_users = db::User::by_signed_up_and_date(ctx, d).await?;
            total_users.sort_by_key(|u| u.id);
            total_users.dedup_by_key(|u| u.id);
            ready.push((d, total_users.len(), chan, t));
        }
        chan.edit_message(ctx, msg, |m| {
            m.content("");
            m.set_embed(embeds::signup_board_overview(ready, gid));
            m.components(|c| c.add_action_row(components::register_list_action_row()))
        })
        .await?;
        Ok(())
    }
pub async fn update_overview ( & self , ctx : & Context ) -> Result < ( ) > { let msg = match self . overview_message_id { Some ( m ) => m , None => return Err ( SignupBoardError :: OverviewMessageNotSet . into ( ) ) , } ; let chan = match self . overview_channel_id { Some ( c ) => c , None => return Err ( SignupBoardError :: OverviewChannelNotSet . into ( ) ) , } ; let gid = load_guild_id ( ctx ) . await ? ; let active_trainings = db :: Training :: all_active ( ctx ) . await ? ; let mut trainings : Vec < ( db :: Training , i64 ) > = Vec :: new ( ) ; for at in active_trainings { let count = at . get_signup_count ( ctx ) . await ? ; trainings . push ( ( at , count ) ) ; } // Sort by custom names and dates trainings . sort_by ( | a , b | title_sort_value ( & b . 0 ) . cmp ( & title_sort_value ( & a . 0 ) ) ) ; trainings . sort_by ( | a , b | a . 0 . date . date ( ) . cmp ( & b . 0 . date . date ( ) ) ) ; // Group by dates let mut groups : Vec < ( NaiveDate , Vec < ( db :: Training , i64 ) > ) > = Vec :: new ( ) ; for ( g , t ) in trainings . into_iter ( ) . group_by ( | a | a . 0 . date . date ( ) ) . into_iter ( ) { groups . push ( ( g , t . collect :: < Vec < _ > > ( ) ) ) ; } // Get the signup board channels for the dates let mut ready : Vec < ( NaiveDate , usize , Option < ChannelId > , Vec < ( db :: Training , i64 ) > , ) > = Vec :: new ( ) ; for ( d , t ) in groups { let chan = db :: SignupBoardChannel :: by_day ( ctx , d ) . await . ok ( ) . map ( | sbc | sbc . channel ( ) ) ; //FIXME do this properly without an extra db access let mut total_users = db :: User :: by_signed_up_and_date ( ctx , d ) . await ? ; total_users . sort_by_key ( | u | u . id ) ; total_users . dedup_by_key ( | u | u . id ) ; ready . push ( ( d , total_users . len ( ) , chan , t ) ) ; } chan . edit_message ( ctx , msg , | m | { m . content ( " " ) ; m . set_embed ( embeds :: signup_board_overview ( ready , gid ) ) ; m . components ( | c | c . add_action_row ( components :: register_list_action_row ( ) ) ) } ) . await ? ; Ok ( ( ) ) }
Updates the overview message if available
Updates the overview message if available
&self
ctx
&Context