commit
0dfebbad9d
@ -20,7 +20,7 @@ pub struct ThreadMessageBuilder {
|
|||||||
pub author_id: Option<UserId>,
|
pub author_id: Option<UserId>,
|
||||||
pub body: MessageBody,
|
pub body: MessageBody,
|
||||||
pub thread_id: ThreadId,
|
pub thread_id: ThreadId,
|
||||||
pub show_in_mod_inbox: Option<bool>,
|
pub show_in_mod_inbox: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@ -148,11 +148,15 @@ impl Thread {
|
|||||||
Ok(e.right().map(|x| Thread {
|
Ok(e.right().map(|x| Thread {
|
||||||
id: ThreadId(x.id),
|
id: ThreadId(x.id),
|
||||||
type_: ThreadType::from_str(&x.thread_type),
|
type_: ThreadType::from_str(&x.thread_type),
|
||||||
messages: serde_json::from_value(
|
messages: {
|
||||||
x.messages.unwrap_or_default(),
|
let mut messages: Vec<ThreadMessage> = serde_json::from_value(
|
||||||
)
|
x.messages.unwrap_or_default(),
|
||||||
.ok()
|
)
|
||||||
.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(),
|
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,
|
old_status: project_item.inner.status,
|
||||||
},
|
},
|
||||||
thread_id: thread,
|
thread_id: thread,
|
||||||
show_in_mod_inbox: None,
|
show_in_mod_inbox: false,
|
||||||
}
|
}
|
||||||
.insert(&mut transaction)
|
.insert(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@ -325,7 +325,7 @@ pub async fn report_edit(
|
|||||||
author_id: Some(user.id.into()),
|
author_id: Some(user.id.into()),
|
||||||
body: MessageBody::ThreadClosure,
|
body: MessageBody::ThreadClosure,
|
||||||
thread_id: thread,
|
thread_id: thread,
|
||||||
show_in_mod_inbox: None,
|
show_in_mod_inbox: false,
|
||||||
}
|
}
|
||||||
.insert(&mut transaction)
|
.insert(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@ -100,12 +100,11 @@ pub async fn thread_get(
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| ThreadMessage {
|
.map(|x| ThreadMessage {
|
||||||
id: x.id.into(),
|
id: x.id.into(),
|
||||||
author_id: if thread_type == ThreadType::Report
|
author_id: if users
|
||||||
&& users
|
.iter()
|
||||||
.iter()
|
.find(|y| x.author_id == Some(y.id.into()))
|
||||||
.find(|y| x.author_id == Some(y.id.into()))
|
.map(|x| x.role.is_mod())
|
||||||
.map(|x| x.role.is_mod())
|
.unwrap_or(false)
|
||||||
.unwrap_or(false)
|
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -152,6 +151,16 @@ pub async fn thread_send_message(
|
|||||||
return Ok(HttpResponse::NotFound().body(""));
|
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 mod_notif = if thread.type_ == ThreadType::Project {
|
||||||
let status = sqlx::query!(
|
let status = sqlx::query!(
|
||||||
"SELECT m.status FROM mods m WHERE thread_id = $1",
|
"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()),
|
author_id: Some(user.id.into()),
|
||||||
body: new_message.body.clone(),
|
body: new_message.body.clone(),
|
||||||
thread_id: thread.id,
|
thread_id: thread.id,
|
||||||
show_in_mod_inbox: Some(mod_notif),
|
show_in_mod_inbox: mod_notif,
|
||||||
}
|
}
|
||||||
.insert(&mut transaction)
|
.insert(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user