Kantoor.DavEvents (Kantoor v1.0.0)

Live-update notifications for DAV collections on Phoenix.PubSub.

The store (Kantoor.Dav.Store) calls publish/2 once a write has committed, so a receiver that re-reads the database always sees it. Two topics, both carrying ids and a revision, never content:

  • dav_collection:<collection_id>: {:dav_collection_changed, %{collection_id:, rev:, kind: :changed | :deleted}}. A member was put, deleted, moved or copied, or the collection's properties changed (rev is the new revision), or the collection itself was deleted or replaced (kind: :deleted, rev: nil).
  • dav_home:<user_id>: {:dav_home_changed, %{user_id:}}. The set of the user's own collections changed (created, deleted, renamed by move/copy).

Receivers must not trust a message for access: they subscribe only to collections they may read and re-read what they show from the database. The open pages use Kantoor.DavEvents.Live for that.

Summary

Functions

Broadcasts the events of one committed write by user_id. Call it after the transaction, never inside it. Duplicate events for one collection collapse to the latest one.

Types

event()

@type event() ::
  {:changed, Ecto.UUID.t(), integer()} | {:deleted, Ecto.UUID.t()} | :home

Functions

home_topic(user_id)

@spec home_topic(Ecto.UUID.t()) :: String.t()

publish(user_id, events)

@spec publish(Ecto.UUID.t(), [event()]) :: :ok

Broadcasts the events of one committed write by user_id. Call it after the transaction, never inside it. Duplicate events for one collection collapse to the latest one.

subscribe(collection_id)

@spec subscribe(Ecto.UUID.t()) :: :ok | {:error, term()}

subscribe_home(user_id)

@spec subscribe_home(Ecto.UUID.t()) :: :ok | {:error, term()}

topic(collection_id)

@spec topic(Ecto.UUID.t()) :: String.t()

unsubscribe(collection_id)

@spec unsubscribe(Ecto.UUID.t()) :: :ok