diff --git a/src/db.rs b/src/db.rs index 0119361..51dfbdf 100644 --- a/src/db.rs +++ b/src/db.rs @@ -138,25 +138,37 @@ impl DB { } } - // if last_post.is_none() || row.post_uuid != last_post.as_ref().unwrap().uuid { - // if let Some(post) = last_post { - // last_thread.as_mut().unwrap().posts.push(post) - // } - // - // if row.post_uuid.is_some() { - // last_post = Some(Post { - // uuid: row.post_uuid, - // contents: row.post_contents, - // author: User { - // uuid: row.user_uuid.unwrap(), - // email: row.user_email.unwrap_or(String::new()), - // username: row.user_username.unwrap_or(String::new()), - // password_hash: row.user_password_hash.unwrap_or(String::new()), - // is_admin: row.user_is_admin.unwrap_or(false) - // } - // }) - // } - // } + if last_post.is_none() || row.post_uuid.is_some() && row.post_uuid.unwrap() != last_post.as_ref().unwrap().uuid { + if let Some(ref post) = last_post { + last_thread.as_mut().unwrap().posts.push(post.clone()) + } + + if row.post_uuid.is_some() { + last_post = Some(Post { + uuid: row.post_uuid.unwrap(), + contents: row.post_contents.unwrap_or(String::new()), + author: User { + uuid: row.user_uuid.unwrap(), + email: row.user_email.unwrap_or(String::new()), + username: row.user_username.unwrap_or(String::new()), + password_hash: row.user_password_hash.unwrap_or(String::new()), + is_admin: row.user_is_admin.unwrap_or(false) + } + }) + } + } + } + + if last_post.is_some() { + last_thread.as_mut().unwrap().posts.push(last_post.unwrap()); + } + + if last_thread.is_some() { + last_board.as_mut().unwrap().threads.push(last_thread.unwrap()); + } + + if last_board.is_some() { + site.as_mut().unwrap().boards.push(last_board.unwrap()); } if let Some(site) = site {