Send the correct update in streamer
get_create_by_ap_id_with_object() seems to fetch the old object. Why this happens needs further investigation.
This commit is contained in:
parent
27f3d802f2
commit
7451f0e81f
|
@ -297,12 +297,16 @@ defp push_to_socket(topic, %Activity{
|
||||||
defp push_to_socket(_topic, %Activity{data: %{"type" => "Delete"}}), do: :noop
|
defp push_to_socket(_topic, %Activity{data: %{"type" => "Delete"}}), do: :noop
|
||||||
|
|
||||||
defp push_to_socket(topic, %Activity{data: %{"type" => "Update"}} = item) do
|
defp push_to_socket(topic, %Activity{data: %{"type" => "Update"}} = item) do
|
||||||
anon_render = StreamerView.render("status_update.json", item)
|
create_activity =
|
||||||
|
Pleroma.Activity.get_create_by_object_ap_id(item.object.data["id"])
|
||||||
|
|> Map.put(:object, item.object)
|
||||||
|
|
||||||
|
anon_render = StreamerView.render("status_update.json", create_activity)
|
||||||
|
|
||||||
Registry.dispatch(@registry, topic, fn list ->
|
Registry.dispatch(@registry, topic, fn list ->
|
||||||
Enum.each(list, fn {pid, auth?} ->
|
Enum.each(list, fn {pid, auth?} ->
|
||||||
if auth? do
|
if auth? do
|
||||||
send(pid, {:render_with_user, StreamerView, "status_update.json", item})
|
send(pid, {:render_with_user, StreamerView, "status_update.json", create_activity})
|
||||||
else
|
else
|
||||||
send(pid, {:text, anon_render})
|
send(pid, {:text, anon_render})
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,8 +26,6 @@ def render("update.json", %Activity{} = activity, %User{} = user) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("status_update.json", %Activity{} = activity, %User{} = user) do
|
def render("status_update.json", %Activity{} = activity, %User{} = user) do
|
||||||
activity = Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
event: "status.update",
|
event: "status.update",
|
||||||
payload:
|
payload:
|
||||||
|
@ -68,8 +66,6 @@ def render("update.json", %Activity{} = activity) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("status_update.json", %Activity{} = activity) do
|
def render("status_update.json", %Activity{} = activity) do
|
||||||
activity = Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
event: "status.update",
|
event: "status.update",
|
||||||
payload:
|
payload:
|
||||||
|
|
|
@ -451,9 +451,9 @@ test "it streams edits in the 'user' stream", %{user: user, token: oauth_token}
|
||||||
|
|
||||||
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
||||||
{:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"})
|
{:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"})
|
||||||
edited = Pleroma.Activity.normalize(edited)
|
create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
|
||||||
|
|
||||||
assert_receive {:render_with_user, _, "status_update.json", ^edited}
|
assert_receive {:render_with_user, _, "status_update.json", ^create}
|
||||||
refute Streamer.filtered_by_user?(user, edited)
|
refute Streamer.filtered_by_user?(user, edited)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -462,9 +462,9 @@ test "it streams own edits in the 'user' stream", %{user: user, token: oauth_tok
|
||||||
|
|
||||||
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
Streamer.get_topic_and_add_socket("user", user, oauth_token)
|
||||||
{:ok, edited} = CommonAPI.update(user, activity, %{status: "mew mew"})
|
{:ok, edited} = CommonAPI.update(user, activity, %{status: "mew mew"})
|
||||||
edited = Pleroma.Activity.normalize(edited)
|
create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
|
||||||
|
|
||||||
assert_receive {:render_with_user, _, "status_update.json", ^edited}
|
assert_receive {:render_with_user, _, "status_update.json", ^create}
|
||||||
refute Streamer.filtered_by_user?(user, edited)
|
refute Streamer.filtered_by_user?(user, edited)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -528,6 +528,35 @@ test "it streams edits in the 'public' stream" do
|
||||||
assert %{"id" => ^activity_id} = Jason.decode!(payload)
|
assert %{"id" => ^activity_id} = Jason.decode!(payload)
|
||||||
refute Streamer.filtered_by_user?(sender, edited)
|
refute Streamer.filtered_by_user?(sender, edited)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it streams multiple edits in the 'public' stream correctly" do
|
||||||
|
sender = insert(:user)
|
||||||
|
|
||||||
|
Streamer.get_topic_and_add_socket("public", nil, nil)
|
||||||
|
{:ok, activity} = CommonAPI.post(sender, %{status: "hey"})
|
||||||
|
assert_receive {:text, _}
|
||||||
|
|
||||||
|
{:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"})
|
||||||
|
|
||||||
|
edited = Pleroma.Activity.normalize(edited)
|
||||||
|
|
||||||
|
%{id: activity_id} = Pleroma.Activity.get_create_by_object_ap_id(edited.object.data["id"])
|
||||||
|
|
||||||
|
assert_receive {:text, event}
|
||||||
|
assert %{"event" => "status.update", "payload" => payload} = Jason.decode!(event)
|
||||||
|
assert %{"id" => ^activity_id} = Jason.decode!(payload)
|
||||||
|
refute Streamer.filtered_by_user?(sender, edited)
|
||||||
|
|
||||||
|
{:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew 2"})
|
||||||
|
|
||||||
|
edited = Pleroma.Activity.normalize(edited)
|
||||||
|
|
||||||
|
%{id: activity_id} = Pleroma.Activity.get_create_by_object_ap_id(edited.object.data["id"])
|
||||||
|
assert_receive {:text, event}
|
||||||
|
assert %{"event" => "status.update", "payload" => payload} = Jason.decode!(event)
|
||||||
|
assert %{"id" => ^activity_id, "content" => "mew mew 2"} = Jason.decode!(payload)
|
||||||
|
refute Streamer.filtered_by_user?(sender, edited)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "thread_containment/2" do
|
describe "thread_containment/2" do
|
||||||
|
|
Loading…
Reference in New Issue