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
Add an alias to a room.
Create a new room with various configuration options and return a room_id on success.
Forget a room.
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.
Get a room state.
Leave a room.
Send a redact event to a room.
Send an event to a room.
Send a message to a room.
Send a state event 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
Represents a position in the timeline, used for paginating events before/after this position.
Link to this section Functions
create_alias(client_api, room_id, room_alias)
View Sourcecreate_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
.
create_room(client_api, options \\ [])
View Sourcecreate_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 roominvite
: a list of user IDs to invite to the roominvite_3pid
: a list of objects representing third party IDs to invite into the room. Map made ofid_server
: The hostname+port of the identity server which should be used for third party identifier lookupsmedium
: The kind of address being passed in the address field, for example emailaddress
: 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 errcodeM_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 eventinitial_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 roomtype
: the type of event to sendstate_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 theis_direct
flag on them.room.member
events sent to the users ininvite
andinvite_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 generatedm.room.power_levels
event content prior to it being sent to the room. Defaults to overriding nothing.
forget(client_api, room_id)
View Sourceforget(client_api :: Polyjuice.Client.API.t(), room_id :: String.t()) :: {:ok, String.t()} | any()
Forget a room.
get_alias(client_api, room_alias)
View Sourceget_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
get_joined_members(client_api, room_id)
View Sourceget_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"
}
}
get_members(client_api, room_id, opts \\ [])
View Sourceget_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 roommembership
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.
get_messages(client_api, room_id, from, dir, opts \\ [])
View Sourceget_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.
get_state(client_api, room_id, event_type \\ nil, state_key \\ "")
View SourceGet 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(client_api, room_id_or_alias, servers \\ [], third_party_signed \\ nil)
View SourceJoin a room.
leave(client_api, room_id)
View Sourceleave(client_api :: Polyjuice.Client.API.t(), room_id :: String.t()) :: {:ok, String.t()} | any()
Leave a room.
Send a redact event to a room.
send_event(client_api, room_id, event_type, event)
View Sourcesend_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.
send_message(client_api, room_id, msg)
View Sourcesend_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"},
)
send_state_event(client_api, room_id, event_type, state_key \\ "", event)
View Sourcesend_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.
set_typing(client_api, room_id, typing, timeout \\ nil)
View Sourceset_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.
stream_messages(client_api, room_id, from, dir, opts \\ [])
View Sourcestream_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()
update_read_markers(client_api, room_id, fully_read, read \\ nil)
View Sourceupdate_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:
- messages the user has read (or indicated they aren't interested in them),
- messages the user might have read some but not others, and
- 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 atread
: the event id the to which the read receipt should be up to
update_read_receipt(client_api, room_id, event_id, receipt_type \\ "m.read")
View Sourceupdate_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.