Hotline.ChatRegistry (Hotline v0.2.1)

Copy Markdown View Source

Tracks known chats using ETS (fast reads) backed by DETS (persistence).

Automatically subscribes to PubSub and records chats from incoming updates. Survives restarts via DETS.

Data at rest

Tracked chats are personal data (names, usernames) persisted unencrypted in the DETS file. On init the registry locks its directory to 0700 before creating the file — closing the brief world-readable window :dets.open_file would otherwise leave on the freshly created file — and then restricts the file itself to 0600 (best effort — skipped with a warning on filesystems without POSIX modes). Operators are responsible for:

  • storing :dets_path in a private, app-owned subdirectory — not the shared default priv/. Because the registry locks the containing directory to 0700, pointing it at bare priv/ over-broadly restricts every other priv/ asset; give it a dedicated dir (e.g. priv/hotline/chats.dets or an external data dir), which also keeps chat PII out of anything published in a release or Hex package, and
  • applying disk-level encryption if the data warrants it.

Usage

Add to your supervision tree (after PubSub):

{Hotline.ChatRegistry, dets_path: "priv/chats.dets"}

Then query:

Hotline.ChatRegistry.list()
Hotline.ChatRegistry.get(7644580464)
Hotline.ChatRegistry.count()

Summary

Functions

Returns a specification to start this module under a supervisor.

Count known chats.

List all known chats.

Manually track a chat.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

count(name \\ __MODULE__)

Count known chats.

get(chat_id, name \\ __MODULE__)

Get a chat by ID.

list(name \\ __MODULE__)

List all known chats.

start_link(opts \\ [])

track(chat, name \\ __MODULE__)

Manually track a chat.