Fix client /messages endpoint event response format
This commit is contained in:
parent
e4a6d36200
commit
659fa17053
2 changed files with 17 additions and 6 deletions
|
@ -12,7 +12,8 @@ defmodule Architex.Event.Formatters do
|
||||||
sender: sender,
|
sender: sender,
|
||||||
origin_server_ts: origin_server_ts,
|
origin_server_ts: origin_server_ts,
|
||||||
unsigned: unsigned,
|
unsigned: unsigned,
|
||||||
room_id: room_id
|
room_id: room_id,
|
||||||
|
state_key: state_key
|
||||||
}) do
|
}) do
|
||||||
data = %{
|
data = %{
|
||||||
content: content,
|
content: content,
|
||||||
|
@ -24,6 +25,7 @@ defmodule Architex.Event.Formatters do
|
||||||
}
|
}
|
||||||
|
|
||||||
data = if unsigned, do: Map.put(data, :unsigned, unsigned), else: data
|
data = if unsigned, do: Map.put(data, :unsigned, unsigned), else: data
|
||||||
|
data = if state_key, do: Map.put(data, :state_key, state_key), else: data
|
||||||
|
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
|
@ -82,7 +82,7 @@ defmodule Architex.Room do
|
||||||
|> limit(^limit)
|
|> limit(^limit)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|
|
||||||
{events, get_start(events), get_end(events, limit)}
|
{events, get_start(events, dir), get_end(events, limit, dir)}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp order_by_direction(query, "b"), do: order_by(query, desc: :origin_server_ts, desc: :nid)
|
defp order_by_direction(query, "b"), do: order_by(query, desc: :origin_server_ts, desc: :nid)
|
||||||
|
@ -114,15 +114,24 @@ defmodule Architex.Room do
|
||||||
where(query, [e], e.nid <= ^to)
|
where(query, [e], e.nid <= ^to)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_start([]), do: nil
|
defp get_start([], _), do: nil
|
||||||
|
|
||||||
defp get_start([%Event{nid: first_nid} | _]) do
|
defp get_start([%Event{nid: first_nid} | _], "f") do
|
||||||
Integer.to_string(first_nid)
|
Integer.to_string(first_nid)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_end(events, limit) when length(events) < limit, do: nil
|
defp get_start(events, "b") do
|
||||||
|
%Event{nid: last_nid} = List.last(events)
|
||||||
|
Integer.to_string(last_nid)
|
||||||
|
end
|
||||||
|
|
||||||
defp get_end(events, _) do
|
defp get_end(events, limit, _) when length(events) < limit, do: nil
|
||||||
|
|
||||||
|
defp get_end([%Event{nid: first_nid} | _], _, "f") do
|
||||||
|
Integer.to_string(first_nid)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_end(events, _, "b") do
|
||||||
%Event{nid: last_nid} = List.last(events)
|
%Event{nid: last_nid} = List.last(events)
|
||||||
Integer.to_string(last_nid)
|
Integer.to_string(last_nid)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue