Polyjuice Client v0.2.3 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

Get messages from a room starting from a certain point.

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".

Send a message to a room.

Paginate messages from a room starting from a certain point.

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

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

View Source
get_messages(
  client_api :: Polyjuice.Client.API.t(),
  room :: 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, event_type \\ nil, state_key \\ "")

View Source
get_state(
  client_api :: Polyjuice.Client.API.t(),
  room :: String.t(),
  event_type :: String.t(),
  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, servers \\ [], third_party_signed \\ nil)

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

Join a room.

Link to this function

send_event(client_api, room, event_type, event)

View Source
send_event(
  client_api :: Polyjuice.Client.API.t(),
  room :: String.t(),
  event_type :: String.t(),
  event :: map()
) :: {:ok, String.t()} | Any

Send an event to a room.

Link to this function

send_message(client_api, room, msg)

View Source
send_message(
  client_api :: Polyjuice.Client.API.t(),
  room :: String.t(),
  msg :: map() | 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, "text message", "!room_id")

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

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

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

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

View Source
send_state_event(
  client_api :: Polyjuice.Client.API.t(),
  room :: String.t(),
  event_type :: String.t(),
  state_key :: String.t(),
  event :: map()
) :: {:ok, String.t()} | Any

Send a state event to a room.

Link to this function

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

View Source
stream_messages(
  client_api :: Polyjuice.Client.API.t(),
  room :: 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_receipt(client_api, room, event_id, receipt_type \\ "m.read")

View Source
update_read_receipt(
  client_api :: Polyjuice.Client.API.t(),
  room :: 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.