//! # List of unread conversations use serde::{Serialize}; use crate::data::unread_conversation::UnreadConversation; #[derive(Serialize)] #[allow(non_snake_case)] pub struct UnreadConversationAPI { id: u64, conv_name: String, last_active: u64, userID: u64, message: String } impl UnreadConversationAPI { /// Construct a new instance pub fn new(conv: &UnreadConversation) -> UnreadConversationAPI { UnreadConversationAPI { id: conv.id, conv_name: conv.name.clone().unwrap_or(String::new()), last_active: conv.last_active, userID: conv.user_id.id(), message: conv.message.clone() } } /// Turn a list of unread conversation into API conversations pub fn for_list(l: &Vec) -> Vec { l.iter() .map(|row| Self::new(row)) .collect() } }