Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into feature/unrepeats
This commit is contained in:
commit
9e0dd21ed6
33 changed files with 242 additions and 61 deletions
|
|
@ -144,7 +144,7 @@ defmodule Pleroma.Formatter do
|
|||
@emoji
|
||||
end
|
||||
|
||||
@link_regex ~r/https?:\/\/[\w\.\/?=\-#\+%&@~\(\):]+[\w\/]/u
|
||||
@link_regex ~r/https?:\/\/[\w\.\/?=\-#\+%&@~'\(\):]+[\w\/]/u
|
||||
|
||||
def html_escape(text) do
|
||||
Regex.split(@link_regex, text, include_captures: true)
|
||||
|
|
@ -168,7 +168,13 @@ defmodule Pleroma.Formatter do
|
|||
subs =
|
||||
subs ++
|
||||
Enum.map(links, fn {uuid, url} ->
|
||||
{uuid, "<a href='#{url}'>#{url}</a>"}
|
||||
{:safe, link} = Phoenix.HTML.Link.link(url, to: url)
|
||||
|
||||
link =
|
||||
link
|
||||
|> IO.iodata_to_binary()
|
||||
|
||||
{uuid, link}
|
||||
end)
|
||||
|
||||
{subs, uuid_text}
|
||||
|
|
|
|||
|
|
@ -322,6 +322,16 @@ defmodule Pleroma.User do
|
|||
update_and_set_cache(cs)
|
||||
end
|
||||
|
||||
def decrease_note_count(%User{} = user) do
|
||||
note_count = user.info["note_count"] || 0
|
||||
note_count = if note_count <= 0, do: 0, else: note_count - 1
|
||||
new_info = Map.put(user.info, "note_count", note_count)
|
||||
|
||||
cs = info_changeset(user, %{info: new_info})
|
||||
|
||||
update_and_set_cache(cs)
|
||||
end
|
||||
|
||||
def update_note_count(%User{} = user) do
|
||||
note_count_query =
|
||||
from(
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
|
||||
@httpoison Application.get_env(:pleroma, :httpoison)
|
||||
|
||||
@instance Application.get_env(:pleroma, :instance)
|
||||
@rewrite_policy Keyword.get(@instance, :rewrite_policy)
|
||||
|
||||
def get_recipients(data) do
|
||||
(data["to"] || []) ++ (data["cc"] || [])
|
||||
end
|
||||
|
|
@ -17,7 +20,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
def insert(map, local \\ true) when is_map(map) do
|
||||
with nil <- Activity.get_by_ap_id(map["id"]),
|
||||
map <- lazy_put_activity_defaults(map),
|
||||
:ok <- insert_full_object(map) do
|
||||
:ok <- insert_full_object(map),
|
||||
{:ok, map} <- @rewrite_policy.filter(map) do
|
||||
{:ok, activity} =
|
||||
Repo.insert(%Activity{
|
||||
data: map,
|
||||
|
|
@ -61,7 +65,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
additional
|
||||
),
|
||||
{:ok, activity} <- insert(create_data, local),
|
||||
:ok <- maybe_federate(activity) do
|
||||
:ok <- maybe_federate(activity),
|
||||
{:ok, actor} <- User.increase_note_count(actor) do
|
||||
{:ok, activity}
|
||||
end
|
||||
end
|
||||
|
|
@ -184,7 +189,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
with Repo.delete(object),
|
||||
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
|
||||
{:ok, activity} <- insert(data, local),
|
||||
:ok <- maybe_federate(activity) do
|
||||
:ok <- maybe_federate(activity),
|
||||
{:ok, actor} <- User.decrease_note_count(user) do
|
||||
{:ok, activity}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
8
lib/pleroma/web/activity_pub/mrf/drop_policy.ex
Normal file
8
lib/pleroma/web/activity_pub/mrf/drop_policy.ex
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
defmodule Pleroma.Web.ActivityPub.MRF.DropPolicy do
|
||||
require Logger
|
||||
|
||||
def filter(object) do
|
||||
Logger.info("REJECTING #{inspect(object)}")
|
||||
{:reject, object}
|
||||
end
|
||||
end
|
||||
5
lib/pleroma/web/activity_pub/mrf/noop_policy.ex
Normal file
5
lib/pleroma/web/activity_pub/mrf/noop_policy.ex
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do
|
||||
def filter(object) do
|
||||
{:ok, object}
|
||||
end
|
||||
end
|
||||
75
lib/pleroma/web/activity_pub/mrf/simple_policy.ex
Normal file
75
lib/pleroma/web/activity_pub/mrf/simple_policy.ex
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
||||
alias Pleroma.User
|
||||
|
||||
@mrf_policy Application.get_env(:pleroma, :mrf_simple)
|
||||
|
||||
@reject Keyword.get(@mrf_policy, :reject)
|
||||
defp check_reject(actor_info, object) do
|
||||
if actor_info.host in @reject do
|
||||
{:reject, nil}
|
||||
else
|
||||
{:ok, object}
|
||||
end
|
||||
end
|
||||
|
||||
@media_removal Keyword.get(@mrf_policy, :media_removal)
|
||||
defp check_media_removal(actor_info, object) do
|
||||
if actor_info.host in @media_removal do
|
||||
object = Map.delete(object, "attachments")
|
||||
end
|
||||
|
||||
{:ok, object}
|
||||
end
|
||||
|
||||
@media_nsfw Keyword.get(@mrf_policy, :media_nsfw)
|
||||
defp check_media_nsfw(actor_info, object) do
|
||||
child_object = object["object"]
|
||||
|
||||
if actor_info.host in @media_nsfw and child_object["attachment"] != nil and
|
||||
length(child_object["attachment"]) > 0 do
|
||||
tags = (child_object["tag"] || []) ++ ["nsfw"]
|
||||
child_object = Map.put(child_object, "tags", tags)
|
||||
child_object = Map.put(child_object, "sensitive", true)
|
||||
object = Map.put(object, "object", child_object)
|
||||
end
|
||||
|
||||
{:ok, object}
|
||||
end
|
||||
|
||||
@ftl_removal Keyword.get(@mrf_policy, :federated_timeline_removal)
|
||||
defp check_ftl_removal(actor_info, object) do
|
||||
if actor_info.host in @ftl_removal do
|
||||
user = User.get_by_ap_id(object["actor"])
|
||||
|
||||
# flip to/cc relationship to make the post unlisted
|
||||
if "https://www.w3.org/ns/activitystreams#Public" in object["to"] and
|
||||
user.follower_address in object["cc"] do
|
||||
to =
|
||||
List.delete(object["to"], "https://www.w3.org/ns/activitystreams#Public") ++
|
||||
[user.follower_address]
|
||||
|
||||
cc =
|
||||
List.delete(object["cc"], user.follower_address) ++
|
||||
["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
||||
object = Map.put(object, "to", to)
|
||||
object = Map.put(object, "cc", cc)
|
||||
end
|
||||
end
|
||||
|
||||
{:ok, object}
|
||||
end
|
||||
|
||||
def filter(object) do
|
||||
actor_info = URI.parse(object["actor"])
|
||||
|
||||
with {:ok, object} <- check_reject(actor_info, object),
|
||||
{:ok, object} <- check_media_removal(actor_info, object),
|
||||
{:ok, object} <- check_media_nsfw(actor_info, object),
|
||||
{:ok, object} <- check_ftl_removal(actor_info, object) do
|
||||
{:ok, object}
|
||||
else
|
||||
e -> {:reject, nil}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -146,7 +146,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
%{"type" => "Like", "object" => object_id, "actor" => actor, "id" => id} = data
|
||||
) do
|
||||
with %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
||||
{:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
|
||||
{:ok, object} <-
|
||||
get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
|
||||
{:ok, activity, object} <- ActivityPub.like(actor, object, id, false) do
|
||||
{:ok, activity}
|
||||
else
|
||||
|
|
@ -158,7 +159,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
%{"type" => "Announce", "object" => object_id, "actor" => actor, "id" => id} = data
|
||||
) do
|
||||
with %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
||||
{:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
|
||||
{:ok, object} <-
|
||||
get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
|
||||
{:ok, activity, object} <- ActivityPub.announce(actor, object, id, false) do
|
||||
{:ok, activity}
|
||||
else
|
||||
|
|
@ -209,7 +211,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
end
|
||||
|
||||
with %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
|
||||
{:ok, object} <- get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
|
||||
{:ok, object} <-
|
||||
get_obj_helper(object_id) || ActivityPub.fetch_object_from_id(object_id),
|
||||
{:ok, activity} <- ActivityPub.delete(object, false) do
|
||||
{:ok, activity}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -175,7 +175,8 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
|
||||
def update_element_in_object(property, element, object) do
|
||||
with new_data <-
|
||||
object.data |> Map.put("#{property}_count", length(element))
|
||||
object.data
|
||||
|> Map.put("#{property}_count", length(element))
|
||||
|> Map.put("#{property}s", element),
|
||||
changeset <- Changeset.change(object, data: new_data),
|
||||
{:ok, object} <- Repo.update(changeset),
|
||||
|
|
|
|||
|
|
@ -113,7 +113,6 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
additional: %{"cc" => cc}
|
||||
})
|
||||
|
||||
User.increase_note_count(user)
|
||||
res
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ defmodule Pleroma.Web.Endpoint do
|
|||
Plug.Static,
|
||||
at: "/",
|
||||
from: :pleroma,
|
||||
only: ~w(index.html static finmoji emoji packs sounds images instance sw.js)
|
||||
only: ~w(index.html static finmoji emoji packs sounds images instance sw.js favicon.png)
|
||||
)
|
||||
|
||||
# Code reloading can be explicitly enabled under the
|
||||
|
|
|
|||
|
|
@ -528,7 +528,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||
^query
|
||||
),
|
||||
limit: 20,
|
||||
order_by: [desc: :inserted_at]
|
||||
order_by: [desc: :id]
|
||||
)
|
||||
|
||||
statuses = Repo.all(q) ++ fetched
|
||||
|
|
|
|||
|
|
@ -63,7 +63,8 @@ defmodule Pleroma.Web.OAuth.OAuthController do
|
|||
client_secret: params["client_secret"]
|
||||
),
|
||||
fixed_token = fix_padding(params["code"]),
|
||||
%Authorization{} = auth <- Repo.get_by(Authorization, token: fixed_token, app_id: app.id),
|
||||
%Authorization{} = auth <-
|
||||
Repo.get_by(Authorization, token: fixed_token, app_id: app.id),
|
||||
{:ok, token} <- Token.exchange_token(app, auth) do
|
||||
response = %{
|
||||
token_type: "Bearer",
|
||||
|
|
|
|||
|
|
@ -131,7 +131,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
|
|||
h.(activity.data["object"]["content"] |> String.replace(~r/[\n\r]/, ""))},
|
||||
{:published, h.(inserted_at)},
|
||||
{:updated, h.(updated_at)},
|
||||
{:"ostatus:conversation", [ref: h.(activity.data["context"])], h.(activity.data["context"])},
|
||||
{:"ostatus:conversation", [ref: h.(activity.data["context"])],
|
||||
h.(activity.data["context"])},
|
||||
{:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []}
|
||||
] ++
|
||||
summary ++
|
||||
|
|
@ -162,7 +163,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
|
|||
# For notes, federate the object id.
|
||||
{:id, h.(activity.data["object"])}
|
||||
]},
|
||||
{:"ostatus:conversation", [ref: h.(activity.data["context"])], h.(activity.data["context"])},
|
||||
{:"ostatus:conversation", [ref: h.(activity.data["context"])],
|
||||
h.(activity.data["context"])},
|
||||
{:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
|
||||
{:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []},
|
||||
{:"thr:in-reply-to", [ref: to_charlist(activity.data["object"])], []}
|
||||
|
|
@ -193,7 +195,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
|
|||
{:content, [type: 'html'], ['RT #{retweeted_activity.data["object"]["content"]}']},
|
||||
{:published, h.(inserted_at)},
|
||||
{:updated, h.(updated_at)},
|
||||
{:"ostatus:conversation", [ref: h.(activity.data["context"])], h.(activity.data["context"])},
|
||||
{:"ostatus:conversation", [ref: h.(activity.data["context"])],
|
||||
h.(activity.data["context"])},
|
||||
{:link, [ref: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
|
||||
{:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []},
|
||||
{:"activity:object", retweeted_xml}
|
||||
|
|
|
|||
|
|
@ -138,19 +138,15 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
|
|||
do: note |> Map.put("inReplyTo", inReplyTo),
|
||||
else: note
|
||||
) do
|
||||
res =
|
||||
ActivityPub.create(%{
|
||||
to: to,
|
||||
actor: actor,
|
||||
context: context,
|
||||
object: note,
|
||||
published: date,
|
||||
local: false,
|
||||
additional: %{"cc" => cc}
|
||||
})
|
||||
|
||||
User.increase_note_count(actor)
|
||||
res
|
||||
ActivityPub.create(%{
|
||||
to: to,
|
||||
actor: actor,
|
||||
context: context,
|
||||
object: note,
|
||||
published: date,
|
||||
local: false,
|
||||
additional: %{"cc" => cc}
|
||||
})
|
||||
else
|
||||
%Activity{} = activity -> {:ok, activity}
|
||||
e -> {:error, e}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,10 @@ defmodule Pleroma.Web.WebFinger do
|
|||
"href" => user.ap_id
|
||||
},
|
||||
%{"rel" => "salmon", "href" => OStatus.salmon_path(user)},
|
||||
%{"rel" => "magic-public-key", "href" => "data:application/magic-public-key,#{magic_key}"},
|
||||
%{
|
||||
"rel" => "magic-public-key",
|
||||
"href" => "data:application/magic-public-key,#{magic_key}"
|
||||
},
|
||||
%{"rel" => "self", "type" => "application/activity+json", "href" => user.ap_id},
|
||||
%{
|
||||
"rel" => "http://ostatus.org/schema/1.0/subscribe",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue