#[cfg(feature = "raw")]
pub mod raw;
mod event;
use std::collections::HashMap;
pub use crate::event::*;
pub use chrono;
use chrono::{DateTime, Utc};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub struct Hangouts {
pub conversations: Vec<Conversation>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub struct Conversation {
pub conversation_id: String,
pub id: String,
pub name: Option<String>,
pub current_participants: Vec<ParticipantId>,
pub participants: HashMap<ParticipantId, Participant>,
pub events: Vec<Event>,
pub self_state: SelfState,
pub sort_timestamp: DateTime<Utc>,
pub group_link_sharing_status: LinkSharingStatus,
}
impl Conversation {
#[inline]
pub fn current_participants(&self) -> Vec<&Participant> {
self.current_participants
.iter()
.map(|id| self.participants.get(id).unwrap())
.collect()
}
#[inline]
pub fn sort_events_by_time(&mut self) {
self.events.sort_by(|a, b| a.timestamp.cmp(&b.timestamp));
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub struct Participant {
pub fallback_name: Option<String>,
pub typ: Option<ParticipantType>,
pub invitation_status: Option<InvitationStatus>,
pub new_invitation_status: Option<InvitationStatus>,
pub read_state: ReadState,
}
impl Participant {
#[inline]
pub fn name(&self) -> Option<&String> {
self.fallback_name.as_ref()
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub struct ParticipantId {
pub gaia_id: String,
pub chat_id: String,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub enum ParticipantType {
Gaia,
OffNetworkPhone,
}
impl ParticipantType {
#[inline]
pub fn is_gaia(&self) -> bool {
matches!(self, Self::Gaia)
}
#[inline]
pub fn is_off_network_phone(&self) -> bool {
matches!(self, Self::OffNetworkPhone)
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub struct SelfState {
pub status: ConversationStatus,
pub notification_level: NotificationLevel,
pub invitation: InvitationData,
pub views: Vec<View>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub enum ConversationStatus {
Active,
Invited,
}
impl ConversationStatus {
#[inline]
pub fn is_active(&self) -> bool {
matches!(self, Self::Active)
}
#[inline]
pub fn is_invited(&self) -> bool {
matches!(self, Self::Invited)
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub enum InvitationStatus {
Pending,
Accepted,
}
impl InvitationStatus {
#[inline]
pub fn is_pending(&self) -> bool {
matches!(self, Self::Pending)
}
#[inline]
pub fn is_accepted(&self) -> bool {
matches!(self, Self::Accepted)
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub struct InvitationData {
pub inviter: ParticipantId,
pub timestamp: DateTime<Utc>,
pub affinity: InvitationAffinity,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub enum InvitationAffinity {
None,
Low,
High,
}
impl InvitationAffinity {
#[inline]
pub fn is_none(&self) -> bool {
matches!(self, Self::None)
}
#[inline]
pub fn is_low(&self) -> bool {
matches!(self, Self::Low)
}
#[inline]
pub fn is_high(&self) -> bool {
matches!(self, Self::High)
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub enum NotificationLevel {
Quiet,
Ring,
}
impl NotificationLevel {
#[inline]
pub fn is_quiet(&self) -> bool {
matches!(self, Self::Quiet)
}
#[inline]
pub fn is_ring(&self) -> bool {
matches!(self, Self::Ring)
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub struct ReadState {
pub timestamp: DateTime<Utc>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub enum View {
Inbox,
Archived,
}
impl View {
#[inline]
pub fn is_inbox(&self) -> bool {
matches!(self, Self::Inbox)
}
#[inline]
pub fn is_archived(&self) -> bool {
matches!(self, Self::Archived)
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde-impl", derive(serde::Deserialize, serde::Serialize))]
pub enum LinkSharingStatus {
Off,
On,
}
impl LinkSharingStatus {
#[inline]
pub fn is_off(&self) -> bool {
matches!(self, Self::Off)
}
#[inline]
pub fn is_on(&self) -> bool {
matches!(self, Self::On)
}
}