~fd/beetboard

a284dac2258169e2297263255caa7947b3b3ba51 — Ersei Saggi 8 months ago 08f54ce
Bugfixes
2 files changed, 19 insertions(+), 7 deletions(-)

M src/lib.rs
M src/strings.rs
M src/lib.rs => src/lib.rs +18 -6
@@ 110,7 110,7 @@ impl BeetClient {
        }
        if command.len() == 1
            || command.len() > 3
            || (command.len() == 2 && strings::HELP_COMMANDS.contains(&command[2]))
            || (command.len() == 2 && strings::HELP_COMMANDS.contains(&command[1]))
        {
            return strings::POST_HELP.to_owned() + strings::PROMPT;
        }


@@ 181,14 181,27 @@ impl BeetClient {
        if command.len() == 2 && strings::HELP_COMMANDS.contains(&command[1]) {
            return strings::SHOW_HELP.to_owned();
        }

        let mut output: String = "".to_string();

        // Could be a lot better with joins, but I don't know how to do that :(
        let post_finder = post::Entity::find()
        let mut post_finder = post::Entity::find()
            .find_with_related(user::Entity)
            .filter(post::Column::Parent.is_null())
            .order_by_asc(post::Column::Id)
            .limit(10);
            .filter(post::Column::Parent.is_null());

        if command.len() == 2 {
            let before = command[1].parse::<i32>();
            if before.is_err() {
                return strings::SHOW_HELP.to_owned() + strings::PROMPT;
            }

            post_finder = post_finder
                .filter(post::Column::Id.lt(before.unwrap()))
                .order_by_asc(post::Column::Id)
                .limit(10);
        } else {
            post_finder = post_finder.order_by_asc(post::Column::Id).limit(10);
        }

        for p in post_finder.all(&self.conn).await.unwrap() {
            output.push_str(


@@ 222,7 235,6 @@ impl BeetClient {
        let post_finder = post::Entity::find()
            .filter(post::Column::Id.eq(id.unwrap()))
            .find_with_related(user::Entity)
            .filter(post::Column::Parent.is_null())
            .order_by_asc(post::Column::Id)
            .all(&self.conn)
            .await

M src/strings.rs => src/strings.rs +1 -1
@@ 65,7 65,7 @@ pub const POST_RESULT: &str = "Posted as #";
pub const SHOW_COMMANDS: [&str; 2] = ["show", "s"];

pub const SHOW_HELP: &str =
    "Usage: show [before ID (optional)]. Note that this only shows the 10 most recent top posts.\n";
    "Usage: show [before post ID (optional)]. Note that this only shows the 10 most recent top posts.\n";

pub const READ_COMMANDS: [&str; 2] = ["read", "r"];