mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-23 22:09:22 +00:00
33 lines
928 B
Rust
33 lines
928 B
Rust
|
//! # 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 as u64,
|
||
|
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()
|
||
|
}
|
||
|
}
|