Verified Commit 67918ce9 authored by Pierre de Lacroix's avatar Pierre de Lacroix
Browse files

refacto and format

parent 2a089f12
Pipeline #264962904 failed with stages
in 21 minutes and 40 seconds
......@@ -7,5 +7,5 @@ defmodule MatrixAppService.Adapter.Transaction do
@doc """
Called when the application service receives an event.
"""
@callback new_event(MatrixAppService.Event.t()) :: any()
@callback new_event(%MatrixAppService.Event{}) :: any()
end
......@@ -7,7 +7,13 @@ defmodule MatrixAppService.Client do
"""
@behaviour MatrixAppService.ClientBehaviour
@type client_options :: {:base_url, String.t()} | MatrixAppService.Client.LowLevel.create_opts()
@type create_opts :: [
access_token: String.t() | nil,
user_id: String.t() | nil,
device_id: String.t() | nil,
storage: Polyjuice.Client.Storage.t() | nil
]
@type client_options :: {:base_url, String.t()} | create_opts()
@doc """
Returns a client for the application service.
......@@ -117,5 +123,5 @@ defmodule MatrixAppService.Client do
defdelegate get_data(client, id, key), to: Polyjuice.Client.Account
defdelegate get_profile(client, id), to: Polyjuice.Client.Profile
defdelegate modify_displayname(client, id, name), to: Polyjuice.Client.Profile
defdelegate put_displayname(client, id, name), to: Polyjuice.Client.Profile
end
......@@ -5,7 +5,13 @@ defmodule MatrixAppService.ClientBehaviour do
TODO: example
"""
@type client_options :: {:base_url, String.t()} | MatrixAppService.Client.LowLevel.create_opts()
@type create_opts :: [
access_token: String.t() | nil,
user_id: String.t() | nil,
device_id: String.t() | nil,
storage: Polyjuice.Client.Storage.t() | nil
]
@type client_options :: {:base_url, String.t()} | create_opts()
@callback client() ::
Polyjuice.Client.LowLevel.t()
......@@ -23,5 +29,5 @@ defmodule MatrixAppService.ClientBehaviour do
{:ok, String.t()} | Any
@callback get_profile(Polyjuice.Client.LowLevel.t(), String.t()) :: {:ok, map()} | any
@callback get_data(Polyjuice.Client.LowLevel.t(), String.t(), String.t()) :: {:ok, map()} | any
@callback modify_displayname(Polyjuice.Client.LowLevel.t(), String.t(), String.t()) :: :ok | any
@callback put_displayname(Polyjuice.Client.LowLevel.t(), String.t(), String.t()) :: :ok | any
end
......@@ -30,29 +30,49 @@ defmodule MatrixAppService.Event do
# user_id: nil
embedded_schema do
field :age, :integer
field :content, :map
field :event_id, :string
field :origin_server_ts, :integer
field :room_id, :string
field :sender, :string
field :state_key, :string
field :type, :string
field :unsigned, :map
field :user_id, :string
field(:age, :integer)
field(:content, :map)
field(:event_id, :string)
field(:origin_server_ts, :integer)
field(:room_id, :string)
field(:sender, :string)
field(:state_key, :string)
field(:type, :string)
field(:unsigned, :map)
field(:user_id, :string)
end
def new(params) do
command = changeset(params)
case command.valid? do
true -> {:ok, apply_changes(command)}
true -> {:ok, apply_changes(command)}
false -> {:error, command.errors}
end
end
defp changeset(params) do
%__MODULE__{}
|> cast(params, [:age, :content, :event_id, :origin_server_ts, :room_id, :sender, :state_key, :type, :unsigned, :user_id])
|> validate_required([:content, :event_id, :origin_server_ts, :room_id, :sender, :type, :unsigned])
|> cast(params, [
:age,
:content,
:event_id,
:origin_server_ts,
:room_id,
:sender,
:state_key,
:type,
:unsigned,
:user_id
])
|> validate_required([
:content,
:event_id,
:origin_server_ts,
:room_id,
:sender,
:type,
:unsigned
])
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment