forked from AkkomaGang/akkoma
Preserve ids on favorites / retweets.
This commit is contained in:
parent
b403ea4d2b
commit
4f9328c622
3 changed files with 20 additions and 6 deletions
|
@ -41,7 +41,7 @@ def create(to, actor, context, object, additional \\ %{}, published \\ nil, loca
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def like(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, local \\ true) do
|
def like(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, activity_id \\ nil, local \\ true) do
|
||||||
cond do
|
cond do
|
||||||
# There's already a like here, so return the original activity.
|
# There's already a like here, so return the original activity.
|
||||||
ap_id in (object.data["likes"] || []) ->
|
ap_id in (object.data["likes"] || []) ->
|
||||||
|
@ -59,6 +59,8 @@ def like(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, loca
|
||||||
"context" => object.data["context"]
|
"context" => object.data["context"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data = if activity_id, do: Map.put(data, "id", activity_id), else: data
|
||||||
|
|
||||||
{:ok, activity} = insert(data, local)
|
{:ok, activity} = insert(data, local)
|
||||||
|
|
||||||
likes = [ap_id | (object.data["likes"] || [])] |> Enum.uniq
|
likes = [ap_id | (object.data["likes"] || [])] |> Enum.uniq
|
||||||
|
@ -81,7 +83,10 @@ def like(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, loca
|
||||||
end
|
end
|
||||||
|
|
||||||
defp update_object_in_activities(%{data: %{"id" => id}} = object) do
|
defp update_object_in_activities(%{data: %{"id" => id}} = object) do
|
||||||
|
# TODO
|
||||||
# Update activities that already had this. Could be done in a seperate process.
|
# 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.all_by_object_ap_id(id)
|
relevant_activities = Activity.all_by_object_ap_id(id)
|
||||||
Enum.map(relevant_activities, fn (activity) ->
|
Enum.map(relevant_activities, fn (activity) ->
|
||||||
new_activity_data = activity.data |> Map.put("object", object.data)
|
new_activity_data = activity.data |> Map.put("object", object.data)
|
||||||
|
@ -176,7 +181,7 @@ def fetch_activities(recipients, opts \\ %{}) do
|
||||||
Enum.reverse(Repo.all(query))
|
Enum.reverse(Repo.all(query))
|
||||||
end
|
end
|
||||||
|
|
||||||
def announce(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, local \\ true) do
|
def announce(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, activity_id \\ nil, local \\ true) do
|
||||||
data = %{
|
data = %{
|
||||||
"type" => "Announce",
|
"type" => "Announce",
|
||||||
"actor" => ap_id,
|
"actor" => ap_id,
|
||||||
|
@ -185,6 +190,8 @@ def announce(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object,
|
||||||
"context" => object.data["context"]
|
"context" => object.data["context"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data = if activity_id, do: Map.put(data, "id", activity_id), else: data
|
||||||
|
|
||||||
{:ok, activity} = insert(data, local)
|
{:ok, activity} = insert(data, local)
|
||||||
|
|
||||||
announcements = [ap_id | (object.data["announcements"] || [])] |> Enum.uniq
|
announcements = [ap_id | (object.data["announcements"] || [])] |> Enum.uniq
|
||||||
|
|
|
@ -49,10 +49,11 @@ def handle_incoming(xml_string) do
|
||||||
{:ok, activities}
|
{:ok, activities}
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_share(_entry, doc, retweeted_activity) do
|
def make_share(entry, doc, retweeted_activity) do
|
||||||
with {:ok, actor} <- find_make_or_update_user(doc),
|
with {:ok, actor} <- find_make_or_update_user(doc),
|
||||||
%Object{} = object <- Object.get_cached_by_ap_id(retweeted_activity.data["object"]["id"]),
|
%Object{} = object <- Object.get_cached_by_ap_id(retweeted_activity.data["object"]["id"]),
|
||||||
{:ok, activity, _object} = ActivityPub.announce(actor, object, false) do
|
id when not is_nil(id) <- string_from_xpath("/entry/id", entry),
|
||||||
|
{:ok, activity, _object} = ActivityPub.announce(actor, object, id, false) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -67,10 +68,11 @@ def handle_share(entry, doc) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_favorite(_entry, doc, favorited_activity) do
|
def make_favorite(entry, doc, favorited_activity) do
|
||||||
with {:ok, actor} <- find_make_or_update_user(doc),
|
with {:ok, actor} <- find_make_or_update_user(doc),
|
||||||
%Object{} = object <- Object.get_cached_by_ap_id(favorited_activity.data["object"]["id"]),
|
%Object{} = object <- Object.get_cached_by_ap_id(favorited_activity.data["object"]["id"]),
|
||||||
{:ok, activity, _object} = ActivityPub.like(actor, object, false) do
|
id when not is_nil(id) <- string_from_xpath("/entry/id", entry),
|
||||||
|
{:ok, activity, _object} = ActivityPub.like(actor, object, id, false) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -93,6 +93,8 @@ test "handle incoming retweets - Mastodon, salmon" do
|
||||||
assert activity.data["type"] == "Announce"
|
assert activity.data["type"] == "Announce"
|
||||||
assert activity.data["actor"] == "https://mastodon.social/users/lambadalambda"
|
assert activity.data["actor"] == "https://mastodon.social/users/lambadalambda"
|
||||||
assert activity.data["object"] == retweeted_activity.data["object"]["id"]
|
assert activity.data["object"] == retweeted_activity.data["object"]["id"]
|
||||||
|
assert activity.data["id"] == "tag:mastodon.social,2017-05-03:objectId=4934452:objectType=Status"
|
||||||
|
|
||||||
refute activity.local
|
refute activity.local
|
||||||
assert retweeted_activity.data["type"] == "Create"
|
assert retweeted_activity.data["type"] == "Create"
|
||||||
assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
|
assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
|
||||||
|
@ -106,6 +108,8 @@ test "handle incoming favorites - GS, websub" do
|
||||||
assert activity.data["type"] == "Like"
|
assert activity.data["type"] == "Like"
|
||||||
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
|
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
|
||||||
assert activity.data["object"] == favorited_activity.data["object"]["id"]
|
assert activity.data["object"] == favorited_activity.data["object"]["id"]
|
||||||
|
assert activity.data["id"] == "tag:social.heldscal.la,2017-05-05:fave:23211:comment:2061643:2017-05-05T09:12:50+00:00"
|
||||||
|
|
||||||
refute activity.local
|
refute activity.local
|
||||||
assert favorited_activity.data["type"] == "Create"
|
assert favorited_activity.data["type"] == "Create"
|
||||||
assert favorited_activity.data["actor"] == "https://shitposter.club/user/1"
|
assert favorited_activity.data["actor"] == "https://shitposter.club/user/1"
|
||||||
|
@ -137,6 +141,7 @@ test "handle incoming replies" do
|
||||||
assert activity.data["object"]["type"] == "Note"
|
assert activity.data["object"]["type"] == "Note"
|
||||||
assert activity.data["object"]["inReplyTo"] == "http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc"
|
assert activity.data["object"]["inReplyTo"] == "http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc"
|
||||||
assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"]
|
assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"]
|
||||||
|
assert activity.data["object"]["id"] == "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "new remote user creation" do
|
describe "new remote user creation" do
|
||||||
|
|
Loading…
Reference in a new issue