use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::error::{Validate, ValidationError};
use crate::id::Id;
use crate::time::Timestamp;
pub const FEATURE_DM_READ_RECEIPTS: &str = "dm_read_receipts";
pub mod reasons {
pub const NOT_A_DM: &str = "not_a_dm";
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[non_exhaustive]
pub struct DmSeen {
pub channel_id: Id,
pub member_id: Id,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub seen_id: Option<Id>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub seen_at: Option<Timestamp>,
}
impl DmSeen {
pub fn new(channel_id: Id, member_id: Id, seen_id: Id, seen_at: Timestamp) -> Self {
DmSeen {
channel_id,
member_id,
seen_id: Some(seen_id),
seen_at: Some(seen_at),
}
}
pub fn removed(channel_id: Id, member_id: Id) -> Self {
DmSeen {
channel_id,
member_id,
seen_id: None,
seen_at: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[non_exhaustive]
pub struct DmReadReceipts {
pub channel_id: Id,
pub active: bool,
pub items: Vec<DmSeen>,
}
impl DmReadReceipts {
pub fn new(channel_id: Id, active: bool, items: Vec<DmSeen>) -> Self {
DmReadReceipts {
channel_id,
active,
items,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[non_exhaustive]
pub struct ReadReceiptSettings {
pub share_read_receipts: bool,
pub install_enabled: bool,
}
impl ReadReceiptSettings {
pub fn new(share_read_receipts: bool, install_enabled: bool) -> Self {
ReadReceiptSettings {
share_read_receipts,
install_enabled,
}
}
pub fn active(&self) -> bool {
self.share_read_receipts && self.install_enabled
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct SetReadReceiptsRequest {
pub share_read_receipts: bool,
}
impl SetReadReceiptsRequest {
pub fn new(share_read_receipts: bool) -> Self {
SetReadReceiptsRequest {
share_read_receipts,
}
}
}
impl Validate for SetReadReceiptsRequest {
fn validate(&self) -> Result<(), ValidationError> {
Ok(())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[non_exhaustive]
pub struct ReadReceiptsPolicyUpdated {
pub enabled: bool,
}
impl ReadReceiptsPolicyUpdated {
pub fn new(enabled: bool) -> Self {
ReadReceiptsPolicyUpdated { enabled }
}
}