push 2 for replied-to messages *am i cooked or am i cooking*

This commit is contained in:
Anish Nayak
2025-08-12 18:26:55 +01:00
parent 9549e70593
commit 14e6d59ddd
3 changed files with 56 additions and 1 deletions
+1
View File
@@ -18,6 +18,7 @@ CREATE TYPE IF NOT EXISTS payphone.message_metadata (
propagation_message_id BIGINT,
propagation_channel_id BIGINT,
replying_to_id BIGINT,
message_replied_to_metadata FROZEN<payphone.message_metadata>,
is_deleted BOOLEAN,
is_edited BOOLEAN,
is_censored BOOLEAN
+45
View File
@@ -12,10 +12,55 @@ pub struct MessageMetadata {
pub propagation_message_id: Option<i64>,
pub propagation_channel_id: Option<i64>,
pub replying_to_id: Option<i64>,
pub message_replied_to_metadata: Option<Box<MessageMetadata>>,
pub is_deleted: Option<bool>,
pub is_edited: Option<bool>,
pub is_censored: Option<bool>,
}
impl<'a> Object<'a> for MessageMetadata {
type Row = (
i64, i64, Option<String>, Option<String>, Option<String>, Option<String>, Option<Vec<String>>, Option<i64>, Option<i64>, Option<i64>, Option<i64>, Option<Box<MessageMetadata>>, Option<bool>, Option<bool>, Option<bool>
);
fn from_row(row: Self::Row) -> Self {
Self {
call_id: row.0,
author_id: row.1,
author_name: row.2,
author_avatar_url: row.3,
author_mask: row.4,
content: row.5,
attachments: row.6,
sticker: row.7,
propagation_message_id: row.8,
propagation_channel_id: row.9,
replying_to_id: row.10,
message_replied_to_metadata: row.11,
is_deleted: row.12,
is_edited: row.13,
is_censored: row.14,
}
}
fn to_row(value: Self) -> Self::Row {
(
value.call_id,
value.author_id,
value.author_name,
value.author_avatar_url,
value.author_mask,
value.content,
value.attachments,
value.sticker,
value.propagation_message_id,
value.propagation_channel_id,
value.replying_to_id,
value.message_replied_to_metadata,
value.is_deleted,
value.is_edited,
value.is_censored,
)
}
}
use scylla::{
client::session::Session,
deserialize::row::DeserializeRow,
+10 -1
View File
@@ -38,10 +38,18 @@ impl MessageCommand<State> for ReportMessageCommand {
.map_err(|_| InteractionError::InteractionNotFound)?
.ok_or(InteractionError::InteractionNotFound)?;
// If the message is a reply, fetch the replied-to message and denormalize its metadata
let mut message_metadata = message.message_metadata.clone();
if let Some(replying_to_id) = message_metadata.replying_to_id {
if let Ok(Some(reply_msg)) = Message::get_by_id(call_id, replying_to_id as u64, db).await {
message_metadata.message_replied_to_metadata = Some(Box::new(reply_msg.message_metadata));
}
}
// Build the report using the new UDT-based message metadata
let report = Report {
report_id: get_random_u64(),
message: message.message_metadata.clone(),
message: message_metadata,
created_at: time::OffsetDateTime::now_utc(),
reviewed_at: None,
created_by_ids: vec![ctx.event.author_id().map(|id| id.get()).unwrap_or(0)],
@@ -49,6 +57,7 @@ impl MessageCommand<State> for ReportMessageCommand {
resolution: None,
};
// Insert the report
report.insert(db).await.map_err(|_| InteractionError::DeferringFailed)?;