Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into develop

This commit is contained in:
Roger Braun 2018-02-02 17:14:58 +01:00
commit 9a9766d648
11 changed files with 63 additions and 15 deletions

View File

@ -104,13 +104,19 @@ defmodule Pleroma.Formatter do
{finmoji, "/finmoji/128px/#{finmoji}-128.png"} {finmoji, "/finmoji/128px/#{finmoji}-128.png"}
end) end)
@emoji_from_file (with {:ok, file} <- File.read("config/emoji.txt") do @emoji_from_file (with {:ok, default} <- File.read("config/emoji.txt") do
file custom =
|> String.trim with {:ok, custom} <- File.read("config/custom_emoji.txt") do
|> String.split("\n") custom
|> Enum.map(fn(line) -> else
[name, file] = String.split(line, ", ") _e -> ""
{name, file} end
(default <> "\n" <> custom)
|> String.trim()
|> String.split(~r/\n+/)
|> Enum.map(fn(line) ->
[name, file] = String.split(line, ~r/,\s*/)
{name, file}
end) end)
else else
_ -> [] _ -> []

View File

@ -12,7 +12,7 @@ defmodule Pleroma.Web.Endpoint do
at: "/media", from: "uploads", gzip: false at: "/media", from: "uploads", gzip: false
plug Plug.Static, plug Plug.Static,
at: "/", from: :pleroma, at: "/", from: :pleroma,
only: ~w(index.html static finmoji emoji packs sounds sw.js) only: ~w(index.html static finmoji emoji packs sounds instance sw.js)
# Code reloading can be explicitly enabled under the # Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint. # :code_reloader configuration of your endpoint.

View File

@ -103,6 +103,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
streaming_api: String.replace(Web.base_url, ["http","https"], "wss") streaming_api: String.replace(Web.base_url, ["http","https"], "wss")
}, },
stats: Stats.get_stats, stats: Stats.get_stats,
thumbnail: Web.base_url <> "/instance/thumbnail.jpeg",
max_toot_chars: Keyword.get(@instance, :limit) max_toot_chars: Keyword.get(@instance, :limit)
} }

View File

@ -62,6 +62,7 @@ defmodule Pleroma.Web.Router do
pipe_through :pleroma_html pipe_through :pleroma_html
get "/ostatus_subscribe", UtilController, :remote_follow get "/ostatus_subscribe", UtilController, :remote_follow
post "/ostatus_subscribe", UtilController, :do_remote_follow post "/ostatus_subscribe", UtilController, :do_remote_follow
post "/main/ostatus", UtilController, :remote_subscribe
end end
scope "/api/pleroma", Pleroma.Web.TwitterAPI do scope "/api/pleroma", Pleroma.Web.TwitterAPI do

View File

@ -0,0 +1,10 @@
<%= if @error do %>
<h2>Error: <%= @error %></h2>
<% else %>
<h2>Remotely follow <%= @nickname %></h2>
<%= form_for @conn, util_path(@conn, :remote_subscribe), [as: "user"], fn f -> %>
<%= hidden_input f, :nickname, value: @nickname %>
<%= text_input f, :profile, placeholder: "Your account ID, e.g. lain@quitter.se" %>
<%= submit "Follow" %>
<% end %>
<% end %>

View File

@ -3,6 +3,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
require Logger require Logger
alias Pleroma.Web alias Pleroma.Web
alias Pleroma.Web.OStatus alias Pleroma.Web.OStatus
alias Pleroma.Web.WebFinger
alias Comeonin.Pbkdf2 alias Comeonin.Pbkdf2
alias Pleroma.Formatter alias Pleroma.Formatter
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
@ -32,6 +33,26 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
json(conn, "ok") json(conn, "ok")
end end
def remote_subscribe(conn, %{"nickname" => nick, "profile" => _}) do
with %User{} = user <- User.get_cached_by_nickname(nick),
avatar = User.avatar_url(user) do
conn
|> render("subscribe.html", %{nickname: nick, avatar: avatar, error: false})
else
_e -> render(conn, "subscribe.html", %{nickname: nick, avatar: nil, error: "Could not find user"})
end
end
def remote_subscribe(conn, %{"user" => %{"nickname" => nick, "profile" => profile}}) do
with {:ok, %{"subscribe_address" => template}} <- WebFinger.finger(profile),
%User{ap_id: ap_id} <- User.get_cached_by_nickname(nick) do
conn
|> Phoenix.Controller.redirect(external: String.replace(template, "{uri}", ap_id))
else
_e ->
render(conn, "subscribe.html", %{nickname: nick, avatar: nil, error: "Something went wrong."})
end
end
def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do
{err, followee} = OStatus.find_or_make_user(acct) {err, followee} = OStatus.find_or_make_user(acct)
avatar = User.avatar_url(followee) avatar = User.avatar_url(followee)

View File

@ -47,6 +47,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
"statusnet_profile_url" => user.ap_id, "statusnet_profile_url" => user.ap_id,
"cover_photo" => User.banner_url(user) |> MediaProxy.url(), "cover_photo" => User.banner_url(user) |> MediaProxy.url(),
"background_image" => image_url(user.info["background"]) |> MediaProxy.url(), "background_image" => image_url(user.info["background"]) |> MediaProxy.url(),
"is_local" => user.local
} }
if assigns[:token] do if assigns[:token] do

View File

@ -69,11 +69,13 @@ defmodule Pleroma.Web.WebFinger do
topic = XML.string_from_xpath(~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href}, doc) topic = XML.string_from_xpath(~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href}, doc)
subject = XML.string_from_xpath("//Subject", doc) subject = XML.string_from_xpath("//Subject", doc)
salmon = XML.string_from_xpath(~s{//Link[@rel="salmon"]/@href}, doc) salmon = XML.string_from_xpath(~s{//Link[@rel="salmon"]/@href}, doc)
subscribe_address = XML.string_from_xpath(~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template}, doc)
data = %{ data = %{
"magic_key" => magic_key, "magic_key" => magic_key,
"topic" => topic, "topic" => topic,
"subject" => subject, "subject" => subject,
"salmon" => salmon "salmon" => salmon,
"subscribe_address" => subscribe_address
} }
{:ok, data} {:ok, data}
end end

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -302,7 +302,8 @@ defmodule Pleroma.Web.OStatusTest do
"host" => "social.heldscal.la", "host" => "social.heldscal.la",
"fqn" => user, "fqn" => user,
"bio" => "cofe", "bio" => "cofe",
"avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]} "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]},
"subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}"
} }
assert data == expected assert data == expected
end end
@ -325,7 +326,8 @@ defmodule Pleroma.Web.OStatusTest do
"host" => "social.heldscal.la", "host" => "social.heldscal.la",
"fqn" => user, "fqn" => user,
"bio" => "cofe", "bio" => "cofe",
"avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]} "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]},
"subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}"
} }
assert data == expected assert data == expected
end end

View File

@ -56,7 +56,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"rights" => %{}, "rights" => %{},
"statusnet_profile_url" => user.ap_id, "statusnet_profile_url" => user.ap_id,
"cover_photo" => banner, "cover_photo" => banner,
"background_image" => nil "background_image" => nil,
"is_local" => true
} }
assert represented == UserView.render("show.json", %{user: user}) assert represented == UserView.render("show.json", %{user: user})
@ -88,7 +89,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"rights" => %{}, "rights" => %{},
"statusnet_profile_url" => user.ap_id, "statusnet_profile_url" => user.ap_id,
"cover_photo" => banner, "cover_photo" => banner,
"background_image" => nil "background_image" => nil,
"is_local" => true
} }
assert represented == UserView.render("show.json", %{user: user, for: follower}) assert represented == UserView.render("show.json", %{user: user, for: follower})
@ -121,7 +123,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"rights" => %{}, "rights" => %{},
"statusnet_profile_url" => follower.ap_id, "statusnet_profile_url" => follower.ap_id,
"cover_photo" => banner, "cover_photo" => banner,
"background_image" => nil "background_image" => nil,
"is_local" => true
} }
assert represented == UserView.render("show.json", %{user: follower, for: user}) assert represented == UserView.render("show.json", %{user: follower, for: user})
@ -154,7 +157,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"rights" => %{}, "rights" => %{},
"statusnet_profile_url" => user.ap_id, "statusnet_profile_url" => user.ap_id,
"cover_photo" => banner, "cover_photo" => banner,
"background_image" => nil "background_image" => nil,
"is_local" => true
} }
blocker = Repo.get(User, blocker.id) blocker = Repo.get(User, blocker.id)