summaryrefslogtreecommitdiff
path: root/lib/polyjuice/client/room.ex
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2020-12-26 18:03:58 -0500
committerHubert Chathi <hubert@uhoreg.ca>2020-12-26 18:03:58 -0500
commit2834044f508f3210c43cbc116a96f25d047e5069 (patch)
tree2acb5a0d7cec7b402c969d17efed10028cbb8953 /lib/polyjuice/client/room.ex
parentMerge branch 'rooms_read_marker' into 'master' (diff)
Add methods for creating rooms.
(Manual merge of https://gitlab.com/uhoreg/polyjuice_client/-/merge_requests/3) Thanks to multi prise.
Diffstat (limited to '')
-rw-r--r--lib/polyjuice/client/room.ex83
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/polyjuice/client/room.ex b/lib/polyjuice/client/room.ex
index 7435244..26317ae 100644
--- a/lib/polyjuice/client/room.ex
+++ b/lib/polyjuice/client/room.ex
@@ -362,4 +362,87 @@ defmodule Polyjuice.Client.Room do
}
)
end
+
+ @doc """
+ 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.
+
+ """
+ @spec create_room(
+ client_api :: Polyjuice.Client.API.t(),
+ options :: Keyword.t()
+ ) :: {:ok, String.t()} | Any
+ def create_room(client_api, options \\ []) do
+ Polyjuice.Client.API.call(
+ client_api,
+ struct(%Polyjuice.Client.Endpoint.PostCreateRoom{}, options)
+ )
+ end
+
+ @doc """
+ This function allow to five a alias to a room
+ it takes:
+ `room`: a string representing the room id
+ `room_alias`: a string representing the new room alias
+ """
+ @spec create_alias(
+ client_api :: Polyjuice.Client.API.t(),
+ room :: String.t(),
+ room_alias :: String.t()
+ ) :: {:ok, String.t()} | Any
+ def create_alias(client_api, room, room_alias) do
+ room_alias =
+ case String.at(room_alias, 0) do
+ "#" -> room_alias
+ _ -> "#" <> room_alias
+ end
+
+ Polyjuice.Client.API.call(
+ client_api,
+ %Polyjuice.Client.Endpoint.PutRoomAlias{
+ room_id: room,
+ room_alias: room_alias
+ }
+ )
+ end
end