summaryrefslogtreecommitdiff
path: root/lib/polyjuice/client/room.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/polyjuice/client/room.ex')
-rw-r--r--lib/polyjuice/client/room.ex108
1 files changed, 58 insertions, 50 deletions
diff --git a/lib/polyjuice/client/room.ex b/lib/polyjuice/client/room.ex
index 28c164c..db4b71e 100644
--- a/lib/polyjuice/client/room.ex
+++ b/lib/polyjuice/client/room.ex
@@ -61,32 +61,34 @@ defmodule Polyjuice.Client.Room do
msg :: map | Polyjuice.Client.MsgBuilder.MsgData.t()
) :: {:ok, String.t()} | any
def send_message(client_api, room, msg) when is_binary(room) do
- cond do
- Polyjuice.Client.MsgBuilder.MsgData.impl_for(msg) != nil ->
- Polyjuice.Client.API.call(
- client_api,
- %Polyjuice.Client.Endpoint.PutRoomsSend{
- txn_id: Polyjuice.Client.API.transaction_id(client_api),
- room: room,
- event_type: "m.room.message",
- message: Polyjuice.Client.MsgBuilder.to_message(msg)
- }
- )
+ Polyjuice.Client.API.room_queue(client_api, room, fn ->
+ cond do
+ Polyjuice.Client.MsgBuilder.MsgData.impl_for(msg) != nil ->
+ Polyjuice.Client.API.call(
+ client_api,
+ %Polyjuice.Client.Endpoint.PutRoomsSend{
+ txn_id: Polyjuice.Client.API.transaction_id(client_api),
+ room: room,
+ event_type: "m.room.message",
+ message: Polyjuice.Client.MsgBuilder.to_message(msg)
+ }
+ )
- is_map(msg) and not Map.has_key?(msg, :__struct__) ->
- Polyjuice.Client.API.call(
- client_api,
- %Polyjuice.Client.Endpoint.PutRoomsSend{
- txn_id: Polyjuice.Client.API.transaction_id(client_api),
- room: room,
- event_type: "m.room.message",
- message: msg
- }
- )
+ is_map(msg) and not Map.has_key?(msg, :__struct__) ->
+ Polyjuice.Client.API.call(
+ client_api,
+ %Polyjuice.Client.Endpoint.PutRoomsSend{
+ txn_id: Polyjuice.Client.API.transaction_id(client_api),
+ room: room,
+ event_type: "m.room.message",
+ message: msg
+ }
+ )
- true ->
- raise ArgumentError, message: "invalid argument msg"
- end
+ true ->
+ raise ArgumentError, message: "invalid argument msg"
+ end
+ end)
end
@doc """
@@ -100,15 +102,17 @@ defmodule Polyjuice.Client.Room do
) :: {:ok, String.t()} | any
def send_event(client_api, room, event_type, event)
when is_binary(event_type) and is_map(event) and is_binary(room) do
- Polyjuice.Client.API.call(
- client_api,
- %Polyjuice.Client.Endpoint.PutRoomsSend{
- txn_id: Polyjuice.Client.API.transaction_id(client_api),
- room: room,
- event_type: event_type,
- message: event
- }
- )
+ Polyjuice.Client.API.room_queue(client_api, room, fn ->
+ Polyjuice.Client.API.call(
+ client_api,
+ %Polyjuice.Client.Endpoint.PutRoomsSend{
+ txn_id: Polyjuice.Client.API.transaction_id(client_api),
+ room: room,
+ event_type: event_type,
+ message: event
+ }
+ )
+ end)
end
@doc """
@@ -123,15 +127,17 @@ defmodule Polyjuice.Client.Room do
) :: {:ok, String.t()} | any
def send_state_event(client_api, room, event_type, state_key \\ "", event)
when is_binary(event_type) and is_binary(state_key) and is_map(event) and is_binary(room) do
- Polyjuice.Client.API.call(
- client_api,
- %Polyjuice.Client.Endpoint.PutRoomsState{
- room: room,
- event_type: event_type,
- state_key: state_key,
- content: event
- }
- )
+ Polyjuice.Client.API.room_queue(client_api, room, fn ->
+ Polyjuice.Client.API.call(
+ client_api,
+ %Polyjuice.Client.Endpoint.PutRoomsState{
+ room: room,
+ event_type: event_type,
+ state_key: state_key,
+ content: event
+ }
+ )
+ end)
end
@doc """
@@ -168,14 +174,16 @@ defmodule Polyjuice.Client.Room do
def join(client_api, room, servers \\ [], third_party_signed \\ nil)
when is_binary(room) and is_list(servers) and
(is_map(third_party_signed) or third_party_signed == nil) do
- Polyjuice.Client.API.call(
- client_api,
- %Polyjuice.Client.Endpoint.PostJoin{
- room: room,
- servers: servers,
- third_party_signed: third_party_signed
- }
- )
+ Polyjuice.Client.API.room_queue(client_api, room, fn ->
+ Polyjuice.Client.API.call(
+ client_api,
+ %Polyjuice.Client.Endpoint.PostJoin{
+ room: room,
+ servers: servers,
+ third_party_signed: third_party_signed
+ }
+ )
+ end)
end
@doc """