use super::{Contact, Scene};
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
pub struct FriendContact {
pub scene: Scene,
pub peer: String,
pub name: Option<String>,
}
impl Contact for FriendContact {
fn scene(&self) -> Scene {
Scene::Friend
}
fn peer(&self) -> &str {
&self.peer
}
fn name(&self) -> Option<&str> {
self.name.as_deref()
}
fn is_friend(&self) -> bool {
true
}
fn is_group(&self) -> bool {
false
}
}
#[cfg(feature = "contact")]
#[macro_export]
macro_rules! contact_friend {
( $( $key:ident : $value:expr ),* $(,)? ) => {{
use $crate::contact::{FriendContact, Scene};
let mut contact = FriendContact {
scene: Scene::Friend,
..FriendContact::default()
};
$(
contact.$key = contact_friend!(@convert $key, $value);
)*
contact
}};
($peer:expr, $name:expr) => {{
use $crate::contact::{FriendContact, Scene};
let mut contact = FriendContact {
scene: Scene::Friend,
..FriendContact::default()
};
contact.peer = $peer.to_string();
contact.name = Some($name.to_string());
contact
}};
($peer:expr) => {{
let mut contact = $crate::contact::FriendContact {
scene: $crate::contact::Scene::Friend,
..$crate::contact::FriendContact::default()
};
contact.peer = $peer.to_string();
contact
}};
(@convert peer, $v:expr) => { $v.to_string() };
(@convert name, None) => { None };
(@convert name, $v:expr) => { Some($v.to_string()) };
}