Fix issue with moderator identities being revealed (#892)

* Fix issue with moderator identities being revealed

* Fix on multiple threads route

* Fix thread notifs

* Fix failing test

* fix thread messages returning nothing
This commit is contained in:
Geometrically
2024-03-19 17:25:49 -07:00
committed by GitHub
parent 730913bec4
commit decfcb6c27
20 changed files with 79 additions and 334 deletions

View File

@@ -21,13 +21,13 @@ pub struct Thread {
pub messages: Vec<ThreadMessage>,
pub members: Vec<UserId>,
pub show_in_mod_inbox: bool,
}
pub struct ThreadMessageBuilder {
pub author_id: Option<UserId>,
pub body: MessageBody,
pub thread_id: ThreadId,
pub hide_identity: bool,
}
#[derive(Serialize, Deserialize, Clone)]
@@ -37,6 +37,7 @@ pub struct ThreadMessage {
pub author_id: Option<UserId>,
pub body: MessageBody,
pub created: DateTime<Utc>,
pub hide_identity: bool,
}
impl ThreadMessageBuilder {
@@ -49,16 +50,17 @@ impl ThreadMessageBuilder {
sqlx::query!(
"
INSERT INTO threads_messages (
id, author_id, body, thread_id
id, author_id, body, thread_id, hide_identity
)
VALUES (
$1, $2, $3, $4
$1, $2, $3, $4, $5
)
",
thread_message_id as ThreadMessageId,
self.author_id.map(|x| x.0),
serde_json::value::to_value(self.body.clone())?,
self.thread_id as ThreadId,
self.hide_identity
)
.execute(&mut **transaction)
.await?;
@@ -131,9 +133,9 @@ impl Thread {
let thread_ids_parsed: Vec<i64> = thread_ids.iter().map(|x| x.0).collect();
let threads = sqlx::query!(
"
SELECT t.id, t.thread_type, t.mod_id, t.report_id, t.show_in_mod_inbox,
SELECT t.id, t.thread_type, t.mod_id, t.report_id,
ARRAY_AGG(DISTINCT tm.user_id) filter (where tm.user_id is not null) members,
JSONB_AGG(DISTINCT jsonb_build_object('id', tmsg.id, 'author_id', tmsg.author_id, 'thread_id', tmsg.thread_id, 'body', tmsg.body, 'created', tmsg.created)) filter (where tmsg.id is not null) messages
JSONB_AGG(DISTINCT jsonb_build_object('id', tmsg.id, 'author_id', tmsg.author_id, 'thread_id', tmsg.thread_id, 'body', tmsg.body, 'created', tmsg.created, 'hide_identity', tmsg.hide_identity)) filter (where tmsg.id is not null) messages
FROM threads t
LEFT OUTER JOIN threads_messages tmsg ON tmsg.thread_id = t.id
LEFT OUTER JOIN threads_members tm ON tm.thread_id = t.id
@@ -159,7 +161,6 @@ impl Thread {
messages
},
members: x.members.unwrap_or_default().into_iter().map(UserId).collect(),
show_in_mod_inbox: x.show_in_mod_inbox,
}))
})
.try_collect::<Vec<Thread>>()
@@ -229,7 +230,7 @@ impl ThreadMessage {
let message_ids_parsed: Vec<i64> = message_ids.iter().map(|x| x.0).collect();
let messages = sqlx::query!(
"
SELECT tm.id, tm.author_id, tm.thread_id, tm.body, tm.created
SELECT tm.id, tm.author_id, tm.thread_id, tm.body, tm.created, tm.hide_identity
FROM threads_messages tm
WHERE tm.id = ANY($1)
",
@@ -244,6 +245,7 @@ impl ThreadMessage {
body: serde_json::from_value(x.body)
.unwrap_or(MessageBody::Deleted { private: false }),
created: x.created,
hide_identity: x.hide_identity,
}))
})
.try_collect::<Vec<ThreadMessage>>()