diff options
author | Francis Dinh <normandy@firemail.cc> | 2018-04-20 16:47:44 -0400 |
---|---|---|
committer | Francis Dinh <normandy@firemail.cc> | 2018-04-20 16:48:18 -0400 |
commit | c5dc7e6e3166674744b33f0a098622f263edb605 (patch) | |
tree | 9059aa5684e377c16f71da2e0f581e355809a1a5 /lib | |
parent | 32a26eb91048bb92abfd3c7770dc0d72855101c3 (diff) | |
parent | a61e8ac15473aca6d0ec9ef20df981bcef9d5897 (diff) | |
download | pleroma-c5dc7e6e3166674744b33f0a098622f263edb605.tar.gz |
Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into feature/unrepeats
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mix/tasks/generate_config.ex | 16 | ||||
-rw-r--r-- | lib/mix/tasks/rm_user.ex | 6 | ||||
-rw-r--r-- | lib/mix/tasks/sample_config.eex | 6 | ||||
-rw-r--r-- | lib/pleroma/user.ex | 7 | ||||
-rw-r--r-- | lib/pleroma/web/common_api/utils.ex | 1 | ||||
-rw-r--r-- | lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 6 | ||||
-rw-r--r-- | lib/pleroma/web/oauth/oauth_controller.ex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/router.ex | 1 | ||||
-rw-r--r-- | lib/pleroma/web/templates/mastodon_api/mastodon/login.html.eex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/templates/o_auth/o_auth/show.html.eex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/twitter_api_controller.ex | 11 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/views/notification_view.ex | 65 |
12 files changed, 95 insertions, 30 deletions
diff --git a/lib/mix/tasks/generate_config.ex b/lib/mix/tasks/generate_config.ex index ae9ac3b75..70a110561 100644 --- a/lib/mix/tasks/generate_config.ex +++ b/lib/mix/tasks/generate_config.ex @@ -9,20 +9,6 @@ defmodule Mix.Tasks.GenerateConfig do name = IO.gets("What is the name of your instance? (e.g. Pleroma/Soykaf): ") |> String.trim() email = IO.gets("What's your admin email address: ") |> String.trim() - mediaproxy = - IO.gets("Do you want to activate the mediaproxy? (y/N): ") - |> String.trim() - |> String.downcase() - |> String.starts_with?("y") - - proxy_url = - if mediaproxy do - IO.gets("What is the mediaproxy's URL? (e.g. https://cache.example.com): ") - |> String.trim() - else - "https://cache.example.com" - end - secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) dbpass = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64) @@ -35,8 +21,6 @@ defmodule Mix.Tasks.GenerateConfig do email: email, name: name, secret: secret, - mediaproxy: mediaproxy, - proxy_url: proxy_url, dbpass: dbpass ) diff --git a/lib/mix/tasks/rm_user.ex b/lib/mix/tasks/rm_user.ex index aa0cf4951..6a698f360 100644 --- a/lib/mix/tasks/rm_user.ex +++ b/lib/mix/tasks/rm_user.ex @@ -1,14 +1,14 @@ defmodule Mix.Tasks.RmUser do use Mix.Task import Mix.Ecto - alias Pleroma.User + alias Pleroma.{User, Repo} @shortdoc "Permanently delete a user" def run([nickname]) do - ensure_started(Repo, []) + Mix.Task.run("app.start") with %User{local: true} = user <- User.get_by_nickname(nickname) do - user.delete() + User.delete(user) end end end diff --git a/lib/mix/tasks/sample_config.eex b/lib/mix/tasks/sample_config.eex index 9330fae2d..e37c864c0 100644 --- a/lib/mix/tasks/sample_config.eex +++ b/lib/mix/tasks/sample_config.eex @@ -11,9 +11,9 @@ config :pleroma, :instance, registrations_open: true config :pleroma, :media_proxy, - enabled: <%= mediaproxy %>, - redirect_on_failure: true, - base_url: "<%= proxy_url %>" + enabled: false, + redirect_on_failure: true + #base_url: "https://cache.pleroma.social" # Configure your database config :pleroma, Pleroma.Repo, diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index e959fe677..c77fd6816 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -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) 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/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index ebd587d26..a49be0588 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -217,8 +217,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do activities = [] else activities = - ActivityPub.fetch_public_activities(params) - |> Enum.reverse() + ActivityPub.fetch_public_activities(params) + |> Enum.reverse() end conn @@ -700,7 +700,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..6297b7bae 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 diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 5a32cf7b4..56dc6533b 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -213,6 +213,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..2bb54977e 100644 --- a/lib/pleroma/web/templates/mastodon_api/mastodon/login.html.eex +++ b/lib/pleroma/web/templates/mastodon_api/mastodon/login.html.eex @@ -3,7 +3,7 @@ <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 02b4e9eb0..429a0b7ac 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 |