beeper_desktop_api/models/
chat.rs1use serde::{Deserialize, Serialize};
4use super::message::Message;
5use super::user::User;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Participants {
10 pub items: Vec<User>,
12 #[serde(rename = "hasMore")]
14 pub has_more: bool,
15 pub total: u32,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct Chat {
22 pub id: String,
24 #[serde(skip_serializing_if = "Option::is_none")]
26 #[serde(rename = "localChatID")]
27 pub local_chat_id: Option<String>,
28 #[serde(rename = "accountID")]
30 pub account_id: String,
31 pub network: String,
33 pub title: String,
35 #[serde(rename = "type")]
37 pub chat_type: String,
38 pub participants: Participants,
40 #[serde(skip_serializing_if = "Option::is_none")]
42 #[serde(rename = "lastActivity")]
43 pub last_activity: Option<String>,
44 #[serde(rename = "unreadCount")]
46 pub unread_count: u32,
47 #[serde(skip_serializing_if = "Option::is_none")]
49 #[serde(rename = "lastReadMessageSortKey")]
50 pub last_read_message_sort_key: Option<u64>,
51 #[serde(rename = "isArchived")]
53 pub is_archived: bool,
54 #[serde(rename = "isMuted")]
56 pub is_muted: bool,
57 #[serde(rename = "isPinned")]
59 pub is_pinned: bool,
60 #[serde(skip_serializing_if = "Option::is_none")]
62 pub preview: Option<Box<Message>>,
63}
64
65impl Chat {
66 pub fn display_name(&self) -> String {
71 if self.chat_type == "single" {
72 if let Some(first_participant) = self.participants.items.iter().filter(|p| !p.is_self.unwrap_or(false)).next() {
74 if let Some(full_name) = &first_participant.full_name {
75 return full_name.clone();
76 }
77 if let Some(username) = &first_participant.username {
78 return username.clone();
79 }
80 }
81 }
82
83 self.title.clone()
85 }
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct CreateChatInput {
91 #[serde(rename = "accountID")]
93 pub account_id: String,
94 #[serde(rename = "participantIDs")]
96 pub participant_ids: Vec<String>,
97 #[serde(skip_serializing_if = "Option::is_none")]
99 pub title: Option<String>,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct CreateChatOutput {
105 #[serde(rename = "chatID")]
107 pub chat_id: String,
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize)]
112pub struct ListChatsOutput {
113 pub items: Vec<Chat>,
115 #[serde(rename = "hasMore")]
117 pub has_more: bool,
118 #[serde(skip_serializing_if = "Option::is_none")]
120 #[serde(rename = "oldestCursor")]
121 pub oldest_cursor: Option<String>,
122 #[serde(skip_serializing_if = "Option::is_none")]
124 #[serde(rename = "newestCursor")]
125 pub newest_cursor: Option<String>,
126}
127
128#[derive(Debug, Clone, Serialize, Deserialize)]
130pub struct SearchChatsOutput {
131 pub items: Vec<Chat>,
133 #[serde(skip_serializing_if = "Option::is_none")]
135 pub chats: Option<std::collections::HashMap<String, Chat>>,
136 #[serde(rename = "hasMore")]
138 pub has_more: bool,
139 #[serde(skip_serializing_if = "Option::is_none")]
141 #[serde(rename = "oldestCursor")]
142 pub oldest_cursor: Option<String>,
143 #[serde(skip_serializing_if = "Option::is_none")]
145 #[serde(rename = "newestCursor")]
146 pub newest_cursor: Option<String>,
147}