Merge branch 'fix/object-reembeds' into 'develop'
Do not rembed the object after updating it Closes #1142 See merge request pleroma/pleroma!1538
This commit is contained in:
commit
aa718ab8f6
|
@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Not being able to pin unlisted posts
|
- Not being able to pin unlisted posts
|
||||||
|
- Objects being re-embedded to activities after being updated (e.g faved/reposted). Running 'mix pleroma.database prune_objects' again is advised.
|
||||||
- Metadata rendering errors resulting in the entire page being inaccessible
|
- Metadata rendering errors resulting in the entire page being inaccessible
|
||||||
- Federation/MediaProxy not working with instances that have wrong certificate order
|
- Federation/MediaProxy not working with instances that have wrong certificate order
|
||||||
- Mastodon API: Handling of search timeouts (`/api/v1/search` and `/api/v2/search`)
|
- Mastodon API: Handling of search timeouts (`/api/v1/search` and `/api/v2/search`)
|
||||||
|
|
|
@ -749,8 +749,8 @@ defp restrict_state(query, _), do: query
|
||||||
|
|
||||||
defp restrict_favorited_by(query, %{"favorited_by" => ap_id}) do
|
defp restrict_favorited_by(query, %{"favorited_by" => ap_id}) do
|
||||||
from(
|
from(
|
||||||
activity in query,
|
[_activity, object] in query,
|
||||||
where: fragment(~s(? <@ (? #> '{"object","likes"}'\)), ^ap_id, activity.data)
|
where: fragment("(?)->'likes' \\? (?)", object.data, ^ap_id)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -251,20 +251,6 @@ def insert_full_object(%{"object" => %{"type" => type} = object_data} = map)
|
||||||
|
|
||||||
def insert_full_object(map), do: {:ok, map, nil}
|
def insert_full_object(map), do: {:ok, map, nil}
|
||||||
|
|
||||||
def update_object_in_activities(%{data: %{"id" => id}} = object) do
|
|
||||||
# TODO
|
|
||||||
# Update activities that already had this. Could be done in a seperate process.
|
|
||||||
# Alternatively, just don't do this and fetch the current object each time. Most
|
|
||||||
# could probably be taken from cache.
|
|
||||||
relevant_activities = Activity.get_all_create_by_object_ap_id(id)
|
|
||||||
|
|
||||||
Enum.map(relevant_activities, fn activity ->
|
|
||||||
new_activity_data = activity.data |> Map.put("object", object.data)
|
|
||||||
changeset = Changeset.change(activity, data: new_activity_data)
|
|
||||||
Repo.update(changeset)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
#### Like-related helpers
|
#### Like-related helpers
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -347,8 +333,7 @@ def update_element_in_object(property, element, object) do
|
||||||
|> Map.put("#{property}_count", length(element))
|
|> Map.put("#{property}_count", length(element))
|
||||||
|> Map.put("#{property}s", element),
|
|> Map.put("#{property}s", element),
|
||||||
changeset <- Changeset.change(object, data: new_data),
|
changeset <- Changeset.change(object, data: new_data),
|
||||||
{:ok, object} <- Object.update_and_set_cache(changeset),
|
{:ok, object} <- Object.update_and_set_cache(changeset) do
|
||||||
_ <- update_object_in_activities(object) do
|
|
||||||
{:ok, object}
|
{:ok, object}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -183,6 +183,7 @@ def to_simple_form(%{data: %{"type" => "Announce"}} = activity, user, with_autho
|
||||||
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
|
||||||
|
|
||||||
retweeted_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
|
retweeted_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
|
||||||
|
retweeted_object = Object.normalize(retweeted_activity)
|
||||||
retweeted_user = User.get_cached_by_ap_id(retweeted_activity.data["actor"])
|
retweeted_user = User.get_cached_by_ap_id(retweeted_activity.data["actor"])
|
||||||
|
|
||||||
retweeted_xml = to_simple_form(retweeted_activity, retweeted_user, true)
|
retweeted_xml = to_simple_form(retweeted_activity, retweeted_user, true)
|
||||||
|
@ -197,7 +198,7 @@ def to_simple_form(%{data: %{"type" => "Announce"}} = activity, user, with_autho
|
||||||
{:"activity:verb", ['http://activitystrea.ms/schema/1.0/share']},
|
{:"activity:verb", ['http://activitystrea.ms/schema/1.0/share']},
|
||||||
{:id, h.(activity.data["id"])},
|
{:id, h.(activity.data["id"])},
|
||||||
{:title, ['#{user.nickname} repeated a notice']},
|
{:title, ['#{user.nickname} repeated a notice']},
|
||||||
{:content, [type: 'html'], ['RT #{retweeted_activity.data["object"]["content"]}']},
|
{:content, [type: 'html'], ['RT #{retweeted_object.data["content"]}']},
|
||||||
{:published, h.(inserted_at)},
|
{:published, h.(inserted_at)},
|
||||||
{:updated, h.(updated_at)},
|
{:updated, h.(updated_at)},
|
||||||
{:"ostatus:conversation", [ref: h.(activity.data["context"])],
|
{:"ostatus:conversation", [ref: h.(activity.data["context"])],
|
||||||
|
|
|
@ -677,14 +677,8 @@ test "adds a like activity to the db" do
|
||||||
assert object.data["likes"] == [user.ap_id]
|
assert object.data["likes"] == [user.ap_id]
|
||||||
assert object.data["like_count"] == 1
|
assert object.data["like_count"] == 1
|
||||||
|
|
||||||
[note_activity] = Activity.get_all_create_by_object_ap_id(object.data["id"])
|
|
||||||
assert note_activity.data["object"]["like_count"] == 1
|
|
||||||
|
|
||||||
{:ok, _like_activity, object} = ActivityPub.like(user_two, object)
|
{:ok, _like_activity, object} = ActivityPub.like(user_two, object)
|
||||||
assert object.data["like_count"] == 2
|
assert object.data["like_count"] == 2
|
||||||
|
|
||||||
[note_activity] = Activity.get_all_create_by_object_ap_id(object.data["id"])
|
|
||||||
assert note_activity.data["object"]["like_count"] == 2
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ test "handle incoming retweets - GS, subscription - local message" do
|
||||||
assert retweeted_activity.data["type"] == "Create"
|
assert retweeted_activity.data["type"] == "Create"
|
||||||
assert retweeted_activity.data["actor"] == user.ap_id
|
assert retweeted_activity.data["actor"] == user.ap_id
|
||||||
assert retweeted_activity.local
|
assert retweeted_activity.local
|
||||||
assert retweeted_activity.data["object"]["announcement_count"] == 1
|
assert Object.normalize(retweeted_activity).data["announcement_count"] == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
test "handle incoming retweets - Mastodon, salmon" do
|
test "handle incoming retweets - Mastodon, salmon" do
|
||||||
|
|
Loading…
Reference in New Issue