forked from AkkomaGang/akkoma
Embed announce activity data instead of linking to it
This commit is contained in:
parent
b1742eca42
commit
8c0806539c
3 changed files with 15 additions and 7 deletions
|
@ -140,9 +140,14 @@ def announce(
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def unannounce(%User{} = actor, %Object{} = object, local \\ true) do
|
def unannounce(
|
||||||
|
%User{} = actor,
|
||||||
|
%Object{} = object,
|
||||||
|
local \\ true,
|
||||||
|
activity_id \\ nil
|
||||||
|
) do
|
||||||
with %Activity{} = activity <- get_existing_announce(actor.ap_id, object),
|
with %Activity{} = activity <- get_existing_announce(actor.ap_id, object),
|
||||||
unannounce_data <- make_unannounce_data(actor, activity),
|
unannounce_data <- make_unannounce_data(actor, activity, activity_id),
|
||||||
{:ok, unannounce_activity} <- insert(unannounce_data, local),
|
{:ok, unannounce_activity} <- insert(unannounce_data, local),
|
||||||
:ok <- maybe_federate(activity),
|
:ok <- maybe_federate(activity),
|
||||||
{:ok, _activity} <- Repo.delete(activity),
|
{:ok, _activity} <- Repo.delete(activity),
|
||||||
|
|
|
@ -283,16 +283,19 @@ def make_announce_data(
|
||||||
"""
|
"""
|
||||||
def make_unannounce_data(
|
def make_unannounce_data(
|
||||||
%User{ap_id: ap_id} = user,
|
%User{ap_id: ap_id} = user,
|
||||||
%Activity{data: %{"id" => id, "context" => context}} = activity
|
%Activity{data: %{"context" => context}} = activity,
|
||||||
|
activity_id
|
||||||
) do
|
) do
|
||||||
%{
|
data = %{
|
||||||
"type" => "Undo",
|
"type" => "Undo",
|
||||||
"actor" => ap_id,
|
"actor" => ap_id,
|
||||||
"object" => id,
|
"object" => activity.data,
|
||||||
"to" => [user.follower_address, activity.data["actor"]],
|
"to" => [user.follower_address, activity.data["actor"]],
|
||||||
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
"cc" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
"context" => context
|
"context" => context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if activity_id, do: Map.put(data, "id", activity_id), else: data
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_announce_to_object(%Activity{data: %{"actor" => actor}}, object) do
|
def add_announce_to_object(%Activity{data: %{"actor" => actor}}, object) do
|
||||||
|
|
|
@ -292,9 +292,9 @@ test "unannouncing a previously announced object" do
|
||||||
assert unannounce_activity.data["to"] == [
|
assert unannounce_activity.data["to"] == [
|
||||||
User.ap_followers(user),
|
User.ap_followers(user),
|
||||||
announce_activity.data["actor"]
|
announce_activity.data["actor"]
|
||||||
]
|
]
|
||||||
assert unannounce_activity.data["type"] == "Undo"
|
assert unannounce_activity.data["type"] == "Undo"
|
||||||
assert unannounce_activity.data["object"] == announce_activity.data["id"]
|
assert unannounce_activity.data["object"] == announce_activity.data
|
||||||
assert unannounce_activity.data["actor"] == user.ap_id
|
assert unannounce_activity.data["actor"] == user.ap_id
|
||||||
assert unannounce_activity.data["context"] == announce_activity.data["context"]
|
assert unannounce_activity.data["context"] == announce_activity.data["context"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue