daemon: add support for getting messages from db
This commit is contained in:
@@ -74,6 +74,28 @@ impl DbusRepository for ServerImpl {
|
||||
fn sync_all_conversations(&mut self) -> Result<(), dbus::MethodErr> {
|
||||
self.send_event_sync(Event::SyncAllConversations)
|
||||
}
|
||||
|
||||
fn get_messages(&mut self, conversation_id: String, last_message_id: String) -> Result<Vec<arg::PropMap>, dbus::MethodErr> {
|
||||
let last_message_id_opt = if last_message_id.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(last_message_id)
|
||||
};
|
||||
|
||||
self.send_event_sync(|r| Event::GetMessages(conversation_id, last_message_id_opt, r))
|
||||
.and_then(|messages| {
|
||||
let result = messages.into_iter().map(|msg| {
|
||||
let mut map = arg::PropMap::new();
|
||||
map.insert("id".into(), arg::Variant(Box::new(msg.id)));
|
||||
map.insert("text".into(), arg::Variant(Box::new(msg.text)));
|
||||
map.insert("date".into(), arg::Variant(Box::new(msg.date.and_utc().timestamp())));
|
||||
map.insert("sender".into(), arg::Variant(Box::new(msg.sender.display_name())));
|
||||
map
|
||||
}).collect();
|
||||
|
||||
Ok(result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl DbusSettings for ServerImpl {
|
||||
|
||||
Reference in New Issue
Block a user