Skip to main content

DeviceRegistry

Trait DeviceRegistry 

Source
pub trait DeviceRegistry: Send + Sync {
    // Required methods
    fn register(
        &self,
        registration: DeviceRegistration,
    ) -> PushStoreFuture<'_, Result<RegistrationOutcome, PushStoreError>>;
    fn rotate(
        &self,
        previous: DeviceToken,
        registration: DeviceRegistration,
    ) -> PushStoreFuture<'_, Result<RegistrationOutcome, PushStoreError>>;
    fn unregister(
        &self,
        owner_id: Uuid,
        token: DeviceToken,
    ) -> PushStoreFuture<'_, Result<bool, PushStoreError>>;
    fn list_for_owner(
        &self,
        owner_id: Uuid,
    ) -> PushStoreFuture<'_, Result<Vec<RegisteredDevice>, PushStoreError>>;
    fn invalidate(
        &self,
        tokens: Vec<DeviceToken>,
        sent_at: DateTime<Utc>,
    ) -> PushStoreFuture<'_, Result<u64, PushStoreError>>;
    fn erase_owner(
        &self,
        owner_id: Uuid,
    ) -> PushStoreFuture<'_, Result<u64, PushStoreError>>;

    // Provided method
    fn invalidate_dead_tokens(
        &self,
        outcomes: &[PushOutcome],
        sent_at: DateTime<Utc>,
    ) -> PushStoreFuture<'_, Result<u64, PushStoreError>> { ... }
}
Expand description

Storage port for the push tokens each owner’s devices registered.

A token belongs to at most one owner. Registering a token another owner holds moves it, so a shared device stops receiving the previous account’s notifications. Each owner keeps at most a configured number of devices; a registration over the cap evicts that owner’s least recently registered devices, never the one being registered. Ties break on created_at, then on the token, so eviction is deterministic.

Required Methods§

Source

fn register( &self, registration: DeviceRegistration, ) -> PushStoreFuture<'_, Result<RegistrationOutcome, PushStoreError>>

Registers or refreshes one device and evicts over the owner’s cap.

Source

fn rotate( &self, previous: DeviceToken, registration: DeviceRegistration, ) -> PushStoreFuture<'_, Result<RegistrationOutcome, PushStoreError>>

Replaces the owner’s previous token with the registration’s token in one step.

The predecessor is removed before the cap is enforced, so rotating never evicts another device. A predecessor the owner does not hold is left alone, which makes a retried rotation safe.

Source

fn unregister( &self, owner_id: Uuid, token: DeviceToken, ) -> PushStoreFuture<'_, Result<bool, PushStoreError>>

Removes one of the owner’s devices; returns whether it existed.

Source

fn list_for_owner( &self, owner_id: Uuid, ) -> PushStoreFuture<'_, Result<Vec<RegisteredDevice>, PushStoreError>>

Lists the owner’s devices, most recently registered first.

Source

fn invalidate( &self, tokens: Vec<DeviceToken>, sent_at: DateTime<Utc>, ) -> PushStoreFuture<'_, Result<u64, PushStoreError>>

Removes tokens the provider reported dead; returns how many went.

Pass the instant the send started as sent_at. A device registered again after it keeps its token, because the provider’s verdict predates the new registration.

Source

fn erase_owner( &self, owner_id: Uuid, ) -> PushStoreFuture<'_, Result<u64, PushStoreError>>

Removes every device of one owner; returns how many went.

Provided Methods§

Source

fn invalidate_dead_tokens( &self, outcomes: &[PushOutcome], sent_at: DateTime<Utc>, ) -> PushStoreFuture<'_, Result<u64, PushStoreError>>

Invalidates every token a send reported as PushOutcome::is_token_dead.

This is the one call to make after PushSender::send returns. Outcomes without a dead token cost no store round trip.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§