commit
0dfebbad9d
@ -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(
|
||||
x.messages.unwrap_or_default(),
|
||||
)
|
||||
.ok()
|
||||
.unwrap_or_default(),
|
||||
messages: {
|
||||
let mut messages: Vec<ThreadMessage> = serde_json::from_value(
|
||||
x.messages.unwrap_or_default(),
|
||||
)
|
||||
.ok()
|
||||
.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(),
|
||||
}))
|
||||
})
|
||||
|
||||
@ -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?;
|
||||
|
||||
@ -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?;
|
||||
|
||||
@ -100,12 +100,11 @@ pub async fn thread_get(
|
||||
.into_iter()
|
||||
.map(|x| ThreadMessage {
|
||||
id: x.id.into(),
|
||||
author_id: if thread_type == ThreadType::Report
|
||||
&& users
|
||||
.iter()
|
||||
.find(|y| x.author_id == Some(y.id.into()))
|
||||
.map(|x| x.role.is_mod())
|
||||
.unwrap_or(false)
|
||||
author_id: if users
|
||||
.iter()
|
||||
.find(|y| x.author_id == Some(y.id.into()))
|
||||
.map(|x| x.role.is_mod())
|
||||
.unwrap_or(false)
|
||||
{
|
||||
None
|
||||
} else {
|
||||
@ -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?;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user