Merge pull request #571 from modrinth/threads-fixes

more threads fixes
This commit is contained in:
Prospector 2023-04-13 10:18:28 -07:00 committed by GitHub
commit 0dfebbad9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 15 deletions

View File

@ -20,7 +20,7 @@ pub struct ThreadMessageBuilder {
pub author_id: Option<UserId>,
pub body: MessageBody,
pub thread_id: ThreadId,
pub show_in_mod_inbox: Option<bool>,
pub show_in_mod_inbox: bool,
}
#[derive(Deserialize)]
@ -148,11 +148,15 @@ impl Thread {
Ok(e.right().map(|x| Thread {
id: ThreadId(x.id),
type_: ThreadType::from_str(&x.thread_type),
messages: serde_json::from_value(
messages: {
let mut messages: Vec<ThreadMessage> = serde_json::from_value(
x.messages.unwrap_or_default(),
)
.ok()
.unwrap_or_default(),
.unwrap_or_default();
messages.sort_by(|a, b| a.created.cmp(&b.created));
messages
},
members: x.members.unwrap_or_default().into_iter().map(UserId).collect(),
}))
})

View File

@ -645,7 +645,7 @@ pub async fn project_edit(
old_status: project_item.inner.status,
},
thread_id: thread,
show_in_mod_inbox: None,
show_in_mod_inbox: false,
}
.insert(&mut transaction)
.await?;

View File

@ -325,7 +325,7 @@ pub async fn report_edit(
author_id: Some(user.id.into()),
body: MessageBody::ThreadClosure,
thread_id: thread,
show_in_mod_inbox: None,
show_in_mod_inbox: false,
}
.insert(&mut transaction)
.await?;

View File

@ -100,8 +100,7 @@ pub async fn thread_get(
.into_iter()
.map(|x| ThreadMessage {
id: x.id.into(),
author_id: if thread_type == ThreadType::Report
&& users
author_id: if users
.iter()
.find(|y| x.author_id == Some(y.id.into()))
.map(|x| x.role.is_mod())
@ -152,6 +151,16 @@ pub async fn thread_send_message(
return Ok(HttpResponse::NotFound().body(""));
}
match &new_message.body {
MessageBody::Text { .. } => {}
_ => {
return Err(ApiError::InvalidInput(
"You may only send text messages through this route!"
.to_string(),
))
}
}
let mod_notif = if thread.type_ == ThreadType::Project {
let status = sqlx::query!(
"SELECT m.status FROM mods m WHERE thread_id = $1",
@ -172,7 +181,7 @@ pub async fn thread_send_message(
author_id: Some(user.id.into()),
body: new_message.body.clone(),
thread_id: thread.id,
show_in_mod_inbox: Some(mod_notif),
show_in_mod_inbox: mod_notif,
}
.insert(&mut transaction)
.await?;