phoenix_presence_list v0.1.0 PhoenixPresenceList View Source
Documentation for PhoenixPresenceList.
Link to this section Summary
Functions
Apply the given joins and leaves diff to the given presence state
Apply the given presence state to the given presence state
Sync the given presence state using a diff of presence join and leave events
Sync the given presence state using a new presence state
Link to this section Functions
Apply the given joins and leaves diff to the given presence state.
Returns a tuple containing the updated state as well as two lists with information about the joins and leaves that took place.
Examples
iex> state = %{}
iex> diff = %{joins: %{"foo" => %{metas: [%{phx_ref: "dWIi5WZTuJg="}]}}, leaves: %{}}
iex> PhoenixPresenceList.apply_diff(state, diff)
{%{"foo" => %{metas: [%{phx_ref: "dWIi5WZTuJg="}]}},
[{"foo", nil, %{metas: [%{phx_ref: "dWIi5WZTuJg="}]}}], []}
Apply the given presence state to the given presence state.
Returns a tuple containing the new presence state along with two lists containing information about the joins and leaves that took place.
Examples
iex> state = %{}
iex> new_state = %{"foo" => %{metas: [%{phx_ref: "dWIi5WZTuJg="}]}}
iex> PhoenixPresenceList.apply_state(state, new_state)
{%{"foo" => %{metas: [%{phx_ref: "dWIi5WZTuJg="}]}},
[{"foo", nil, %{metas: [%{phx_ref: "dWIi5WZTuJg="}]}}], []}
Sync the given presence state using a diff of presence join and leave events.
Returns the updated presence list. In case information on leaves and joins
is needed, have a look at apply_diff/2
.
Examples
iex> state = %{}
iex> diff = %{joins: %{"foo" => %{metas: [%{phx_ref: "dWIi5WZTuJg="}]}}, leaves: %{}}
iex> state = PhoenixPresenceList.sync_diff(state, diff)
%{"foo" => %{metas: [%{phx_ref: "dWIi5WZTuJg="}]}}
iex> diff = %{joins: %{"foo" => %{metas: [%{phx_ref: "U9NnWWscQRU="}]}}, leaves: %{}}
iex> state = PhoenixPresenceList.sync_diff(state, diff)
%{"foo" => %{metas: [%{phx_ref: "dWIi5WZTuJg="}, %{phx_ref: "U9NnWWscQRU="}]}}
iex> diff = %{joins: %{}, leaves: %{"foo" => %{metas: [%{phx_ref: "U9NnWWscQRU="}]}}}
iex> PhoenixPresenceList.sync_diff(state, diff)
%{"foo" => %{metas: [%{phx_ref: "dWIi5WZTuJg="}]}}
Sync the given presence state using a new presence state.
Returns the new presence state. In case information on leaves and joins is
needed, have a look at apply_state/2
.