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

Library of room_message related functions.

Summary

Functions

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

Creates a room_message.

Deletes a room_message.

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

Returns the list of room_messages.

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

## Examples

Joins your process to room messages

Removes your process from a room's messages

Functions

Link to this function

change_room_message(room_message, attrs \\ %{})

View Source
@spec change_room_message(Teiserver.Communication.RoomMessage.t(), map()) ::
  Ecto.Changeset.t()

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

Examples

iex> change_room_message(room_message)
%Ecto.Changeset{data: %RoomMessage{}}
Link to this function

create_room_message(attrs \\ %{})

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

Creates a room_message.

Examples

iex> create_room_message(%{field: value})
{:ok, %RoomMessage{}}

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

delete_room_message(room_message)

View Source

Deletes a room_message.

Examples

iex> delete_room_message(room_message)
{:ok, %RoomMessage{}}

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

get_room_message(room_message_id, query_args \\ [])

View Source

Gets a single room_message.

Returns nil if the RoomMessage does not exist.

Examples

iex> get_room_message(123)
%RoomMessage{}

iex> get_room_message(456)
nil
Link to this function

get_room_message!(room_message_id, query_args \\ [])

View Source

Gets a single room_message.

Raises Ecto.NoResultsError if the RoomMessage does not exist.

Examples

iex> get_room_message!(123)
%RoomMessage{}

iex> get_room_message!(456)
** (Ecto.NoResultsError)
Link to this function

list_recent_room_messages(room_id, limit \\ 50)

View Source

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

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

Examples

iex> list_recent_room_messages(123)
[%RoomMessage{}, ...]

iex> list_recent_room_messages(456)
[]
Link to this function

list_room_messages(query_args \\ [])

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

Returns the list of room_messages.

Examples

iex> list_room_messages()
[%RoomMessage{}, ...]
Link to this function

send_room_message(sender_id, room_id, content, attrs \\ %{})

View Source
  • Creates a room message
  • If successful generate a pubsub message

## Examples

  iex> send_room_message(123, 123, "Message content")
  {:ok, %RoomMessage{}}

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

subscribe_to_room_messages(room_or_room_id)

View Source
@spec subscribe_to_room_messages(
  Teiserver.Communication.Room.id()
  | Teiserver.Communication.Room.t()
) ::
  :ok

Joins your process to room messages

Link to this function

unsubscribe_from_room_messages(room_or_room_id)

View Source
@spec unsubscribe_from_room_messages(
  Teiserver.Communication.Room.id()
  | Teiserver.Communication.Room.t()
) :: :ok

Removes your process from a room's messages

Link to this function

update_room_message(room_message, attrs)

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

Updates a room_message.

Examples

iex> update_room_message(room_message, %{field: new_value})
{:ok, %RoomMessage{}}

iex> update_room_message(room_message, %{field: bad_value})
{:error, %Ecto.Changeset{}}