moved message structs and ran cargo fmt

This commit is contained in:
Anish Nayak
2025-08-12 19:59:53 +01:00
parent 14e6d59ddd
commit 540db21c45
11 changed files with 211 additions and 171 deletions
+90 -66
View File
@@ -1,66 +1,4 @@
use scylla::{SerializeValue, DeserializeValue};
#[derive(Debug, Clone, SerializeValue, DeserializeValue)]
pub struct MessageMetadata {
pub call_id: i64,
pub author_id: i64,
pub author_name: Option<String>,
pub author_avatar_url: Option<String>,
pub author_mask: Option<String>,
pub content: Option<String>,
pub attachments: Option<Vec<String>>,
pub sticker: Option<i64>,
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::{DeserializeValue, SerializeValue};
use scylla::{
client::session::Session,
deserialize::row::DeserializeRow,
@@ -253,6 +191,83 @@ impl From<TwilightUser> for User {
}
}
#[derive(Debug, Clone, SerializeValue, DeserializeValue)]
pub struct MessageMetadata {
pub call_id: i64,
pub author_id: i64,
pub author_name: Option<String>,
pub author_avatar_url: Option<String>,
pub author_mask: Option<String>,
pub content: Option<String>,
pub attachments: Option<Vec<String>>,
pub sticker: Option<i64>,
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,
)
}
}
// --- BEGIN: Payphone Message and Report Models ---
#[derive(Debug, Clone)]
@@ -263,7 +278,11 @@ pub struct Message {
}
impl Message {
pub async fn get_by_id(call_id: u64, message_id: u64, session: &Session) -> Result<Option<Self>, DatabaseError> {
pub async fn get_by_id(
call_id: u64,
message_id: u64,
session: &Session,
) -> Result<Option<Self>, DatabaseError> {
let call_id = u64_to_i64(call_id);
let message_id = u64_to_i64(message_id);
let result = session
@@ -287,7 +306,9 @@ impl Message {
message_metadata: row.2,
})),
Err(error) => match error {
SingleRowError::DeserializationFailed(_) | SingleRowError::TypeCheckFailed(_) => Err(DatabaseError::DeserializationFailed),
SingleRowError::DeserializationFailed(_) | SingleRowError::TypeCheckFailed(_) => {
Err(DatabaseError::DeserializationFailed)
}
SingleRowError::UnexpectedRowCount(_) => Ok(None),
},
}
@@ -325,7 +346,10 @@ impl Report {
&self.message,
self.created_at,
self.reviewed_at,
self.created_by_ids.iter().map(|&id| u64_to_i64(id)).collect::<Vec<i64>>(),
self.created_by_ids
.iter()
.map(|&id| u64_to_i64(id))
.collect::<Vec<i64>>(),
self.reviewed_by_id.map(u64_to_i64),
self.resolution.as_ref(),
),