config :pleroma, Pleroma.Upload, uploads: "uploads"
+config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png"]
+
# Configures the endpoint
config :pleroma, Pleroma.Web.Endpoint,
url: [host: "localhost"],
_ -> []
end)
- @emoji @finmoji_with_filenames ++ @emoji_from_file
+ @emoji_from_globs (
+ static_path = Path.join(:code.priv_dir(:pleroma), "static")
+
+ globs =
+ Application.get_env(:pleroma, :emoji, [])
+ |> Keyword.get(:shortcode_globs, [])
+
+ paths =
+ Enum.map(globs, fn glob ->
+ Path.join(static_path, glob)
+ |> Path.wildcard()
+ end)
+ |> Enum.concat()
+
+ Enum.map(paths, fn path ->
+ shortcode = Path.basename(path, Path.extname(path))
+ external_path = Path.join("/", Path.relative_to(path, static_path))
+ {shortcode, external_path}
+ end)
+ )
+
+ @emoji @finmoji_with_filenames ++ @emoji_from_globs ++ @emoji_from_file
def emojify(text, emoji \\ @emoji)
def emojify(text, nil), do: text
"""
def fix_object(object) do
object
- |> Map.put("actor", object["attributedTo"])
+ |> fix_actor
|> fix_attachments
|> fix_context
|> fix_in_reply_to
|> fix_content_map
end
+ def fix_actor(%{"attributedTo" => actor} = object) do
+ # attributedTo can be a list in the case of peertube or plume
+ actor =
+ if is_list(actor) do
+ Enum.at(actor, 0)
+ else
+ actor
+ end
+
+ object
+ |> Map.put("actor", actor)
+ end
+
def fix_in_reply_to(%{"inReplyTo" => in_reply_to_id} = object)
when not is_nil(in_reply_to_id) do
case ActivityPub.fetch_object_from_id(in_reply_to_id) do
# TODO: validate those with a Ecto scheme
# - tags
# - emoji
- def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
+ def handle_incoming(%{"type" => "Create", "object" => %{"type" => objtype} = object} = data)
+ when objtype in ["Article", "Note"] do
with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),
%User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
- object = fix_object(data["object"])
+ # prefer the activity's actor instead of attributedTo
+ object =
+ fix_object(data["object"])
+ |> Map.put("actor", data["actor"])
params = %{
to: data["to"],
Inserts a full object if it is contained in an activity.
"""
def insert_full_object(%{"object" => %{"type" => type} = object_data})
- when is_map(object_data) and type in ["Note"] do
+ when is_map(object_data) and type in ["Article", "Note"] do
with {:ok, _} <- Object.create(object_data) do
:ok
end
def render("user.json", %{user: user}) do
{:ok, user} = WebFinger.ensure_keys_present(user)
{:ok, _, public_key} = Salmon.keys_from_pem(user.info["keys"])
- public_key = :public_key.pem_entry_encode(:RSAPublicKey, public_key)
+ public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key)
public_key = :public_key.pem_encode([public_key])
%{
},
compose: %{
me: "#{user.id}",
- default_privacy: "public",
+ default_privacy: user.info["default_scope"] || "public",
default_sensitive: false
},
media_attachments: %{
%{
id: to_string(activity.id),
uri: object,
- # TODO: This might be wrong, check with mastodon.
- url: nil,
+ url: object,
account: AccountView.render("account.json", %{user: user}),
in_reply_to_id: nil,
in_reply_to_account_id: nil,
in_reply_to_id: reply_to && to_string(reply_to.id),
in_reply_to_account_id: reply_to_user && to_string(reply_to_user.id),
reblog: nil,
- content: HtmlSanitizeEx.basic_html(object["content"]),
+ content: render_content(object),
created_at: created_at,
reblogs_count: announcement_count,
favourites_count: like_count,
"direct"
end
end
+
+ def render_content(%{"type" => "Article"} = object) do
+ summary = object["name"]
+
+ content =
+ if !!summary and summary != "" do
+ "<p><a href=\"#{object["url"]}\">#{summary}</a></p>#{object["content"]}"
+ else
+ object["content"]
+ end
+
+ HtmlSanitizeEx.basic_html(content)
+ end
+
+ def render_content(object) do
+ HtmlSanitizeEx.basic_html(object["content"])
+ end
end
alias Pleroma.Stats
alias Pleroma.Web
- @instance Application.get_env(:pleroma, :instance)
-
def schemas(conn, _params) do
response = %{
links: [
# Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
def nodeinfo(conn, %{"version" => "2.0"}) do
+ instance = Application.get_env(:pleroma, :instance)
+ media_proxy = Application.get_env(:pleroma, :media_proxy)
stats = Stats.get_stats()
response = %{
version: "2.0",
software: %{
name: "pleroma",
- version: Keyword.get(@instance, :version)
+ version: Keyword.get(instance, :version)
},
protocols: ["ostatus", "activitypub"],
services: %{
inbound: [],
outbound: []
},
- openRegistrations: Keyword.get(@instance, :registrations_open),
+ openRegistrations: Keyword.get(instance, :registrations_open),
usage: %{
users: %{
total: stats.user_count || 0
localPosts: stats.status_count || 0
},
metadata: %{
- nodeName: Keyword.get(@instance, :name)
+ nodeName: Keyword.get(instance, :name),
+ mediaProxy: Keyword.get(media_proxy, :enabled)
}
}
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
alias Pleroma.{Activity, User}
- alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
+ alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView}
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Formatter
tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
- summary = activity.data["object"]["summary"]
-
- content =
- if !!summary and summary != "" do
- "<span>#{activity.data["object"]["summary"]}</span><br />#{content}</span>"
- else
- content
- end
+ {summary, content} = ActivityView.render_content(object)
html =
HtmlSanitizeEx.basic_html(content)
"tags" => tags,
"activity_type" => "post",
"possibly_sensitive" => possibly_sensitive,
- "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object)
+ "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object),
+ "summary" => object["summary"]
}
end
user
end
+ user =
+ if default_scope = params["default_scope"] do
+ with new_info <- Map.put(user.info, "default_scope", default_scope),
+ change <- User.info_changeset(user, %{info: new_info}),
+ {:ok, user} <- User.update_and_set_cache(change) do
+ user
+ else
+ _e -> user
+ end
+ else
+ user
+ end
+
with changeset <- User.update_changeset(user, params),
{:ok, user} <- User.update_and_set_cache(changeset) do
CommonAPI.update(user)
tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
- summary = activity.data["object"]["summary"]
- content = object["content"]
-
- content =
- if !!summary and summary != "" do
- "<span>#{activity.data["object"]["summary"]}</span><br />#{content}</span>"
- else
- content
- end
+ {summary, content} = render_content(object)
html =
HtmlSanitizeEx.basic_html(content)
"tags" => tags,
"activity_type" => "post",
"possibly_sensitive" => possibly_sensitive,
- "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object)
+ "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object),
+ "summary" => summary
}
end
+
+ def render_content(%{"type" => "Note"} = object) do
+ summary = object["summary"]
+
+ content =
+ if !!summary and summary != "" do
+ "<p>#{summary}</p>#{object["content"]}"
+ else
+ object["content"]
+ end
+
+ {summary, content}
+ end
+
+ def render_content(%{"type" => "Article"} = object) do
+ summary = object["name"] || object["summary"]
+
+ content =
+ if !!summary and summary != "" do
+ "<p><a href=\"#{object["url"]}\">#{summary}</a></p>#{object["content"]}"
+ else
+ object["content"]
+ end
+
+ {summary, content}
+ end
+
+ def render_content(object) do
+ summary = object["summary"] || "Unhandled activity type: #{object["type"]}"
+ content = "<p>#{summary}</p>#{object["content"]}"
+
+ {summary, content}
+ end
end
"cover_photo" => User.banner_url(user) |> MediaProxy.url(),
"background_image" => image_url(user.info["background"]) |> MediaProxy.url(),
"is_local" => user.local,
- "locked" => !!user.info["locked"]
+ "locked" => !!user.info["locked"],
+ "default_scope" => user.info["default_scope"] || "public"
}
if assigns[:token] do
assert result["id"] == user.ap_id
assert result["preferredUsername"] == user.nickname
- assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN RSA PUBLIC KEY")
+ assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
end
end
}
expected_html =
- "<span>2hu</span><br />alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{
+ "<p>2hu</p>alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{
mentioned_user.ap_id
}\">@shp</a>"
"activity_type" => "post",
"possibly_sensitive" => true,
"uri" => activity.data["object"]["id"],
- "visibility" => "direct"
+ "visibility" => "direct",
+ "summary" => "2hu"
}
assert ActivityRepresenter.to_map(activity, %{
"text" => "Hey @shp!",
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user}),
- "visibility" => "direct"
+ "visibility" => "direct",
+ "summary" => nil
}
assert result == expected
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
- "locked" => false
+ "locked" => false,
+ "default_scope" => "public"
}
assert represented == UserView.render("show.json", %{user: user})
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
- "locked" => false
+ "locked" => false,
+ "default_scope" => "public"
}
assert represented == UserView.render("show.json", %{user: user, for: follower})
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
- "locked" => false
+ "locked" => false,
+ "default_scope" => "public"
}
assert represented == UserView.render("show.json", %{user: follower, for: user})
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
- "locked" => false
+ "locked" => false,
+ "default_scope" => "public"
}
blocker = Repo.get(User, blocker.id)