Polyjuice Client v0.4.4 Polyjuice.Client.Room View Source

Room-related functions.

Link to this section Summary

Types

Represents a position in the timeline, used for paginating events before/after this position.

Functions

Create a new room with various configuration options and return a room_id on success.

Get room ID and additional information, given a room's alias

Get the joined members of the room.

Get a list of membership events of the room.

Get messages from a room starting from a certain point.

Send a message to a room.

Set the typing indicator for the given user. The timeout parameter is in milliseconds.

Paginate messages from a room starting from a certain point.

Set up the read receipt marker positions for a given room.

Update the client's read receipt (of the given type) to the given message in the given room.

Link to this section Types

Link to this type

timeline_pos()

View Source
timeline_pos() :: String.t()

Represents a position in the timeline, used for paginating events before/after this position.

Link to this section Functions

Link to this function

create_alias(client_api, room_id, room_alias)

View Source
create_alias(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t(),
  room_alias :: String.t()
) :: :ok | Any

Add an alias to a room.

Adds the alias room_alias to the room with ID room_id.

Link to this function

create_room(client_api, options \\ [])

View Source
create_room(client_api :: Polyjuice.Client.API.t(), options :: Keyword.t()) ::
  {:ok, map()} | Any

Create a new room with various configuration options and return a room_id on success.

options is a keyword list of options. Recognized options are:

  • visibility: a :public visibility indicates that the room will be shown in the published room list. A :private visibility will hide the room from the published room list. Rooms default to private visibility if this key is not included.
  • room_alias_name: The desired room alias local part.
  • name: If this is included, an m.room.name event will be sent into the room to indicate the name of the room.
  • topic: if this is included, an m.room.topic event will be sent into the room to indicate the topic for the room
  • invite: a list of user IDs to invite to the room
  • invite_3pid: a list of objects representing third party IDs to invite into the room. Map made of

    • id_server: The hostname+port of the identity server which should be used for third party identifier lookups
    • medium: The kind of address being passed in the address field, for example email
    • address: The invitee's third party identifier
  • room_version: the room version to set for the room. If not provided, the homeserver is to use its configured default. If provided, the homeserver will return a 400 error with the errcode M_UNSUPPORTED_ROOM_VERSION if it does not support the room version.
  • creation_content: extra keys, such as m.federate, to be added to the content of the m.room.create event
  • initial_state: a list of state events to set in the new room. This allows the user to override the default state events set in the new room

    • type: the type of event to send
    • state_key: The state_key of the state event. Defaults to an empty string.
    • content: the content of the event
  • preset: the preset corresponding to the join rules. There are three options: :private_chat which means that only invited users (including guest users) may join, :trusted_private_chat works as the previous but all invited users have the same power level as the room creator, and :public_chat is for public access, with guest access forbidden.
  • is_direct: this flag makes the server set the is_direct flag on the m.room.member events sent to the users in invite and invite_3pid
  • power_level_content_override: the power level content to override in the default power level event. This object is applied on top of the generated m.room.power_levels event content prior to it being sent to the room. Defaults to overriding nothing.
Link to this function

forget(client_api, room_id)

View Source
forget(client_api :: Polyjuice.Client.API.t(), room_id :: String.t()) ::
  {:ok, String.t()} | any()

Forget a room.

Link to this function

get_alias(client_api, room_alias)

View Source
get_alias(client_api :: Polyjuice.Client.API.t(), room_alias :: String.t()) ::
  {:ok, {room_id :: String.t(), map()}} | Any

Get room ID and additional information, given a room's alias

Link to this function

get_joined_members(client_api, room_id)

View Source
get_joined_members(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t()
) :: {:ok, %{optional(String.t()) => map()}} | Any

Get the joined members of the room.

In contrast with the get_members function, which returns the full membership events, this function returns a map from user ID to basic member info, in the form:

%{
  "@alice:example.org" => %{
    "display_name" => "alice",
    "avatar_url" => "mxc://example.org/aabbccddeeffgghh"
  }
}
Link to this function

get_members(client_api, room_id, opts \\ [])

View Source
get_members(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t(),
  opts :: list()
) :: {:ok, [Polyjuice.Util.event()]} | Any

Get a list of membership events of the room.

Supported options are:

  • at The point in time (pagination token) to return members for in the room
  • membership The kind of membership to filter for. Defaults to no filtering if unspecified.
  • not_membership The kind of membership to exclude from the result When specified alongside membership, the two parameters create an 'or' condition.
Link to this function

get_messages(client_api, room_id, from, dir, opts \\ [])

View Source
get_messages(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t(),
  from :: timeline_pos(),
  dir :: :forward | :backward,
  opts :: list()
) :: {:ok, map()} | any()

Get messages from a room starting from a certain point.

Link to this function

get_state(client_api, room_id, event_type \\ nil, state_key \\ "")

View Source
get_state(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t(),
  event_type :: String.t() | nil,
  state_key :: String.t()
) :: {:ok, String.t()} | any()

Get a room state.

If event_type is not provided, returns a list of events.

If event_type and state_key are provided, returns an event content. state_key can be omitted but this will return events that have a blank state key, not events that have "any state key".

Link to this function

join(client_api, room_id_or_alias, servers \\ [], third_party_signed \\ nil)

View Source
join(
  client_api :: Polyjuice.Client.API.t(),
  room_id_or_alias :: String.t(),
  servers :: [String.t()],
  third_party_signed :: map() | nil
) :: {:ok, String.t()} | any()

Join a room.

Link to this function

leave(client_api, room_id)

View Source
leave(client_api :: Polyjuice.Client.API.t(), room_id :: String.t()) ::
  {:ok, String.t()} | any()

Leave a room.

Link to this function

redact_message(client_api, room_id, event, reason \\ nil)

View Source
redact_message(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t(),
  event :: String.t(),
  reason :: String.t() | nil
) :: {:ok, String.t()} | any()

Send a redact event to a room.

Link to this function

send_event(client_api, room_id, event_type, event)

View Source
send_event(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t(),
  event_type :: String.t(),
  event :: Polyjuice.Util.event_content()
) :: {:ok, String.t()} | any()

Send an event to a room.

Link to this function

send_message(client_api, room_id, msg)

View Source
send_message(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t(),
  msg ::
    Polyjuice.Util.event_content() | Polyjuice.Client.MsgBuilder.MsgData.t()
) :: {:ok, String.t()} | any()

Send a message to a room.

msg can either be anything that implements the Polyjuice.Client.MsgBuilder.MsgData protocol (which will be sent as an m.message), or a map (which specifies the full message content).

Examples:

Polyjuice.Client.Room.send_message(client, "!room_id", "text message")

Polyjuice.Client.Room.send_message(
  client,
  "!room_id"
  {"message with formatting", "<i>message</i> with <b>formatting</b>"},
)

Polyjuice.Client.Room.send_message(
  client,
  "!room_id"
  ["Hello, ", Polyjuice.Client.MsgBuilder.mention("@world:example.com")],
)

Polyjuice.Client.Room.send_message(
  client,
  "!room_id"
  %{"msgtype" => "m.notice", "body" => "using full message content"},
)
Link to this function

send_state_event(client_api, room_id, event_type, state_key \\ "", event)

View Source
send_state_event(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t(),
  event_type :: String.t(),
  state_key :: String.t(),
  event :: Polyjuice.Util.event_content()
) :: {:ok, String.t()} | any()

Send a state event to a room.

Link to this function

set_typing(client_api, room_id, typing, timeout \\ nil)

View Source
set_typing(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t(),
  typing :: boolean(),
  timeout :: non_neg_integer() | nil
) :: :ok | any()

Set the typing indicator for the given user. The timeout parameter is in milliseconds.

Link to this function

stream_messages(client_api, room_id, from, dir, opts \\ [])

View Source
stream_messages(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t(),
  from :: timeline_pos(),
  dir :: :forward | :backward,
  opts :: list()
) :: Enumerable.t()

Paginate messages from a room starting from a certain point.

This function returns a stream of message chunks as would be returned by get_messages.

Examples:

Back-paginate until it reaches events before a given timestamp.

Polyjuice.Client.Room.stream_messages(client, "!room_id", token, :backward)
|> Stream.map(&Map.get(&1, "chunk", []))
|> Stream.concat()
|> Stream.take_while(&(Map.get(&1, "origin_server_ts", 0) >= timestamp))
|> Enum.reverse()
Link to this function

update_read_markers(client_api, room_id, fully_read, read \\ nil)

View Source
update_read_markers(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t(),
  fully_read :: String.t(),
  read :: String.t() | nil
) :: {:ok} | any()

Set up the read receipt marker positions for a given room.

The history for a given room may be split into three sections:

  1. messages the user has read (or indicated they aren't interested in them),
  2. messages the user might have read some but not others, and
  3. messages the user hasn't seen yet.

The "fully read marker" (also known as a "read marker") marks the last event of the first section, whereas the user's read receipt marks the last event of the second section. It takes:

  • fully_read: the event id the read marker should be located at
  • read: the event id the to which the read receipt should be up to
Link to this function

update_read_receipt(client_api, room_id, event_id, receipt_type \\ "m.read")

View Source
update_read_receipt(
  client_api :: Polyjuice.Client.API.t(),
  room_id :: String.t(),
  event_id :: String.t(),
  receipt_type :: String.t()
) :: :ok | any()

Update the client's read receipt (of the given type) to the given message in the given room.