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" => "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 ->
|
||||
Enum.each(list, fn {pid, auth?} ->
|
||||
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
|
||||
send(pid, {:text, anon_render})
|
||||
end
|
||||
|
|
|
@ -26,8 +26,6 @@ def render("update.json", %Activity{} = activity, %User{} = user) do
|
|||
end
|
||||
|
||||
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",
|
||||
payload:
|
||||
|
@ -68,8 +66,6 @@ def render("update.json", %Activity{} = activity) do
|
|||
end
|
||||
|
||||
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",
|
||||
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)
|
||||
{: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)
|
||||
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)
|
||||
{: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)
|
||||
end
|
||||
end
|
||||
|
@ -528,6 +528,35 @@ test "it streams edits in the 'public' stream" do
|
|||
assert %{"id" => ^activity_id} = Jason.decode!(payload)
|
||||
refute Streamer.filtered_by_user?(sender, edited)
|
||||
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
|
||||
|
||||
describe "thread_containment/2" do
|
||||
|
|
Loading…
Reference in New Issue