diff options
author | rinpatch <rinpatch@sdf.org> | 2019-06-15 09:56:01 +0000 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2019-06-15 09:56:01 +0000 |
commit | fb4af26d75406f557a8b1a8dd388e16865b5bda2 (patch) | |
tree | be0e4beaddc40d8daeea09f2c94410b2991b677e /lib | |
parent | 62ffc00a5d5975a75c905bc728feb71cd15a34d3 (diff) | |
parent | 0632ed2f87671d90d029d435a084a8da72f549ea (diff) | |
download | pleroma-fb4af26d75406f557a8b1a8dd388e16865b5bda2.tar.gz |
Merge branch 'feature/add-chat-token-to-masto-api' into 'develop'
Mastodon API: Return the token needed for the chat.
See merge request pleroma/pleroma!1292
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 9 | ||||
-rw-r--r-- | lib/pleroma/web/mastodon_api/views/account_view.ex | 10 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 684b03066..eea4040ec 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -168,8 +168,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def verify_credentials(%{assigns: %{user: user}} = conn, _) do + chat_token = Phoenix.Token.sign(conn, "user socket", user.id) + account = - AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true}) + AccountView.render("account.json", %{ + user: user, + for: user, + with_pleroma_settings: true, + with_chat_token: chat_token + }) json(conn, account) end diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 0ec9ecd93..72ae9bcda 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -133,6 +133,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do |> maybe_put_settings(user, opts[:for], user_info) |> maybe_put_notification_settings(user, opts[:for]) |> maybe_put_settings_store(user, opts[:for], opts) + |> maybe_put_chat_token(user, opts[:for], opts) end defp username_from_nickname(string) when is_binary(string) do @@ -164,6 +165,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do defp maybe_put_settings_store(data, _, _, _), do: data + defp maybe_put_chat_token(data, %User{id: id}, %User{id: id}, %{ + with_chat_token: token + }) do + data + |> Kernel.put_in([:pleroma, :chat_token], token) + end + + defp maybe_put_chat_token(data, _, _, _), do: data + defp maybe_put_role(data, %User{info: %{show_role: true}} = user, _) do data |> Kernel.put_in([:pleroma, :is_admin], user.info.is_admin) |