push 1 checkpoiint *holy hell i sure hope it works*
This commit is contained in:
@@ -1,3 +1,21 @@
|
||||
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 is_deleted: Option<bool>,
|
||||
pub is_edited: Option<bool>,
|
||||
pub is_censored: Option<bool>,
|
||||
}
|
||||
use scylla::{
|
||||
client::session::Session,
|
||||
deserialize::row::DeserializeRow,
|
||||
@@ -190,6 +208,89 @@ impl From<TwilightUser> for User {
|
||||
}
|
||||
}
|
||||
|
||||
// --- BEGIN: Payphone Message and Report Models ---
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Message {
|
||||
pub call_id: u64,
|
||||
pub message_id: u64,
|
||||
pub message_metadata: MessageMetadata,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
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
|
||||
.query_unpaged(
|
||||
r#"
|
||||
SELECT call_id, message_id, message_metadata
|
||||
FROM payphone.messages
|
||||
WHERE call_id = ? AND message_id = ?
|
||||
LIMIT 1;
|
||||
"#,
|
||||
(call_id, message_id),
|
||||
)
|
||||
.await
|
||||
.map_err(DatabaseError::QueryError)?
|
||||
.into_rows_result()
|
||||
.map_err(|_| DatabaseError::ResultNotRows)?;
|
||||
match result.single_row::<(i64, i64, MessageMetadata)>() {
|
||||
Ok(row) => Ok(Some(Self {
|
||||
call_id: i64_to_u64(row.0),
|
||||
message_id: i64_to_u64(row.1),
|
||||
message_metadata: row.2,
|
||||
})),
|
||||
Err(error) => match error {
|
||||
SingleRowError::DeserializationFailed(_) | SingleRowError::TypeCheckFailed(_) => Err(DatabaseError::DeserializationFailed),
|
||||
SingleRowError::UnexpectedRowCount(_) => Ok(None),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Report {
|
||||
pub report_id: u64,
|
||||
pub message: MessageMetadata,
|
||||
pub created_at: OffsetDateTime,
|
||||
pub reviewed_at: Option<OffsetDateTime>,
|
||||
pub created_by_ids: Vec<u64>,
|
||||
pub reviewed_by_id: Option<u64>,
|
||||
pub resolution: Option<String>,
|
||||
}
|
||||
|
||||
impl Report {
|
||||
pub async fn insert(&self, session: &Session) -> Result<(), DatabaseError> {
|
||||
session
|
||||
.query_unpaged(
|
||||
r#"
|
||||
INSERT INTO payphone.reports (
|
||||
report_id,
|
||||
message,
|
||||
created_at,
|
||||
reviewed_at,
|
||||
created_by_ids,
|
||||
reviewed_by_id,
|
||||
resolution
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?);
|
||||
"#,
|
||||
(
|
||||
u64_to_i64(self.report_id),
|
||||
&self.message,
|
||||
self.created_at,
|
||||
self.reviewed_at,
|
||||
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(),
|
||||
),
|
||||
)
|
||||
.await
|
||||
.map_err(DatabaseError::QueryError)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Server {
|
||||
pub id: u64,
|
||||
|
||||
Reference in New Issue
Block a user