add: "ask about this" from neospring
This commit is contained in:
parent
f94570f74c
commit
2c83ed3d9d
9 changed files with 122 additions and 31 deletions
|
@ -2,6 +2,7 @@ use std::collections::HashMap;
|
|||
use oiseau::cache::Cache;
|
||||
use tetratto_shared::unix_epoch_timestamp;
|
||||
use crate::model::addr::RemoteAddr;
|
||||
use crate::model::communities::Post;
|
||||
use crate::model::communities_permissions::CommunityPermission;
|
||||
use crate::model::uploads::{MediaType, MediaUpload};
|
||||
use crate::model::{
|
||||
|
@ -38,13 +39,26 @@ impl DataManager {
|
|||
|
||||
auto_method!(get_question_by_id()@get_question_from_row -> "SELECT * FROM questions WHERE id = $1" --name="question" --returns=Question --cache-key-tmpl="atto.question:{}");
|
||||
|
||||
/// Get the post a given question is asking about.
|
||||
pub async fn get_question_asking_about(
|
||||
&self,
|
||||
question: &Question,
|
||||
) -> Result<Option<(User, Post)>> {
|
||||
Ok(if let Some(id) = question.context.asking_about {
|
||||
let post = self.get_post_by_id(id).await?;
|
||||
Some((self.get_user_by_id(post.owner).await?, post))
|
||||
} else {
|
||||
None
|
||||
})
|
||||
}
|
||||
|
||||
/// Fill the given vector of questions with their owner as well.
|
||||
pub async fn fill_questions(
|
||||
&self,
|
||||
questions: Vec<Question>,
|
||||
ignore_users: &[usize],
|
||||
) -> Result<Vec<(Question, User)>> {
|
||||
let mut out: Vec<(Question, User)> = Vec::new();
|
||||
) -> Result<Vec<(Question, User, Option<(User, Post)>)>> {
|
||||
let mut out: Vec<(Question, User, Option<(User, Post)>)> = Vec::new();
|
||||
|
||||
let mut seen_users: HashMap<usize, User> = HashMap::new();
|
||||
for question in questions {
|
||||
|
@ -53,7 +67,8 @@ impl DataManager {
|
|||
}
|
||||
|
||||
if let Some(ua) = seen_users.get(&question.owner) {
|
||||
out.push((question, ua.to_owned()));
|
||||
let asking_about = self.get_question_asking_about(&question).await?;
|
||||
out.push((question, ua.to_owned(), asking_about));
|
||||
} else {
|
||||
let user = if question.owner == 0 {
|
||||
User::anonymous()
|
||||
|
@ -62,7 +77,9 @@ impl DataManager {
|
|||
};
|
||||
|
||||
seen_users.insert(question.owner, user.clone());
|
||||
out.push((question, user));
|
||||
|
||||
let asking_about = self.get_question_asking_about(&question).await?;
|
||||
out.push((question, user, asking_about));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,12 +89,17 @@ impl DataManager {
|
|||
/// Filter to update questions to clean their owner for public APIs.
|
||||
pub fn questions_owner_filter(
|
||||
&self,
|
||||
questions: &Vec<(Question, User)>,
|
||||
) -> Vec<(Question, User)> {
|
||||
let mut out: Vec<(Question, User)> = Vec::new();
|
||||
questions: &Vec<(Question, User, Option<(User, Post)>)>,
|
||||
) -> Vec<(Question, User, Option<(User, Post)>)> {
|
||||
let mut out: Vec<(Question, User, Option<(User, Post)>)> = Vec::new();
|
||||
|
||||
for mut question in questions.clone() {
|
||||
question.1.clean();
|
||||
|
||||
if question.2.is_some() {
|
||||
question.2.as_mut().unwrap().0.clean();
|
||||
}
|
||||
|
||||
out.push(question);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue