Allow disabling Chats feature
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
parent
0a076443ad
commit
4aa0d5d709
9 changed files with 54 additions and 8 deletions
|
|
@ -979,6 +979,8 @@ config :pleroma, :database_config_whitelist, [
|
||||||
{:web_push_encryption, :vapid_details}
|
{:web_push_encryption, :vapid_details}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
config :pleroma, Pleroma.Chat, enabled: true
|
||||||
|
|
||||||
# Import environment specific config. This must remain at the bottom
|
# Import environment specific config. This must remain at the bottom
|
||||||
# of this file so it overrides the configuration defined above.
|
# of this file so it overrides the configuration defined above.
|
||||||
import_config "#{Mix.env()}.exs"
|
import_config "#{Mix.env()}.exs"
|
||||||
|
|
|
||||||
|
|
@ -2726,6 +2726,19 @@ config :pleroma, :config_description, [
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
%{
|
||||||
|
group: :pleroma,
|
||||||
|
key: Pleroma.Chat,
|
||||||
|
type: :group,
|
||||||
|
description: "Pleroma Chat settings",
|
||||||
|
children: [
|
||||||
|
%{
|
||||||
|
key: :enabled,
|
||||||
|
type: :boolean,
|
||||||
|
description: "Enables the backend chats API."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
%{
|
%{
|
||||||
group: :pleroma,
|
group: :pleroma,
|
||||||
key: :http,
|
key: :http,
|
||||||
|
|
|
||||||
|
|
@ -108,4 +108,6 @@ defmodule Pleroma.Chat do
|
||||||
|> cast(%{pinned: false}, [:pinned])
|
|> cast(%{pinned: false}, [:pinned])
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def enabled?, do: Pleroma.Config.get([__MODULE__, :enabled], true)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
|
||||||
capabilities =
|
capabilities =
|
||||||
if is_boolean(user.accepts_chat_messages) do
|
if is_boolean(user.accepts_chat_messages) do
|
||||||
%{
|
%{
|
||||||
"acceptsChatMessages" => user.accepts_chat_messages
|
"acceptsChatMessages" => Pleroma.Chat.enabled?() and user.accepts_chat_messages
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
%{}
|
%{}
|
||||||
|
|
|
||||||
|
|
@ -385,6 +385,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
|
||||||
|> cast_params()
|
|> cast_params()
|
||||||
|> Map.update(:include_types, [], fn include_types -> include_types end)
|
|> Map.update(:include_types, [], fn include_types -> include_types end)
|
||||||
|
|
||||||
|
if "pleroma:chat_mention" in options.include_types and not Pleroma.Chat.enabled?() do
|
||||||
|
options
|
||||||
|
|> Map.update(:include_types, [], fn include_types ->
|
||||||
|
List.delete(include_types, "pleroma:chat_mention")
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
options
|
||||||
|
end
|
||||||
|
|
||||||
if ("pleroma:report" not in options.include_types and
|
if ("pleroma:report" not in options.include_types and
|
||||||
User.privileged?(user, :reports_manage_reports)) or
|
User.privileged?(user, :reports_manage_reports)) or
|
||||||
User.privileged?(user, :reports_manage_reports) do
|
User.privileged?(user, :reports_manage_reports) do
|
||||||
|
|
|
||||||
|
|
@ -287,6 +287,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||||
user.last_status_at &&
|
user.last_status_at &&
|
||||||
user.last_status_at |> NaiveDateTime.to_date() |> Date.to_iso8601()
|
user.last_status_at |> NaiveDateTime.to_date() |> Date.to_iso8601()
|
||||||
|
|
||||||
|
accepts_chat_messages = Pleroma.Chat.enabled?() and user.accepts_chat_messages
|
||||||
|
|
||||||
%{
|
%{
|
||||||
id: to_string(user.id),
|
id: to_string(user.id),
|
||||||
username: username_from_nickname(user.nickname),
|
username: username_from_nickname(user.nickname),
|
||||||
|
|
@ -336,7 +338,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||||
relationship: relationship,
|
relationship: relationship,
|
||||||
skip_thread_containment: user.skip_thread_containment,
|
skip_thread_containment: user.skip_thread_containment,
|
||||||
background_image: image_url(user.background) |> MediaProxy.url(),
|
background_image: image_url(user.background) |> MediaProxy.url(),
|
||||||
accepts_chat_messages: user.accepts_chat_messages,
|
accepts_chat_messages: accepts_chat_messages,
|
||||||
favicon: favicon,
|
favicon: favicon,
|
||||||
avatar_description: avatar_description,
|
avatar_description: avatar_description,
|
||||||
header_description: header_description
|
header_description: header_description
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,9 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
|
||||||
def features do
|
def features do
|
||||||
[
|
[
|
||||||
"pleroma_api",
|
"pleroma_api",
|
||||||
|
if Config.get([Pleroma.Chat, :enabled], true) do
|
||||||
|
"chat"
|
||||||
|
end,
|
||||||
"mastodon_api",
|
"mastodon_api",
|
||||||
"mastodon_api_grouped_notifications",
|
"mastodon_api_grouped_notifications",
|
||||||
"mastodon_api_streaming",
|
"mastodon_api_streaming",
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
|
||||||
)
|
)
|
||||||
|
|
||||||
plug(Pleroma.Web.ApiSpec.CastAndValidate, replace_params: false)
|
plug(Pleroma.Web.ApiSpec.CastAndValidate, replace_params: false)
|
||||||
|
plug(:ensure_chats_enabled)
|
||||||
|
|
||||||
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.ChatOperation
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.ChatOperation
|
||||||
|
|
||||||
|
|
@ -244,4 +245,16 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
|
||||||
_ -> nil
|
_ -> nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp ensure_chats_enabled(conn, _opts) do
|
||||||
|
if Chat.enabled?() do
|
||||||
|
conn
|
||||||
|
else
|
||||||
|
conn
|
||||||
|
|> put_status(:not_found)
|
||||||
|
|> put_view(Pleroma.Web.ErrorView)
|
||||||
|
|> render("404.json")
|
||||||
|
|> halt()
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -289,6 +289,7 @@ defmodule Pleroma.Web.Streamer do
|
||||||
|
|
||||||
defp do_stream(topic, {user, %MessageReference{} = cm_ref})
|
defp do_stream(topic, {user, %MessageReference{} = cm_ref})
|
||||||
when topic in ["user", "user:pleroma_chat"] do
|
when topic in ["user", "user:pleroma_chat"] do
|
||||||
|
if Pleroma.Chat.enabled?() do
|
||||||
topic = "#{topic}:#{user.id}"
|
topic = "#{topic}:#{user.id}"
|
||||||
|
|
||||||
text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref}, topic)
|
text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref}, topic)
|
||||||
|
|
@ -299,6 +300,7 @@ defmodule Pleroma.Web.Streamer do
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp do_stream("user", %Activity{} = item) do
|
defp do_stream("user", %Activity{} = item) do
|
||||||
Logger.debug("Trying to push to users")
|
Logger.debug("Trying to push to users")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue