30 lines
1.2 KiB
Rust
30 lines
1.2 KiB
Rust
use dbus::arg;
|
|
use dbus_tree::MethodErr;
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
use crate::daemon::Daemon;
|
|
use crate::dbus::interface::NetBuzzertKordophoneServer as DbusServer;
|
|
|
|
impl DbusServer for Arc<Mutex<Daemon>> {
|
|
fn get_version(&mut self) -> Result<String, MethodErr> {
|
|
let daemon = self.lock().map_err(|_| MethodErr::failed("Failed to lock daemon"))?;
|
|
Ok(daemon.version.clone())
|
|
}
|
|
|
|
fn get_conversations(&mut self) -> Result<Vec<arg::PropMap>, dbus::MethodErr> {
|
|
// Get a repository instance and use it to fetch conversations
|
|
let mut daemon = self.lock().map_err(|_| MethodErr::failed("Failed to lock daemon"))?;
|
|
let conversations = daemon.get_conversations();
|
|
|
|
// Convert conversations to DBus property maps
|
|
let result = conversations.into_iter().map(|conv| {
|
|
let mut map = arg::PropMap::new();
|
|
map.insert("guid".into(), arg::Variant(Box::new(conv.guid)));
|
|
map.insert("display_name".into(), arg::Variant(Box::new(conv.display_name.unwrap_or_default())));
|
|
map.insert("unread_count".into(), arg::Variant(Box::new(conv.unread_count as i32)));
|
|
map
|
|
}).collect();
|
|
|
|
Ok(result)
|
|
}
|
|
}
|