forked from AkkomaGang/akkoma
Correctly handle unlisted messages coming in through Ostatus.
This commit is contained in:
parent
b82637f32d
commit
fcf1937a40
2 changed files with 14 additions and 1 deletions
|
@ -88,6 +88,7 @@ def fetch_replied_to_activity(entry, inReplyTo) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: Clean this up a bit.
|
||||||
def handle_note(entry, doc \\ nil) do
|
def handle_note(entry, doc \\ nil) do
|
||||||
with id <- XML.string_from_xpath("//id", entry),
|
with id <- XML.string_from_xpath("//id", entry),
|
||||||
activity when is_nil(activity) <- Activity.get_create_activity_by_object_ap_id(id),
|
activity when is_nil(activity) <- Activity.get_create_activity_by_object_ap_id(id),
|
||||||
|
@ -104,15 +105,18 @@ def handle_note(entry, doc \\ nil) do
|
||||||
mentions <- get_mentions(entry),
|
mentions <- get_mentions(entry),
|
||||||
to <- make_to_list(actor, mentions),
|
to <- make_to_list(actor, mentions),
|
||||||
date <- XML.string_from_xpath("//published", entry),
|
date <- XML.string_from_xpath("//published", entry),
|
||||||
|
unlisted <- XML.string_from_xpath("//mastodon:scope", entry) == "unlisted",
|
||||||
|
cc <- if(unlisted, do: ["https://www.w3.org/ns/activitystreams#Public"], else: []),
|
||||||
note <- CommonAPI.Utils.make_note_data(actor.ap_id, to, context, content_html, attachments, inReplyToActivity, [], cw),
|
note <- CommonAPI.Utils.make_note_data(actor.ap_id, to, context, content_html, attachments, inReplyToActivity, [], cw),
|
||||||
note <- note |> Map.put("id", id) |> Map.put("tag", tags),
|
note <- note |> Map.put("id", id) |> Map.put("tag", tags),
|
||||||
note <- note |> Map.put("published", date),
|
note <- note |> Map.put("published", date),
|
||||||
note <- note |> Map.put("emoji", get_emoji(entry)),
|
note <- note |> Map.put("emoji", get_emoji(entry)),
|
||||||
note <- add_external_url(note, entry),
|
note <- add_external_url(note, entry),
|
||||||
|
note <- note |> Map.put("cc", cc),
|
||||||
# TODO: Handle this case in make_note_data
|
# TODO: Handle this case in make_note_data
|
||||||
note <- (if inReplyTo && !inReplyToActivity, do: note |> Map.put("inReplyTo", inReplyTo), else: note)
|
note <- (if inReplyTo && !inReplyToActivity, do: note |> Map.put("inReplyTo", inReplyTo), else: note)
|
||||||
do
|
do
|
||||||
res = ActivityPub.create(%{to: to, actor: actor, context: context, object: note, published: date, local: false})
|
res = ActivityPub.create(%{to: to, actor: actor, context: context, object: note, published: date, local: false, additional: %{"cc" => cc}})
|
||||||
User.increase_note_count(actor)
|
User.increase_note_count(actor)
|
||||||
res
|
res
|
||||||
else
|
else
|
||||||
|
|
|
@ -90,6 +90,15 @@ test "handle incoming notes - Mastodon, with CW" do
|
||||||
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "handle incoming unlisted messages, put public into cc" do
|
||||||
|
incoming = File.read!("test/fixtures/mastodon-note-unlisted.xml")
|
||||||
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||||
|
refute "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
||||||
|
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["cc"]
|
||||||
|
refute "https://www.w3.org/ns/activitystreams#Public" in activity.data["object"]["to"]
|
||||||
|
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["object"]["cc"]
|
||||||
|
end
|
||||||
|
|
||||||
test "handle incoming retweets - Mastodon, with CW" do
|
test "handle incoming retweets - Mastodon, with CW" do
|
||||||
incoming = File.read!("test/fixtures/cw_retweet.xml")
|
incoming = File.read!("test/fixtures/cw_retweet.xml")
|
||||||
{:ok, [[_activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
|
{:ok, [[_activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
|
||||||
|
|
Loading…
Reference in a new issue