aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma')
-rw-r--r--lib/pleroma/formatter.ex10
-rw-r--r--lib/pleroma/user.ex19
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex12
-rw-r--r--lib/pleroma/web/activity_pub/mrf/drop_policy.ex8
-rw-r--r--lib/pleroma/web/activity_pub/mrf/noop_policy.ex5
-rw-r--r--lib/pleroma/web/activity_pub/mrf/simple_policy.ex76
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex9
-rw-r--r--lib/pleroma/web/activity_pub/utils.ex3
-rw-r--r--lib/pleroma/web/common_api/common_api.ex1
-rw-r--r--lib/pleroma/web/common_api/utils.ex1
-rw-r--r--lib/pleroma/web/endpoint.ex2
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex15
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex5
-rw-r--r--lib/pleroma/web/ostatus/activity_representer.ex9
-rw-r--r--lib/pleroma/web/ostatus/handlers/note_handler.ex22
-rw-r--r--lib/pleroma/web/router.ex33
-rw-r--r--lib/pleroma/web/templates/mastodon_api/mastodon/login.html.eex4
-rw-r--r--lib/pleroma/web/templates/o_auth/o_auth/show.html.eex2
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api_controller.ex11
-rw-r--r--lib/pleroma/web/twitter_api/views/notification_view.ex65
-rw-r--r--lib/pleroma/web/web_finger/web_finger.ex5
21 files changed, 264 insertions, 53 deletions
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index 515909af1..456416fbd 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -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}
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index e959fe677..207674999 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -104,7 +104,7 @@ defmodule Pleroma.User do
|> cast(params, [:bio, :name])
|> unique_constraint(:nickname)
|> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
- |> validate_length(:bio, max: 1000)
+ |> validate_length(:bio, max: 5000)
|> validate_length(:name, min: 1, max: 100)
end
@@ -250,6 +250,13 @@ defmodule Pleroma.User do
Repo.get_by(User, nickname: nickname)
end
+ def get_by_nickname_or_email(nickname_or_email) do
+ case user = Repo.get_by(User, nickname: nickname_or_email) do
+ %User{} -> user
+ nil -> Repo.get_by(User, email: nickname_or_email)
+ end
+ end
+
def get_cached_user_info(user) do
key = "user_info:#{user.id}"
Cachex.get!(:user_cache, key, fallback: fn _ -> user_info(user) end)
@@ -315,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(
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 37fbf3d6d..984d1162d 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -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
@@ -171,7 +176,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
diff --git a/lib/pleroma/web/activity_pub/mrf/drop_policy.ex b/lib/pleroma/web/activity_pub/mrf/drop_policy.ex
new file mode 100644
index 000000000..4333bca28
--- /dev/null
+++ b/lib/pleroma/web/activity_pub/mrf/drop_policy.ex
@@ -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
diff --git a/lib/pleroma/web/activity_pub/mrf/noop_policy.ex b/lib/pleroma/web/activity_pub/mrf/noop_policy.ex
new file mode 100644
index 000000000..9dd3acb04
--- /dev/null
+++ b/lib/pleroma/web/activity_pub/mrf/noop_policy.ex
@@ -0,0 +1,5 @@
+defmodule Pleroma.Web.ActivityPub.MRF.NoOpPolicy do
+ def filter(object) do
+ {:ok, object}
+ end
+end
diff --git a/lib/pleroma/web/activity_pub/mrf/simple_policy.ex b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex
new file mode 100644
index 000000000..ea1af0f4d
--- /dev/null
+++ b/lib/pleroma/web/activity_pub/mrf/simple_policy.ex
@@ -0,0 +1,76 @@
+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
+ child_object = Map.delete(object["object"], "attachment")
+ object = Map.put(object, "object", child_object)
+ 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
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 00b9f74ff..2871a2544 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -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
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 7a0762e9f..7b2bf8fa7 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -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),
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index 21225c3b7..2c4b591d4 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -103,7 +103,6 @@ defmodule Pleroma.Web.CommonAPI do
additional: %{"cc" => cc}
})
- User.increase_note_count(user)
res
end
end
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 49c4ee1eb..3c092d524 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -61,6 +61,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
def make_content_html(status, mentions, attachments, tags, no_attachment_links \\ false) do
status
+ |> String.replace("\r", "")
|> format_input(mentions, tags)
|> maybe_add_attachments(attachments, no_attachment_links)
end
diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex
index dfafc95f4..1a012c1b4 100644
--- a/lib/pleroma/web/endpoint.ex
+++ b/lib/pleroma/web/endpoint.ex
@@ -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
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 21b99f919..c84c226e8 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -212,9 +212,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|> Map.put("actor_id", ap_id)
|> Map.put("whole_db", true)
- activities =
- ActivityPub.fetch_public_activities(params)
- |> Enum.reverse()
+ if params["pinned"] == "true" do
+ # Since Pleroma has no "pinned" posts feature, we'll just set an empty list here
+ activities = []
+ else
+ activities =
+ ActivityPub.fetch_public_activities(params)
+ |> Enum.reverse()
+ end
conn
|> add_link_headers(:user_statuses, activities, params["id"])
@@ -516,7 +521,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
^query
),
limit: 20,
- order_by: [desc: :inserted_at]
+ order_by: [desc: :id]
)
statuses = Repo.all(q) ++ fetched
@@ -688,7 +693,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def login_post(conn, %{"authorization" => %{"name" => name, "password" => password}}) do
- with %User{} = user <- User.get_cached_by_nickname(name),
+ with %User{} = user <- User.get_by_nickname_or_email(name),
true <- Pbkdf2.checkpw(password, user.password_hash),
{:ok, app} <- get_or_make_app(),
{:ok, auth} <- Authorization.create_authorization(app, user),
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index 05f366611..11dc1806f 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -29,7 +29,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
"redirect_uri" => redirect_uri
} = params
}) do
- with %User{} = user <- User.get_cached_by_nickname(name),
+ with %User{} = user <- User.get_by_nickname_or_email(name),
true <- Pbkdf2.checkpw(password, user.password_hash),
%App{} = app <- Repo.get_by(App, client_id: client_id),
{:ok, auth} <- Authorization.create_authorization(app, user) do
@@ -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",
diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex
index 2f28c456e..921a89bd0 100644
--- a/lib/pleroma/web/ostatus/activity_representer.ex
+++ b/lib/pleroma/web/ostatus/activity_representer.ex
@@ -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}
diff --git a/lib/pleroma/web/ostatus/handlers/note_handler.ex b/lib/pleroma/web/ostatus/handlers/note_handler.ex
index b012abd51..bd6e92238 100644
--- a/lib/pleroma/web/ostatus/handlers/note_handler.ex
+++ b/lib/pleroma/web/ostatus/handlers/note_handler.ex
@@ -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}
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 8ee27e63c..cecf5527c 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -5,6 +5,8 @@ defmodule Pleroma.Web.Router do
@instance Application.get_env(:pleroma, :instance)
@federating Keyword.get(@instance, :federating)
+ @public Keyword.get(@instance, :public)
+ @registrations_open Keyword.get(@instance, :registrations_open)
def user_fetcher(username) do
{:ok, Repo.get_by(User, %{nickname: username})}
@@ -160,21 +162,9 @@ defmodule Pleroma.Web.Router do
get("/statusnet/version", TwitterAPI.UtilController, :version)
end
- @instance Application.get_env(:pleroma, :instance)
- @registrations_open Keyword.get(@instance, :registrations_open)
-
scope "/api", Pleroma.Web do
pipe_through(:api)
- get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
-
- get(
- "/statuses/public_and_external_timeline",
- TwitterAPI.Controller,
- :public_and_external_timeline
- )
-
- get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
get("/users/show", TwitterAPI.Controller, :show_user)
@@ -193,6 +183,24 @@ defmodule Pleroma.Web.Router do
end
scope "/api", Pleroma.Web do
+ if @public do
+ pipe_through(:api)
+ else
+ pipe_through(:authenticated_api)
+ end
+
+ get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
+
+ get(
+ "/statuses/public_and_external_timeline",
+ TwitterAPI.Controller,
+ :public_and_external_timeline
+ )
+
+ get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
+ end
+
+ scope "/api", Pleroma.Web do
pipe_through(:authenticated_api)
get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
@@ -212,6 +220,7 @@ defmodule Pleroma.Web.Router do
get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
+ get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
post("/statuses/update", TwitterAPI.Controller, :status_update)
post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
diff --git a/lib/pleroma/web/templates/mastodon_api/mastodon/login.html.eex b/lib/pleroma/web/templates/mastodon_api/mastodon/login.html.eex
index 2ef67b901..34cd7ed89 100644
--- a/lib/pleroma/web/templates/mastodon_api/mastodon/login.html.eex
+++ b/lib/pleroma/web/templates/mastodon_api/mastodon/login.html.eex
@@ -1,9 +1,9 @@
-<h2>Login in to Mastodon Frontend</h2>
+<h2>Login to Mastodon Frontend</h2>
<%= if @error do %>
<h2><%= @error %></h2>
<% end %>
<%= form_for @conn, mastodon_api_path(@conn, :login), [as: "authorization"], fn f -> %>
-<%= text_input f, :name, placeholder: "Username" %>
+<%= text_input f, :name, placeholder: "Username or email" %>
<br>
<%= password_input f, :password, placeholder: "Password" %>
<br>
diff --git a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex
index a7fa7523b..de2241ec9 100644
--- a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex
+++ b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex
@@ -2,7 +2,7 @@
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
<h2>OAuth Authorization</h2>
<%= form_for @conn, o_auth_path(@conn, :authorize), [as: "authorization"], fn f -> %>
-<%= label f, :name, "Name" %>
+<%= label f, :name, "Name or email" %>
<%= text_input f, :name %>
<br>
<%= label f, :password, "Password" %>
diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
index 5f44e46c0..6cf8682b8 100644
--- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
@@ -1,8 +1,8 @@
defmodule Pleroma.Web.TwitterAPI.Controller do
use Pleroma.Web, :controller
- alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView}
+ alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView}
alias Pleroma.Web.CommonAPI
- alias Pleroma.{Repo, Activity, User}
+ alias Pleroma.{Repo, Activity, User, Notification}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Ecto.Changeset
@@ -119,6 +119,13 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|> render(ActivityView, "index.json", %{activities: activities, for: user})
end
+ def notifications(%{assigns: %{user: user}} = conn, params) do
+ notifications = Notification.for_user(user, params)
+
+ conn
+ |> render(NotificationView, "notification.json", %{notifications: notifications, for: user})
+ end
+
def follow(%{assigns: %{user: user}} = conn, params) do
case TwitterAPI.follow(user, params) do
{:ok, user, followed, _activity} ->
diff --git a/lib/pleroma/web/twitter_api/views/notification_view.ex b/lib/pleroma/web/twitter_api/views/notification_view.ex
new file mode 100644
index 000000000..f41edea0b
--- /dev/null
+++ b/lib/pleroma/web/twitter_api/views/notification_view.ex
@@ -0,0 +1,65 @@
+defmodule Pleroma.Web.TwitterAPI.NotificationView do
+ use Pleroma.Web, :view
+ alias Pleroma.{Notification, User}
+ alias Pleroma.Web.CommonAPI.Utils
+ alias Pleroma.Web.MediaProxy
+ alias Pleroma.Web.TwitterAPI.UserView
+ alias Pleroma.Web.TwitterAPI.ActivityView
+
+ defp get_user(ap_id, opts) do
+ cond do
+ user = opts[:users][ap_id] ->
+ user
+
+ String.ends_with?(ap_id, "/followers") ->
+ nil
+
+ ap_id == "https://www.w3.org/ns/activitystreams#Public" ->
+ nil
+
+ true ->
+ User.get_cached_by_ap_id(ap_id)
+ end
+ end
+
+ def render("notification.json", %{notifications: notifications, for: user}) do
+ render_many(
+ notifications,
+ Pleroma.Web.TwitterAPI.NotificationView,
+ "notification.json",
+ for: user
+ )
+ end
+
+ def render(
+ "notification.json",
+ %{
+ notification: %Notification{
+ id: id,
+ seen: seen,
+ activity: activity,
+ inserted_at: created_at
+ },
+ for: user
+ } = opts
+ ) do
+ ntype =
+ case activity.data["type"] do
+ "Create" -> "mention"
+ "Like" -> "like"
+ "Announce" -> "repeat"
+ "Follow" -> "follow"
+ end
+
+ from = get_user(activity.data["actor"], opts)
+
+ %{
+ "id" => id,
+ "ntype" => ntype,
+ "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
+ "from_profile" => UserView.render("show.json", %{user: from, for: user}),
+ "is_seen" => if(seen, do: 1, else: 0),
+ "created_at" => created_at |> Utils.format_naive_asctime()
+ }
+ end
+end
diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex
index e45c0ed8d..dc9ad2014 100644
--- a/lib/pleroma/web/web_finger/web_finger.ex
+++ b/lib/pleroma/web/web_finger/web_finger.ex
@@ -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",