aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoger Braun <rbraun@Bobble.local>2017-09-13 15:55:10 +0200
committerRoger Braun <rbraun@Bobble.local>2017-09-13 15:55:10 +0200
commit49929321c761cf389d42ca52d88dc8ec09a375cc (patch)
tree2b1617202f4475a48d9d46a9773ea262d96b5ce4 /lib
parentf03524805fdc95b9681f59a68a1edb2885f2e7ba (diff)
downloadpleroma-49929321c761cf389d42ca52d88dc8ec09a375cc.tar.gz
Add relationships to masto api.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex9
-rw-r--r--lib/pleroma/web/mastodon_api/views/account_view.ex17
-rw-r--r--lib/pleroma/web/router.ex2
3 files changed, 28 insertions, 0 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 219d860a9..69b559a09 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.CommonAPI
+ import Ecto.Query
import Logger
def create_app(conn, params) do
@@ -177,6 +178,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|> json(result)
end
+ def relationships(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ id = List.wrap(id)
+ q = from u in User,
+ where: u.id in ^id
+ targets = Repo.all(q)
+ render conn, AccountView, "relationships.json", %{user: user, targets: targets}
+ end
+
def empty_array(conn, _) do
Logger.debug("Unimplemented, returning an empty array")
json(conn, [])
diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex
index 85cce754a..4e9ee4132 100644
--- a/lib/pleroma/web/mastodon_api/views/account_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/account_view.ex
@@ -1,6 +1,7 @@
defmodule Pleroma.Web.MastodonAPI.AccountView do
use Pleroma.Web, :view
alias Pleroma.User
+ alias Pleroma.Web.MastodonAPI.AccountView
defp image_url(%{"url" => [ %{ "href" => href } | t ]}), do: href
defp image_url(_), do: nil
@@ -38,4 +39,20 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
url: user.ap_id
}
end
+
+ def render("relationship.json", %{user: user, target: target}) do
+ %{
+ id: target.id,
+ following: User.following?(target, user),
+ followed_by: User.following?(user, target),
+ blocking: false,
+ muting: false,
+ requested: false,
+ domain_blocking: false
+ }
+ end
+
+ def render("relationships.json", %{user: user, targets: targets}) do
+ render_many(targets, AccountView, "relationship.json", user: user, as: :target)
+ end
end
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 161635558..883fd56f4 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -56,6 +56,8 @@ defmodule Pleroma.Web.Router do
pipe_through :authenticated_api
get "/accounts/verify_credentials", MastodonAPIController, :verify_credentials
+ get "/accounts/relationships", MastodonAPIController, :relationships
+
get "/timelines/home", MastodonAPIController, :home_timeline
post "/statuses", MastodonAPIController, :post_status