Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into feature/unrepeats
This commit is contained in:
commit
c5dc7e6e31
43 changed files with 405 additions and 74 deletions
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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" %>
|
||||
|
|
|
|||
|
|
@ -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} ->
|
||||
|
|
|
|||
65
lib/pleroma/web/twitter_api/views/notification_view.ex
Normal file
65
lib/pleroma/web/twitter_api/views/notification_view.ex
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue