diff options
author | lain <lain@soykaf.club> | 2020-08-22 20:45:16 +0200 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-08-22 20:45:16 +0200 |
commit | d49fdb315f4ea1a03e22063b14ba804104b8527b (patch) | |
tree | 61e43092f714fa4d57fb6e26bc9ea45c830c8a41 /lib/pleroma/web/matrix_controller.ex | |
parent | b5ea5fe851e404c3b1fca90eb4a57e6a34ff205a (diff) | |
download | pleroma-d49fdb315f4ea1a03e22063b14ba804104b8527b.tar.gz |
MatrixController: Add basic tests, respect the 'since' parameter.
Diffstat (limited to 'lib/pleroma/web/matrix_controller.ex')
-rw-r--r-- | lib/pleroma/web/matrix_controller.ex | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/pleroma/web/matrix_controller.ex b/lib/pleroma/web/matrix_controller.ex index d02d5859b..00f27924d 100644 --- a/lib/pleroma/web/matrix_controller.ex +++ b/lib/pleroma/web/matrix_controller.ex @@ -161,7 +161,7 @@ defmodule Pleroma.Web.MatrixController do end def sync(%{assigns: %{user: user}} = conn, params) do - with {:ok, timeout} <- Ecto.Type.cast(:integer, params["timeout"]) do + with {:ok, timeout} when not is_nil(timeout) <- Ecto.Type.cast(:integer, params["timeout"]) do :timer.sleep(timeout) end @@ -183,9 +183,21 @@ defmodule Pleroma.Web.MatrixController do [user, recipient] |> membership_events_from_list(chat) - messages = + q = chat |> MessageReference.for_chat_query() + + q = + if since = params["since"] do + from(mr in q, + where: mr.id > ^since + ) + else + q + end + + messages = + q |> Repo.all() |> Enum.map(fn message -> chat_data = message.object.data @@ -273,12 +285,16 @@ defmodule Pleroma.Web.MatrixController do } } - Map.merge(acc, room) + if length(messages) > 0 do + Map.merge(acc, room) + else + acc + end end) most_recent_cmr_id = Enum.reduce(chats, nil, fn {_k, chat}, acc -> - id = List.first(chat.timeline.events).event_id + id = List.last(chat.timeline.events).event_id if !acc || (acc && acc < id) do id |