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: StringUnique identifier for this invite.
creator_id: StringFour-word identity of the invite creator.
recipient_id: StringFour-word identity of the intended recipient.
entity_id: StringTarget entity ID.
entity_type: EntityTypeTarget entity type.
role: StringRole to grant on acceptance.
message: Option<String>Optional message from creator to recipient.
status: InviteStatusCurrent status of the invite.
created_at: i64When 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
impl Invite
Sourcepub 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
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 creatorrecipient_id- Four-word identity of the recipiententity_id- ID of the entity to joinentity_type- Type of the entityrole- Role to grant on acceptancemessage- Optional message to recipientexpires_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());Sourcepub fn set_id(self, id: String) -> Self
pub fn set_id(self, id: String) -> Self
Set a custom ID on this invite (builder pattern).
Returns self for method chaining.
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Check if the invite is still pending.
Sourcepub fn is_accepted(&self) -> bool
pub fn is_accepted(&self) -> bool
Check if the invite has been accepted.
Sourcepub fn is_resolved(&self) -> bool
pub fn is_resolved(&self) -> bool
Check if the invite is in a terminal state.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the invite has expired based on current time.
Sourcepub fn is_expired_at(&self, at: DateTime<Utc>) -> bool
pub fn is_expired_at(&self, at: DateTime<Utc>) -> bool
Check if the invite would be expired at a given time.
Sourcepub fn is_valid_at(&self, at: DateTime<Utc>) -> bool
pub fn is_valid_at(&self, at: DateTime<Utc>) -> bool
Check if the invite would be valid at a given time.
Sourcepub fn accept(&mut self, acceptor_id: &str) -> Result<(), InviteActionError>
pub fn accept(&mut self, acceptor_id: &str) -> Result<(), InviteActionError>
Accept the invite.
Returns Err if invite is not in a valid state.
Sourcepub fn accept_at(
&mut self,
acceptor_id: &str,
at: DateTime<Utc>,
) -> Result<(), InviteActionError>
pub fn accept_at( &mut self, acceptor_id: &str, at: DateTime<Utc>, ) -> Result<(), InviteActionError>
Accept the invite at a specific time (for testing).
Sourcepub fn reject(&mut self, rejector_id: &str) -> Result<(), InviteActionError>
pub fn reject(&mut self, rejector_id: &str) -> Result<(), InviteActionError>
Reject the invite.
Returns Err if invite is not in a valid state.
Sourcepub fn reject_at(
&mut self,
rejector_id: &str,
at: DateTime<Utc>,
) -> Result<(), InviteActionError>
pub fn reject_at( &mut self, rejector_id: &str, at: DateTime<Utc>, ) -> Result<(), InviteActionError>
Reject the invite at a specific time (for testing).
Sourcepub fn revoke(&mut self, revoker_id: &str) -> Result<(), InviteActionError>
pub fn revoke(&mut self, revoker_id: &str) -> Result<(), InviteActionError>
Revoke the invite (creator or admin action).
Returns Err if invite is not pending.
Sourcepub fn revoke_at(
&mut self,
revoker_id: &str,
at: DateTime<Utc>,
) -> Result<(), InviteActionError>
pub fn revoke_at( &mut self, revoker_id: &str, at: DateTime<Utc>, ) -> Result<(), InviteActionError>
Revoke the invite at a specific time (for testing).
Sourcepub fn mark_expired(&mut self) -> Result<(), InviteActionError>
pub fn mark_expired(&mut self) -> Result<(), InviteActionError>
Mark the invite as expired.
This is typically called during cleanup when checking validity.
Sourcepub fn mark_expired_at(
&mut self,
at: DateTime<Utc>,
) -> Result<(), InviteActionError>
pub fn mark_expired_at( &mut self, at: DateTime<Utc>, ) -> Result<(), InviteActionError>
Mark the invite as expired at a specific time.
Sourcepub fn created_at_datetime(&self) -> DateTime<Utc>
pub fn created_at_datetime(&self) -> DateTime<Utc>
Get the created_at timestamp as DateTime.
Sourcepub fn expires_at_datetime(&self) -> Option<DateTime<Utc>>
pub fn expires_at_datetime(&self) -> Option<DateTime<Utc>>
Get the expires_at timestamp as DateTime, if set.
Sourcepub fn resolved_at_datetime(&self) -> Option<DateTime<Utc>>
pub fn resolved_at_datetime(&self) -> Option<DateTime<Utc>>
Get the resolved_at timestamp as DateTime, if set.
Sourcepub fn time_remaining(&self) -> Option<Duration>
pub fn time_remaining(&self) -> Option<Duration>
Get time remaining until expiration, if applicable.