forked from AkkomaGang/akkoma
Activity: get_all_by_object_ap_id/1 → get_all_create_by_object_ap_id/1
This commit is contained in:
parent
4ad5a0abb9
commit
f8ab1b7427
4 changed files with 7 additions and 7 deletions
|
@ -63,10 +63,6 @@ def by_object_ap_id(ap_id) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_all_by_object_ap_id(ap_id) do
|
|
||||||
Repo.all(create_by_object_ap_id(ap_id))
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_activity_by_object_id_query(ap_ids) do
|
def create_activity_by_object_id_query(ap_ids) do
|
||||||
from(
|
from(
|
||||||
activity in Activity,
|
activity in Activity,
|
||||||
|
@ -81,6 +77,10 @@ def create_activity_by_object_id_query(ap_ids) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_all_create_by_object_ap_id(ap_id) do
|
||||||
|
Repo.all(create_by_object_ap_id(ap_id))
|
||||||
|
end
|
||||||
|
|
||||||
def get_create_activity_by_object_ap_id(ap_id) when is_binary(ap_id) do
|
def get_create_activity_by_object_ap_id(ap_id) when is_binary(ap_id) do
|
||||||
create_activity_by_object_id_query([ap_id])
|
create_activity_by_object_id_query([ap_id])
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
|
|
|
@ -198,7 +198,7 @@ def update_object_in_activities(%{data: %{"id" => id}} = object) do
|
||||||
# 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
|
# Alternatively, just don't do this and fetch the current object each time. Most
|
||||||
# could probably be taken from cache.
|
# could probably be taken from cache.
|
||||||
relevant_activities = Activity.get_all_by_object_ap_id(id)
|
relevant_activities = Activity.get_all_create_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)
|
||||||
|
|
|
@ -16,7 +16,7 @@ test "returns an activity by it's AP id" do
|
||||||
|
|
||||||
test "returns activities by it's objects AP ids" do
|
test "returns activities by it's objects AP ids" do
|
||||||
activity = insert(:note_activity)
|
activity = insert(:note_activity)
|
||||||
[found_activity] = Activity.get_all_by_object_ap_id(activity.data["object"]["id"])
|
[found_activity] = Activity.get_all_create_by_object_ap_id(activity.data["object"]["id"])
|
||||||
|
|
||||||
assert activity == found_activity
|
assert activity == found_activity
|
||||||
end
|
end
|
||||||
|
|
|
@ -330,7 +330,7 @@ test "adds a like activity to the db" do
|
||||||
assert like_activity == same_like_activity
|
assert like_activity == same_like_activity
|
||||||
assert object.data["likes"] == [user.ap_id]
|
assert object.data["likes"] == [user.ap_id]
|
||||||
|
|
||||||
[note_activity] = Activity.get_all_by_object_ap_id(object.data["id"])
|
[note_activity] = Activity.get_all_create_by_object_ap_id(object.data["id"])
|
||||||
assert note_activity.data["object"]["like_count"] == 1
|
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)
|
||||||
|
|
Loading…
Reference in a new issue