Skip to main content

Invite

Struct Invite 

Source
pub struct Invite {
    pub id: String,
    pub creator_id: String,
    pub recipient_id: String,
    pub entity_id: String,
    pub entity_type: EntityType,
    pub role: String,
    pub message: Option<String>,
    pub status: InviteStatus,
    pub created_at: i64,
    pub expires_at: Option<i64>,
    pub resolved_at: Option<i64>,
    pub resolved_by: Option<String>,
}
Expand description

An invitation to join an entity.

Invites are created by entity members with appropriate permissions and target a specific four-word identity. On acceptance, the recipient becomes a member with the specified role.

Fields§

§id: String

Unique identifier for this invite.

§creator_id: String

Four-word identity of the invite creator.

§recipient_id: String

Four-word identity of the intended recipient.

§entity_id: String

Target entity ID.

§entity_type: EntityType

Target entity type.

§role: String

Role to grant on acceptance.

§message: Option<String>

Optional message from creator to recipient.

§status: InviteStatus

Current status of the invite.

§created_at: i64

When the invite was created (Unix timestamp ms).

§expires_at: Option<i64>

When the invite expires, if set (Unix timestamp ms).

§resolved_at: Option<i64>

When the invite was resolved (accepted/rejected/revoked).

§resolved_by: Option<String>

Who resolved the invite (recipient for accept/reject, admin for revoke).

Implementations§

Source§

impl Invite

Source

pub fn new( creator_id: String, recipient_id: String, entity_id: String, entity_type: EntityType, role: String, message: Option<String>, expires_in_hours: Option<u32>, ) -> Self

Create a new pending invite.

§Arguments
  • creator_id - Four-word identity of the creator
  • recipient_id - Four-word identity of the recipient
  • entity_id - ID of the entity to join
  • entity_type - Type of the entity
  • role - Role to grant on acceptance
  • message - Optional message to recipient
  • expires_in_hours - Optional expiration in hours from now
§Example
use communitas_core::invite::Invite;
use communitas_core::crdt::EntityType;

let invite = Invite::new(
    "alice-brave-cloud-dawn".to_string(),
    "bob-calm-river-east".to_string(),
    "project-123".to_string(),
    EntityType::Project,
    "member".to_string(),
    Some("Join our project!".to_string()),
    Some(168), // 1 week
);

assert!(invite.is_pending());
assert!(invite.is_valid());
Source

pub fn set_id(self, id: String) -> Self

Set a custom ID on this invite (builder pattern).

Returns self for method chaining.

Source

pub fn is_pending(&self) -> bool

Check if the invite is still pending.

Source

pub fn is_accepted(&self) -> bool

Check if the invite has been accepted.

Source

pub fn is_resolved(&self) -> bool

Check if the invite is in a terminal state.

Source

pub fn is_expired(&self) -> bool

Check if the invite has expired based on current time.

Source

pub fn is_expired_at(&self, at: DateTime<Utc>) -> bool

Check if the invite would be expired at a given time.

Source

pub fn is_valid(&self) -> bool

Check if the invite is valid (pending and not expired).

Source

pub fn is_valid_at(&self, at: DateTime<Utc>) -> bool

Check if the invite would be valid at a given time.

Source

pub fn accept(&mut self, acceptor_id: &str) -> Result<(), InviteActionError>

Accept the invite.

Returns Err if invite is not in a valid state.

Source

pub fn accept_at( &mut self, acceptor_id: &str, at: DateTime<Utc>, ) -> Result<(), InviteActionError>

Accept the invite at a specific time (for testing).

Source

pub fn reject(&mut self, rejector_id: &str) -> Result<(), InviteActionError>

Reject the invite.

Returns Err if invite is not in a valid state.

Source

pub fn reject_at( &mut self, rejector_id: &str, at: DateTime<Utc>, ) -> Result<(), InviteActionError>

Reject the invite at a specific time (for testing).

Source

pub fn revoke(&mut self, revoker_id: &str) -> Result<(), InviteActionError>

Revoke the invite (creator or admin action).

Returns Err if invite is not pending.

Source

pub fn revoke_at( &mut self, revoker_id: &str, at: DateTime<Utc>, ) -> Result<(), InviteActionError>

Revoke the invite at a specific time (for testing).

Source

pub fn mark_expired(&mut self) -> Result<(), InviteActionError>

Mark the invite as expired.

This is typically called during cleanup when checking validity.

Source

pub fn mark_expired_at( &mut self, at: DateTime<Utc>, ) -> Result<(), InviteActionError>

Mark the invite as expired at a specific time.

Source

pub fn created_at_datetime(&self) -> DateTime<Utc>

Get the created_at timestamp as DateTime.

Source

pub fn expires_at_datetime(&self) -> Option<DateTime<Utc>>

Get the expires_at timestamp as DateTime, if set.

Source

pub fn resolved_at_datetime(&self) -> Option<DateTime<Utc>>

Get the resolved_at timestamp as DateTime, if set.

Source

pub fn time_remaining(&self) -> Option<Duration>

Get time remaining until expiration, if applicable.

Source

pub fn time_remaining_at(&self, at: DateTime<Utc>) -> Option<Duration>

Get time remaining until expiration at a specific time.

Trait Implementations§

Source§

impl Clone for Invite

Source§

fn clone(&self) -> Invite

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Invite

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Invite

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Invite

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Invite

§

impl RefUnwindSafe for Invite

§

impl Send for Invite

§

impl Sync for Invite

§

impl Unpin for Invite

§

impl UnwindSafe for Invite

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,