1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-23 22:09:22 +00:00
comunicapiv3/src/api_data/list_unread_conversations_api.rs

33 lines
926 B
Rust
Raw Normal View History

2020-06-22 16:55:24 +00:00
//! # 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,
2020-06-25 08:08:34 +00:00
userID: conv.user_id.id(),
2020-06-22 16:55:24 +00:00
message: conv.message.clone()
}
}
/// Turn a list of unread conversation into API conversations
pub fn for_list(l: &Vec<UnreadConversation>) -> Vec<UnreadConversationAPI> {
l.iter()
.map(|row| Self::new(row))
.collect()
}
}