View Source Teiserver.Communication.MatchMessageLib (Teiserver v0.0.4)

Library of match_message related functions.

Summary

Functions

Returns an %Ecto.Changeset{} for tracking match_message changes.

Creates a match_message.

Deletes a match_message.

Returns the list of match_messages.

Returns a list of messages from a match ordered as the newest first.

Wraps send_match_message/3 to send a message when in the lobby instead of the match

  • Creates a match message
  • If successful generate a pubsub message

## Examples

Joins your process to match messages

Removes your process from a match's messages

Functions

Link to this function

change_match_message(match_message, attrs \\ %{})

View Source
@spec change_match_message(Teiserver.Communication.MatchMessage.t(), map()) ::
  Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking match_message changes.

Examples

iex> change_match_message(match_message)
%Ecto.Changeset{data: %MatchMessage{}}
Link to this function

create_match_message(attrs \\ %{})

View Source
@spec create_match_message(map()) ::
  {:ok, Teiserver.Communication.MatchMessage.t()} | {:error, Ecto.Changeset.t()}

Creates a match_message.

Examples

iex> create_match_message(%{field: value})
{:ok, %MatchMessage{}}

iex> create_match_message(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

delete_match_message(match_message)

View Source

Deletes a match_message.

Examples

iex> delete_match_message(match_message)
{:ok, %MatchMessage{}}

iex> delete_match_message(match_message)
{:error, %Ecto.Changeset{}}
Link to this function

get_match_message(match_message_id, query_args \\ [])

View Source

Gets a single match_message.

Returns nil if the MatchMessage does not exist.

Examples

iex> get_match_message("uuid")
%MatchMessage{}

iex> get_match_message("uuid")
nil
Link to this function

get_match_message!(match_message_id, query_args \\ [])

View Source

Gets a single match_message.

Raises Ecto.NoResultsError if the MatchMessage does not exist.

Examples

iex> get_match_message!("uuid")
%MatchMessage{}

iex> get_match_message!("uuid")
** (Ecto.NoResultsError)
Link to this function

list_match_messages(query_args \\ [])

View Source
@spec list_match_messages(list()) :: list()

Returns the list of match_messages.

Examples

iex> list_match_messages()
[%MatchMessage{}, ...]
Link to this function

list_recent_match_messages(match_id, limit \\ 50)

View Source
@spec list_recent_match_messages(Teiserver.Game.Match.id(), non_neg_integer()) :: [
  Teiserver.Communication.MatchMessage.t()
]

Returns a list of messages from a match ordered as the newest first.

In the event of there being ne messages for a match of that ID the function will return an empty list.

Examples

iex> list_recent_match_messages("uuid")
[%MatchMessage{}, ...]

iex> list_recent_match_messages("uuid")
[]
Link to this function

send_lobby_message(sender_id, lobby_id, content)

View Source
@spec send_lobby_message(Teiserver.user_id(), Lobby.id(), String.t()) ::
  {:ok, Teiserver.Communication.MatchMessage.t()} | {:error, Ecto.Changeset.t()}

Wraps send_match_message/3 to send a message when in the lobby instead of the match

  • Creates a match message
  • If successful generate a pubsub message for both the Match and the Lobby

## Examples

  iex> send_lobby_message("uuid", "uuid", "Message content")
  {:ok, %MatchMessage{}}

  iex> send_lobby_message("uuid", "uuid", "Message content")
  {:error, %Ecto.Changeset{}}
Link to this function

send_match_message(sender_id, match_id, content, attrs \\ %{})

View Source
@spec send_match_message(
  Teiserver.user_id(),
  Teiserver.Game.Match.id(),
  String.t(),
  map()
) ::
  {:ok, Teiserver.Communication.MatchMessage.t()} | {:error, Ecto.Changeset.t()}
  • Creates a match message
  • If successful generate a pubsub message

## Examples

  iex> send_match_message("uuid", "uuid", "Message content")
  {:ok, %MatchMessage{}}

  iex> send_match_message("uuid", "uuid", "Message content")
  {:error, %Ecto.Changeset{}}
Link to this function

subscribe_to_match_messages(match_or_match_id)

View Source
@spec subscribe_to_match_messages(
  Teiserver.Game.Match.id()
  | Teiserver.Game.Match.t()
) :: :ok

Joins your process to match messages

Link to this function

unsubscribe_from_match_messages(match_or_match_id)

View Source
@spec unsubscribe_from_match_messages(
  Teiserver.Game.Match.id()
  | Teiserver.Game.Match.t()
) :: :ok

Removes your process from a match's messages

Link to this function

update_match_message(match_message, attrs)

View Source
@spec update_match_message(Teiserver.Communication.MatchMessage.t(), map()) ::
  {:ok, Teiserver.Communication.MatchMessage.t()} | {:error, Ecto.Changeset.t()}

Updates a match_message.

Examples

iex> update_match_message(match_message, %{field: new_value})
{:ok, %MatchMessage{}}

iex> update_match_message(match_message, %{field: bad_value})
{:error, %Ecto.Changeset{}}