asobi_chat_channel (asobi v0.75.1)

View Source

Summary

Functions

channels()

-spec channels() -> [#{channel_id := binary(), members := non_neg_integer()}].

Every chat channel running on this node, with its current member count.

Two ETS reads and one pg lookup per channel: no channel process is called, so an operator listing channels cannot block behind one that is busy.

The registry is the source rather than pg:which_groups/1, which the console this replaces used. pg drops a group when its last member leaves, so a running channel nobody is currently joined to is simply absent there - and the console asked the wrong scope besides, so its channel list was always empty.

Capped at 1000 channels, the same ceiling asobi_leaderboards:boards/0 enumerates under, so the in-memory sort behind this stays bounded. [] before the chat supervisor has started, and members => 0 for every channel when pg has not.

get_history(ChannelId, Limit)

-spec get_history(binary(), pos_integer()) -> [map()].

handle_call/3

-spec handle_call(term(), gen_server:from(), map()) -> {reply, term(), map(), pos_integer()}.

handle_cast/2

-spec handle_cast(term(), map()) -> {noreply, map(), pos_integer()}.

handle_info/2

-spec handle_info(term(), map()) -> {noreply, map(), pos_integer()} | {stop, normal, map()}.

init/1

-spec init({binary(), binary()}) -> {ok, map(), pos_integer()}.

join(ChannelId, Pid)

-spec join(binary(), pid()) -> ok.

leave(ChannelId, Pid)

-spec leave(binary(), pid()) -> ok.

send_message(ChannelId, SenderId, Content)

-spec send_message(binary(), binary(), binary()) -> ok.

start_link(ChannelId, ChannelType)

-spec start_link(binary(), binary()) -> gen_server:start_ret().

terminate/2

-spec terminate(term(), map()) -> ok.