821537186e
- Reorganized import statements in adapter tests for better readability - Replaced or_insert_with(Vec::new) with or_default() in test closures - Updated Cargo.lock with new dependency versions and checksums - Added TLS features to tonic dependency configuration - Included sqlx, chrono, and uuid dependencies with specific features - Added jsonwebtoken and arc-swap as project dependencies - Reformatted assertion statements to comply with line length limits - Adjusted base64 import order in engine codec module - Updated protobuf include statement formatting
78 lines
2.2 KiB
Rust
78 lines
2.2 KiB
Rust
//! Message edit history — maps to `message_edit` table.
|
|
//!
|
|
//! Immutable append-only log of every edit to a message.
|
|
//! Used for audit trails, "edited" indicators with hover-to-see-original,
|
|
//! and compliance / moderation review.
|
|
|
|
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
use uuid::Uuid;
|
|
|
|
/// One edit record. Stored every time a message body is modified.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
|
|
pub struct MessageEdit {
|
|
pub id: Uuid,
|
|
pub message_id: Uuid,
|
|
/// Who made the edit (usually the author; can be a moderator).
|
|
pub edited_by: Uuid,
|
|
/// Body content before the edit.
|
|
pub old_body: String,
|
|
/// Body content after the edit.
|
|
pub new_body: String,
|
|
pub edited_at: DateTime<Utc>,
|
|
}
|
|
|
|
/// Lightweight summary for the "edited" tooltip (no full body).
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct EditSummary {
|
|
pub edit_count: i64,
|
|
pub last_edited_at: Option<DateTime<Utc>>,
|
|
pub last_edited_by: Option<Uuid>,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_message_edit_serialize() {
|
|
let edit = MessageEdit {
|
|
id: Uuid::now_v7(),
|
|
message_id: Uuid::now_v7(),
|
|
edited_by: Uuid::now_v7(),
|
|
old_body: "before edit".to_string(),
|
|
new_body: "after edit".to_string(),
|
|
edited_at: Utc::now(),
|
|
};
|
|
|
|
let json = serde_json::to_value(&edit).unwrap();
|
|
assert_eq!(json["old_body"], "before edit");
|
|
assert_eq!(json["new_body"], "after edit");
|
|
}
|
|
|
|
#[test]
|
|
fn test_edit_summary_serialize() {
|
|
let summary = EditSummary {
|
|
edit_count: 3,
|
|
last_edited_at: Some(Utc::now()),
|
|
last_edited_by: Some(Uuid::now_v7()),
|
|
};
|
|
|
|
let json = serde_json::to_value(&summary).unwrap();
|
|
assert_eq!(json["edit_count"], 3);
|
|
}
|
|
|
|
#[test]
|
|
fn test_edit_summary_no_edits() {
|
|
let summary = EditSummary {
|
|
edit_count: 0,
|
|
last_edited_at: None,
|
|
last_edited_by: None,
|
|
};
|
|
|
|
let json = serde_json::to_value(&summary).unwrap();
|
|
assert_eq!(json["edit_count"], 0);
|
|
assert!(json["last_edited_at"].is_null());
|
|
}
|
|
}
|