Pushest v0.2.2 Pushest.Socket.Data.Presence View Source

Structure representing presence information, connected user IDs and data of them.

Link to this section Summary

Functions

Adds new user data to a Presence struct and returns new one containg the merge. Used when member_added event is being fired to merge new user to local presence

Merges current Presence struct with new presence data frame. Always keeps :me part from current state

Removes user data from a Presence struct and returns new one without given user data. Used when member_removed event is being fired to remove that user from local presence

Link to this section Functions

Link to this function add_member(presence, map) View Source
add_member(
  %Pushest.Socket.Data.Presence{
    count: term(),
    hash: term(),
    ids: term(),
    me: term()
  },
  map()
) :: %Pushest.Socket.Data.Presence{
  count: term(),
  hash: term(),
  ids: term(),
  me: term()
}

Adds new user data to a Presence struct and returns new one containg the merge. Used when member_added event is being fired to merge new user to local presence.

Examples

iex> Pushest.Socket.Data.Presence.add_member(
  ...> %Pushest.Socket.Data.Presence{me: %{user_id: "1"}, count: 1, ids: ["1"], hash: %{"1" => nil}},
  ...> %{"user_id" => "2", "user_info" => %{"name" => "Tomas Koutsky"}}
  ...> )
  %Pushest.Socket.Data.Presence{
    me: %{user_id: "1"},
    count: 2, ids: ["2", "1"],
    hash: %{"1" => nil, "2" => %{"name" => "Tomas Koutsky"}}
  }
Link to this function merge(current, next) View Source
merge(
  %Pushest.Socket.Data.Presence{
    count: term(),
    hash: term(),
    ids: term(),
    me: term()
  },
  %Pushest.Socket.Data.Presence{
    count: term(),
    hash: term(),
    ids: term(),
    me: term()
  }
  | nil
) :: %Pushest.Socket.Data.Presence{
  count: term(),
  hash: term(),
  ids: term(),
  me: term()
}

Merges current Presence struct with new presence data frame. Always keeps :me part from current state.

Examples

iex> Pushest.Socket.Data.Presence.merge(%Pushest.Socket.Data.Presence{count: 1, ids: [1]}, nil)
%Pushest.Socket.Data.Presence{count: 1, ids: [1]}

iex> Pushest.Socket.Data.Presence.merge(
...> %Pushest.Socket.Data.Presence{me: %{user_id: 1}},
...> %{"count" => 1, "ids" => [1]}
...> )
%Pushest.Socket.Data.Presence{count: 1, ids: [1], hash: nil, me: %{user_id: 1}}
Link to this function remove_member(presence, map) View Source
remove_member(
  %Pushest.Socket.Data.Presence{
    count: term(),
    hash: term(),
    ids: term(),
    me: term()
  },
  map()
) :: %Pushest.Socket.Data.Presence{
  count: term(),
  hash: term(),
  ids: term(),
  me: term()
}

Removes user data from a Presence struct and returns new one without given user data. Used when member_removed event is being fired to remove that user from local presence.

Examples

iex> Pushest.Socket.Data.Presence.remove_member(
  ...> %Pushest.Socket.Data.Presence{me: %{user_id: "1"}, count: 2, ids: ["1", "2"], hash: %{"1" => nil, "2" => nil}},
  ...> %{"user_id" => "2"}
  ...> )
  %Pushest.Socket.Data.Presence{
    me: %{user_id: "1"},
    count: 1, ids: ["1"],
    hash: %{"1" => nil}
  }