mirror of
https://github.com/chatmail/core.git
synced 2026-05-18 22:36:29 +03:00
Add documentation to contact module
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
//! Contacts module
|
//! Contacts module
|
||||||
|
|
||||||
#![allow(missing_docs)]
|
|
||||||
|
|
||||||
use std::cmp::Reverse;
|
use std::cmp::Reverse;
|
||||||
use std::collections::BinaryHeap;
|
use std::collections::BinaryHeap;
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
@@ -48,12 +46,18 @@ const SEEN_RECENTLY_SECONDS: i64 = 600;
|
|||||||
pub struct ContactId(u32);
|
pub struct ContactId(u32);
|
||||||
|
|
||||||
impl ContactId {
|
impl ContactId {
|
||||||
|
/// Undefined contact. Used as a placeholder for trashed messages.
|
||||||
pub const UNDEFINED: ContactId = ContactId::new(0);
|
pub const UNDEFINED: ContactId = ContactId::new(0);
|
||||||
|
|
||||||
/// The owner of the account.
|
/// The owner of the account.
|
||||||
///
|
///
|
||||||
/// The email-address is set by `set_config` using "addr".
|
/// The email-address is set by `set_config` using "addr".
|
||||||
pub const SELF: ContactId = ContactId::new(1);
|
pub const SELF: ContactId = ContactId::new(1);
|
||||||
|
|
||||||
|
/// ID of the contact for info messages.
|
||||||
pub const INFO: ContactId = ContactId::new(2);
|
pub const INFO: ContactId = ContactId::new(2);
|
||||||
|
|
||||||
|
/// ID of the contact for device messages.
|
||||||
pub const DEVICE: ContactId = ContactId::new(5);
|
pub const DEVICE: ContactId = ContactId::new(5);
|
||||||
const LAST_SPECIAL: ContactId = ContactId::new(9);
|
const LAST_SPECIAL: ContactId = ContactId::new(9);
|
||||||
|
|
||||||
@@ -177,6 +181,8 @@ pub struct Contact {
|
|||||||
)]
|
)]
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
pub enum Origin {
|
pub enum Origin {
|
||||||
|
/// Unknown origin. Can be used as a minimum origin to specify that the caller does not care
|
||||||
|
/// about origin of the contact.
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
|
|
||||||
/// The contact is a mailing list address, needed to unblock mailing lists
|
/// The contact is a mailing list address, needed to unblock mailing lists
|
||||||
@@ -257,12 +263,13 @@ pub(crate) enum Modifier {
|
|||||||
Created,
|
Created,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Verification status of the contact.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, FromPrimitive)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, FromPrimitive)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum VerifiedStatus {
|
pub enum VerifiedStatus {
|
||||||
/// Contact is not verified.
|
/// Contact is not verified.
|
||||||
Unverified = 0,
|
Unverified = 0,
|
||||||
// TODO: is this a thing?
|
/// SELF has verified the fingerprint of a contact. Currently unused.
|
||||||
Verified = 1,
|
Verified = 1,
|
||||||
/// SELF and contact have verified their fingerprints in both directions; in the UI typically checkmarks are shown.
|
/// SELF and contact have verified their fingerprints in both directions; in the UI typically checkmarks are shown.
|
||||||
BidirectVerified = 2,
|
BidirectVerified = 2,
|
||||||
@@ -275,6 +282,7 @@ impl Default for VerifiedStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Contact {
|
impl Contact {
|
||||||
|
/// Loads a contact snapshot from the database.
|
||||||
pub async fn load_from_db(context: &Context, contact_id: ContactId) -> Result<Self> {
|
pub async fn load_from_db(context: &Context, contact_id: ContactId) -> Result<Self> {
|
||||||
let mut contact = context
|
let mut contact = context
|
||||||
.sql
|
.sql
|
||||||
@@ -847,6 +855,7 @@ impl Contact {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns number of blocked contacts.
|
||||||
pub async fn get_blocked_cnt(context: &Context) -> Result<usize> {
|
pub async fn get_blocked_cnt(context: &Context) -> Result<usize> {
|
||||||
let count = context
|
let count = context
|
||||||
.sql
|
.sql
|
||||||
@@ -1138,7 +1147,7 @@ impl Contact {
|
|||||||
Ok(VerifiedStatus::Unverified)
|
Ok(VerifiedStatus::Unverified)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the address that verified the given contact
|
/// Returns the address that verified the given contact.
|
||||||
pub async fn get_verifier_addr(
|
pub async fn get_verifier_addr(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
contact_id: &ContactId,
|
contact_id: &ContactId,
|
||||||
@@ -1150,6 +1159,7 @@ impl Contact {
|
|||||||
.and_then(|peerstate| peerstate.get_verifier().map(|addr| addr.to_owned())))
|
.and_then(|peerstate| peerstate.get_verifier().map(|addr| addr.to_owned())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the ContactId that verified the given contact.
|
||||||
pub async fn get_verifier_id(
|
pub async fn get_verifier_id(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
contact_id: &ContactId,
|
contact_id: &ContactId,
|
||||||
@@ -1162,7 +1172,7 @@ impl Contact {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the ContactId that verified the given contact
|
/// Returns the number of real (i.e. non-special) contacts in the database.
|
||||||
pub async fn get_real_cnt(context: &Context) -> Result<usize> {
|
pub async fn get_real_cnt(context: &Context) -> Result<usize> {
|
||||||
if !context.sql.is_open().await {
|
if !context.sql.is_open().await {
|
||||||
return Ok(0);
|
return Ok(0);
|
||||||
@@ -1178,6 +1188,7 @@ impl Contact {
|
|||||||
Ok(count)
|
Ok(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if a contact with this ID exists.
|
||||||
pub async fn real_exists_by_id(context: &Context, contact_id: ContactId) -> Result<bool> {
|
pub async fn real_exists_by_id(context: &Context, contact_id: ContactId) -> Result<bool> {
|
||||||
if contact_id.is_special() {
|
if contact_id.is_special() {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
@@ -1193,6 +1204,7 @@ impl Contact {
|
|||||||
Ok(exists)
|
Ok(exists)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates the origin of the contact, but only if new origin is higher than the current one.
|
||||||
pub async fn scaleup_origin_by_id(
|
pub async fn scaleup_origin_by_id(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
contact_id: ContactId,
|
contact_id: ContactId,
|
||||||
@@ -1453,6 +1465,7 @@ fn cat_fingerprint(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Compares two email addresses, normalizing them beforehand.
|
||||||
pub fn addr_cmp(addr1: &str, addr2: &str) -> bool {
|
pub fn addr_cmp(addr1: &str, addr2: &str) -> bool {
|
||||||
let norm1 = addr_normalize(addr1).to_lowercase();
|
let norm1 = addr_normalize(addr1).to_lowercase();
|
||||||
let norm2 = addr_normalize(addr2).to_lowercase();
|
let norm2 = addr_normalize(addr2).to_lowercase();
|
||||||
|
|||||||
Reference in New Issue
Block a user