Private
Public Access
1
0

kpcli: adds 'db' subcommand for interacting with the database

This commit is contained in:
2025-01-08 13:32:55 -08:00
parent 89f8d21ebb
commit 793faab721
10 changed files with 197 additions and 29 deletions

View File

@@ -1,14 +1,48 @@
use std::fmt::Display;
use time::OffsetDateTime;
use pretty::RcDoc;
use kordophone::model::Conversation;
pub struct PrintableConversation {
pub guid: String,
pub date: OffsetDateTime,
pub unread_count: i32,
pub last_message_preview: Option<String>,
pub participants: Vec<String>,
pub display_name: Option<String>,
}
impl From<kordophone::model::Conversation> for PrintableConversation {
fn from(value: kordophone::model::Conversation) -> Self {
Self {
guid: value.guid,
date: value.date,
unread_count: value.unread_count,
last_message_preview: value.last_message_preview,
participants: value.participant_display_names,
display_name: value.display_name,
}
}
}
impl From<kordophone_db::models::Conversation> for PrintableConversation {
fn from(value: kordophone_db::models::Conversation) -> Self {
Self {
guid: value.guid,
date: OffsetDateTime::from_unix_timestamp(value.date.and_utc().timestamp()).unwrap(),
unread_count: value.unread_count.into(),
last_message_preview: value.last_message_preview,
participants: value.participants.into_iter().map(|p| p.display_name).collect(),
display_name: value.display_name,
}
}
}
pub struct ConversationPrinter<'a> {
doc: RcDoc<'a, Conversation>
doc: RcDoc<'a, PrintableConversation>
}
impl<'a> ConversationPrinter<'a> {
pub fn new(conversation: &'a Conversation) -> Self {
pub fn new(conversation: &'a PrintableConversation) -> Self {
let preview = conversation.last_message_preview
.as_deref()
.unwrap_or("<null>")
@@ -27,7 +61,7 @@ impl<'a> ConversationPrinter<'a> {
.append("[")
.append(RcDoc::line()
.append(
conversation.participant_display_names
conversation.participants
.iter()
.map(|name|
RcDoc::text(name)