Polyjuice Client v0.3.1 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
Forget a room.
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".
Leave a room.
Send an event to a room.
Send a message to a room.
Send a state event 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
Represents a position in the timeline, used for paginating events before/after this position.
Link to this section Functions
forget(client_api, room)
View Sourceforget(client_api :: Polyjuice.Client.API.t(), room :: String.t()) :: {:ok, String.t()} | any()
Forget a room.
get_messages(client_api, room, from, dir, opts \\ [])
View Sourceget_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.
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".
Join a room.
leave(client_api, room)
View Sourceleave(client_api :: Polyjuice.Client.API.t(), room :: String.t()) :: {:ok, String.t()} | any()
Leave a room.
Send an event to a room.
send_message(client_api, room, msg)
View Sourcesend_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"
)
send_state_event(client_api, room, event_type, state_key \\ "", event)
View SourceSend a state event to a room.
stream_messages(client_api, room, from, dir, opts \\ [])
View Sourcestream_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()
update_read_receipt(client_api, room, event_id, receipt_type \\ "m.read")
View Sourceupdate_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.