Remove Shout feature

This commit is contained in:
Alex Gleason 2022-11-03 13:07:50 -05:00
parent f8e8bd9f5c
commit 39d7093ff5
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
23 changed files with 17 additions and 409 deletions

View file

@ -110,17 +110,6 @@
"xmpp"
]
websocket_config = [
path: "/websocket",
serializer: [
{Phoenix.Socket.V1.JSONSerializer, "~> 1.0.0"},
{Phoenix.Socket.V2.JSONSerializer, "~> 2.0.0"}
],
timeout: 60_000,
transport_log: false,
compress: false
]
# Configures the endpoint
config :pleroma, Pleroma.Web.Endpoint,
url: [host: "localhost"],
@ -130,9 +119,6 @@
{:_,
[
{"/api/v1/streaming", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
{"/websocket", Phoenix.Endpoint.CowboyWebSocket,
{Phoenix.Transports.WebSocket,
{Pleroma.Web.Endpoint, Pleroma.Web.UserSocket, websocket_config}}},
{:_, Phoenix.Endpoint.Cowboy2Handler, {Pleroma.Web.Endpoint, []}}
]}
]
@ -475,10 +461,6 @@
image_quality: 85,
min_content_length: 100 * 1024
config :pleroma, :shout,
enabled: true,
limit: 5_000
config :phoenix, :format_encoders, json: Jason, "activity+json": Jason
config :phoenix, :json_library, Jason

View file

@ -2742,27 +2742,6 @@
}
]
},
%{
group: :pleroma,
key: :shout,
type: :group,
description: "Pleroma shout settings",
children: [
%{
key: :enabled,
type: :boolean,
description: "Enables the backend Shoutbox chat feature."
},
%{
key: :limit,
type: :integer,
description: "Shout message character limit.",
suggestions: [
5_000
]
}
]
},
%{
group: :pleroma,
key: :http,

View file

@ -8,11 +8,6 @@ For from source installations Pleroma configuration works by first importing the
To add configuration to your config file, you can copy it from the base config. The latest version of it can be viewed [here](https://git.pleroma.social/pleroma/pleroma/blob/develop/config/config.exs). You can also use this file if you don't know how an option is supposed to be formatted.
## :shout
* `enabled` - Enables the backend Shoutbox chat feature. Defaults to `true`.
* `limit` - Shout character limit. Defaults to `5_000`
## :instance
* `name`: The instances name.
* `email`: Email used to reach an Administrator/Moderator of the instance.

View file

@ -103,7 +103,6 @@ Has these additional fields under the `pleroma` object:
- `hide_followers_count`: boolean, true when the user has follower stat hiding enabled
- `hide_follows_count`: boolean, true when the user has follow stat hiding enabled
- `settings_store`: A generic map of settings for frontends. Opaque to the backend. Only returned in `/api/v1/accounts/verify_credentials` and `/api/v1/accounts/update_credentials`
- `chat_token`: The token needed for Pleroma shoutbox. Only returned in `/api/v1/accounts/verify_credentials`
- `deactivated`: boolean, true when the user is deactivated
- `allow_following_move`: boolean, true when the user allows automatically follow moved following accounts
- `unread_conversation_count`: The count of unread conversations. Only returned to the account owner.

View file

@ -45,7 +45,6 @@ See also [the Nodeinfo standard](https://nodeinfo.diaspora.software/).
"multifetch",
"pleroma:api/v1/notifications:include_types_filter",
"chat",
"shout",
"relay",
"pleroma_emoji_reactions",
"pleroma_chat_messages"
@ -205,7 +204,6 @@ See also [the Nodeinfo standard](https://nodeinfo.diaspora.software/).
"multifetch",
"pleroma:api/v1/notifications:include_types_filter",
"chat",
"shout",
"relay",
"pleroma_emoji_reactions",
"pleroma_chat_messages"

View file

@ -112,7 +112,6 @@ def start(_type, _args) do
] ++
task_children(@mix_env) ++
dont_run_in_test(@mix_env) ++
shout_child(shout_enabled?()) ++
[Pleroma.Gopher.Server]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
@ -237,8 +236,6 @@ def build_cachex(type, opts),
type: :worker
}
defp shout_enabled?, do: Config.get([:shout, :enabled])
defp dont_run_in_test(env) when env in [:test, :benchmark], do: []
defp dont_run_in_test(_) do
@ -259,15 +256,6 @@ defp background_migrators do
]
end
defp shout_child(true) do
[
Pleroma.Web.ShoutChannel.ShoutChannelState,
{Phoenix.PubSub, [name: Pleroma.PubSub, adapter: Phoenix.PubSub.PG2]}
]
end
defp shout_child(_), do: []
defp task_children(:test) do
[
%{

View file

@ -214,7 +214,6 @@ def warn do
check_activity_expiration_config(),
check_remote_ip_plug_name(),
check_uploders_s3_public_endpoint(),
check_old_chat_shoutbox(),
check_quarantined_instances_tuples(),
check_transparency_exclusions_tuples(),
check_simple_policy_tuples(),
@ -392,27 +391,4 @@ def check_uploders_s3_public_endpoint do
:ok
end
end
@spec check_old_chat_shoutbox() :: :ok | nil
def check_old_chat_shoutbox do
instance_config = Pleroma.Config.get([:instance])
chat_config = Pleroma.Config.get([:chat]) || []
use_old_config =
Keyword.has_key?(instance_config, :chat_limit) or
Keyword.has_key?(chat_config, :enabled)
if use_old_config do
Logger.error("""
!!!DEPRECATION WARNING!!!
Your config is using the old namespace for the Shoutbox configuration. You need to convert to the new namespace. e.g.,
\n* `config :pleroma, :chat, enabled` and `config :pleroma, :instance, chat_limit` are now equal to:
\n* `config :pleroma, :shout, enabled` and `config :pleroma, :shout, limit`
""")
:error
else
:ok
end
end
end

View file

@ -16,7 +16,6 @@ defmodule Pleroma.Config.TransferTask do
defp reboot_time_keys,
do: [
{:pleroma, :hackney_pools},
{:pleroma, :shout},
{:pleroma, Oban},
{:pleroma, :rate_limit},
{:pleroma, :markup},

View file

@ -49,7 +49,6 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
},
background_image: %Schema{type: :string, nullable: true, format: :uri},
birthday: %Schema{type: :string, nullable: true, format: :date},
chat_token: %Schema{type: :string},
is_confirmed: %Schema{
type: :boolean,
description:
@ -180,8 +179,6 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
"is_moderator" => false,
"skip_thread_containment" => false,
"accepts_chat_messages" => true,
"chat_token" =>
"SFMyNTY.g3QAAAACZAAEZGF0YW0AAAASOXRLaTNlc2JHN09RZ1oyOTIwZAAGc2lnbmVkbgYARNplS3EB.Mb_Iaqew2bN1I1o79B_iP7encmVCpTKC4OtHZRxdjKc",
"unread_conversation_count" => 0,
"tags" => [],
"notification_settings" => %{

View file

@ -1,45 +0,0 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.UserSocket do
use Phoenix.Socket
alias Pleroma.User
## Channels
# channel "room:*", Pleroma.Web.RoomChannel
channel("chat:*", Pleroma.Web.ShoutChannel)
# Socket params are passed from the client and can
# be used to verify and authenticate a user. After
# verification, you can put default assigns into
# the socket that will be set for all channels, ie
#
# {:ok, assign(socket, :user_id, verified_user_id)}
#
# To deny connection, return `:error`.
#
# See `Phoenix.Token` documentation for examples in
# performing token verification on connect.
def connect(%{"token" => token}, socket) do
with true <- Pleroma.Config.get([:shout, :enabled]),
{:ok, user_id} <- Phoenix.Token.verify(socket, "user socket", token, max_age: 84_600),
%User{} = user <- Pleroma.User.get_cached_by_id(user_id) do
{:ok, assign(socket, :user_name, user.nickname)}
else
_e -> :error
end
end
# Socket id's are topics that allow you to identify all sockets for a given user:
#
# def id(socket), do: "user_socket:#{socket.assigns.user_id}"
#
# Would allow you to broadcast a "disconnect" event and terminate
# all active sockets and channels for a given user:
#
# Pleroma.Web.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
#
# Returning `nil` makes this socket anonymous.
def id(_socket), do: nil
end

View file

@ -9,7 +9,6 @@ defmodule Pleroma.Web.Endpoint do
alias Pleroma.Config
socket("/socket", Pleroma.Web.UserSocket)
socket("/live", Phoenix.LiveView.Socket)
plug(Unplug,

View file

@ -157,13 +157,10 @@ defp validate_email_param(_) do
@doc "GET /api/v1/accounts/verify_credentials"
def verify_credentials(%{assigns: %{user: user}} = conn, _) do
chat_token = Phoenix.Token.sign(conn, "user socket", user.id)
render(conn, "show.json",
user: user,
for: user,
with_pleroma_settings: true,
with_chat_token: chat_token
with_pleroma_settings: true
)
end

View file

@ -305,7 +305,6 @@ defp do_render("show.json", %{user: user} = opts) do
|> maybe_put_settings(user, opts[:for], opts)
|> maybe_put_notification_settings(user, opts[:for])
|> maybe_put_settings_store(user, opts[:for], opts)
|> maybe_put_chat_token(user, opts[:for], opts)
|> maybe_put_activation_status(user, opts[:for])
|> maybe_put_follow_requests_count(user, opts[:for])
|> maybe_put_allow_following_move(user, opts[:for])
@ -362,15 +361,6 @@ defp maybe_put_settings_store(data, %User{} = user, %User{}, %{
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{show_role: true} = user, _) do
data
|> Kernel.put_in([:pleroma, :is_admin], user.is_admin)

View file

@ -41,7 +41,6 @@ def render("show.json", _) do
background_upload_limit: Keyword.get(instance, :background_upload_limit),
banner_upload_limit: Keyword.get(instance, :banner_upload_limit),
background_image: Pleroma.Web.Endpoint.url() <> Keyword.get(instance, :background_image),
shout_limit: Config.get([:shout, :limit]),
description_limit: Keyword.get(instance, :description_limit),
pleroma: pleroma_configuration(instance),
soapbox: %{
@ -120,13 +119,6 @@ def features do
if Config.get([:gopher, :enabled]) do
"gopher"
end,
# backwards compat
if Config.get([:shout, :enabled]) do
"chat"
end,
if Config.get([:shout, :enabled]) do
"shout"
end,
if Config.get([:instance, :allow_relay]) do
"relay"
end,
@ -245,7 +237,6 @@ defp pleroma_configuration2(instance) do
banner_upload_limit: Keyword.get(instance, :banner_upload_limit),
background_image:
Pleroma.Web.Endpoint.url() <> Keyword.get(instance, :background_image),
shout_limit: Config.get([:shout, :limit]),
description_limit: Keyword.get(instance, :description_limit)
})
})

View file

@ -1,59 +0,0 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ShoutChannel do
use Phoenix.Channel
alias Pleroma.User
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.ShoutChannel.ShoutChannelState
def join("chat:public", _message, socket) do
send(self(), :after_join)
{:ok, socket}
end
def handle_info(:after_join, socket) do
push(socket, "messages", %{messages: ShoutChannelState.messages()})
{:noreply, socket}
end
def handle_in("new_msg", %{"text" => text}, %{assigns: %{user_name: user_name}} = socket) do
text = String.trim(text)
if String.length(text) in 1..Pleroma.Config.get([:shout, :limit]) do
author = User.get_cached_by_nickname(user_name)
author_json = AccountView.render("show.json", user: author, skip_visibility_check: true)
message = ShoutChannelState.add_message(%{text: text, author: author_json})
broadcast!(socket, "new_msg", message)
end
{:noreply, socket}
end
end
defmodule Pleroma.Web.ShoutChannel.ShoutChannelState do
use Agent
@max_messages 20
def start_link(_) do
Agent.start_link(fn -> %{max_id: 1, messages: []} end, name: __MODULE__)
end
def add_message(message) do
Agent.get_and_update(__MODULE__, fn state ->
id = state[:max_id] + 1
message = Map.put(message, "id", id)
messages = [message | state[:messages]] |> Enum.take(@max_messages)
{message, %{max_id: id, messages: messages}}
end)
end
def messages do
Agent.get(__MODULE__, fn state -> state[:messages] |> Enum.reverse() end)
end
end

View file

@ -7,75 +7,6 @@ defmodule Pleroma.Repo.Migrations.RenameInstanceChat do
alias Pleroma.ConfigDB
@instance_params %{group: :pleroma, key: :instance}
@shout_params %{group: :pleroma, key: :shout}
@chat_params %{group: :pleroma, key: :chat}
def up do
instance_updated? = maybe_update_instance_key(:up) != :noop
chat_updated? = maybe_update_chat_key(:up) != :noop
case Enum.any?([instance_updated?, chat_updated?]) do
true -> :ok
false -> :noop
end
end
def down do
instance_updated? = maybe_update_instance_key(:down) != :noop
chat_updated? = maybe_update_chat_key(:down) != :noop
case Enum.any?([instance_updated?, chat_updated?]) do
true -> :ok
false -> :noop
end
end
# pleroma.instance.chat_limit -> pleroma.shout.limit
defp maybe_update_instance_key(:up) do
with %ConfigDB{value: values} <- ConfigDB.get_by_params(@instance_params),
limit when is_integer(limit) <- values[:chat_limit] do
@shout_params |> Map.put(:value, limit: limit) |> ConfigDB.update_or_create()
@instance_params |> Map.put(:subkeys, [":chat_limit"]) |> ConfigDB.delete()
else
_ ->
:noop
end
end
# pleroma.shout.limit -> pleroma.instance.chat_limit
defp maybe_update_instance_key(:down) do
with %ConfigDB{value: values} <- ConfigDB.get_by_params(@shout_params),
limit when is_integer(limit) <- values[:limit] do
@instance_params |> Map.put(:value, chat_limit: limit) |> ConfigDB.update_or_create()
@shout_params |> Map.put(:subkeys, [":limit"]) |> ConfigDB.delete()
else
_ ->
:noop
end
end
# pleroma.chat.enabled -> pleroma.shout.enabled
defp maybe_update_chat_key(:up) do
with %ConfigDB{value: values} <- ConfigDB.get_by_params(@chat_params),
enabled? when is_boolean(enabled?) <- values[:enabled] do
@shout_params |> Map.put(:value, enabled: enabled?) |> ConfigDB.update_or_create()
@chat_params |> Map.put(:subkeys, [":enabled"]) |> ConfigDB.delete()
else
_ ->
:noop
end
end
# pleroma.shout.enabled -> pleroma.chat.enabled
defp maybe_update_chat_key(:down) do
with %ConfigDB{value: values} <- ConfigDB.get_by_params(@shout_params),
enabled? when is_boolean(enabled?) <- values[:enabled] do
@chat_params |> Map.put(:value, enabled: enabled?) |> ConfigDB.update_or_create()
@shout_params |> Map.put(:subkeys, [":enabled"]) |> ConfigDB.delete()
else
_ ->
:noop
end
end
def up, do: :noop
def down, do: :noop
end

View file

@ -379,14 +379,4 @@ test "pool timeout" do
"Your config is using old setting name `timeout` instead of `recv_timeout` in pool settings"
end
end
test "check_old_chat_shoutbox/0" do
clear_config([:instance, :chat_limit], 1_000)
clear_config([:chat, :enabled], true)
assert capture_log(fn ->
DeprecationWarnings.check_old_chat_shoutbox()
end) =~
"Your config is using the old namespace for the Shoutbox configuration."
end
end

View file

@ -110,8 +110,8 @@ test "don't restart if no reboot time settings were changed" do
end
test "on reboot time key" do
clear_config(:shout)
insert(:config, key: :shout, value: [enabled: false])
clear_config([:rate_limit, :enabled], true)
insert(:config, key: :rate_limit, value: [enabled: false])
# Note that we don't actually restart Pleroma.
# See module Restarter.Pleroma
@ -144,10 +144,10 @@ test "on reboot time subkey" do
end
test "don't restart pleroma on reboot time key and subkey if there is false flag" do
clear_config(:shout)
clear_config([:rate_limit, :enabled], true)
clear_config(Pleroma.Captcha)
insert(:config, key: :shout, value: [enabled: false])
insert(:config, key: :rate_limit, value: [enabled: false])
insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60])
refute String.contains?(

View file

@ -1,56 +0,0 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.RenameInstanceChatTest do
use Pleroma.DataCase
import Pleroma.Factory
import Pleroma.Tests.Helpers
alias Pleroma.ConfigDB
setup do: clear_config([:instance])
setup do: clear_config([:chat])
setup_all do: require_migration("20200806175913_rename_instance_chat")
describe "up/0" do
test "migrates chat settings to shout", %{migration: migration} do
insert(:config, group: :pleroma, key: :instance, value: [chat_limit: 6000])
insert(:config, group: :pleroma, key: :chat, value: [enabled: true])
assert migration.up() == :ok
assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil
assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}) == nil
assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}).value == [
limit: 6000,
enabled: true
]
end
test "does nothing when chat settings are not set", %{migration: migration} do
assert migration.up() == :noop
assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil
assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) == nil
end
end
describe "down/0" do
test "migrates shout settings back to instance and chat", %{migration: migration} do
insert(:config, group: :pleroma, key: :shout, value: [limit: 42, enabled: true])
assert migration.down() == :ok
assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}).value == [enabled: true]
assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}).value == [chat_limit: 42]
assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) == nil
end
test "does nothing when shout settings are not set", %{migration: migration} do
assert migration.down() == :noop
assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil
assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}) == nil
assert ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) == nil
end
end
end

View file

@ -409,7 +409,7 @@ test "saving config with partial update", %{conn: conn} do
end
test "saving config which need pleroma reboot", %{conn: conn} do
clear_config([:shout, :enabled], true)
clear_config([:streamer, :workers], 3)
assert conn
|> put_req_header("content-type", "application/json")
@ -417,17 +417,17 @@ test "saving config which need pleroma reboot", %{conn: conn} do
"/api/pleroma/admin/config",
%{
configs: [
%{group: ":pleroma", key: ":shout", value: [%{"tuple" => [":enabled", true]}]}
%{group: ":pleroma", key: ":streamer", value: [%{"tuple" => [":workers", 5]}]}
]
}
)
|> json_response_and_validate_schema(200) == %{
"configs" => [
%{
"db" => [":enabled"],
"db" => [":workers"],
"group" => ":pleroma",
"key" => ":shout",
"value" => [%{"tuple" => [":enabled", true]}]
"key" => ":streamer",
"value" => [%{"tuple" => [":workers", 5]}]
}
],
"need_reboot" => true
@ -454,7 +454,7 @@ test "saving config which need pleroma reboot", %{conn: conn} do
end
test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
clear_config([:shout, :enabled], true)
clear_config([:streamer, :workers], 3)
assert conn
|> put_req_header("content-type", "application/json")
@ -462,17 +462,17 @@ test "update setting which need reboot, don't change reboot flag until reboot",
"/api/pleroma/admin/config",
%{
configs: [
%{group: ":pleroma", key: ":shout", value: [%{"tuple" => [":enabled", true]}]}
%{group: ":pleroma", key: ":streamer", value: [%{"tuple" => [":workers", 5]}]}
]
}
)
|> json_response_and_validate_schema(200) == %{
"configs" => [
%{
"db" => [":enabled"],
"db" => [":workers"],
"group" => ":pleroma",
"key" => ":shout",
"value" => [%{"tuple" => [":enabled", true]}]
"key" => ":streamer",
"value" => [%{"tuple" => [":workers", 5]}]
}
],
"need_reboot" => true

View file

@ -1823,7 +1823,6 @@ test "verify_credentials" do
response = json_response_and_validate_schema(conn, 200)
assert %{"id" => id, "source" => %{"privacy" => "public"}} = response
assert response["pleroma"]["chat_token"]
assert response["pleroma"]["unread_notifications_count"] == 6
assert id == to_string(user.id)
end

View file

@ -43,7 +43,6 @@ test "get instance information", %{conn: conn} do
"background_upload_limit" => _,
"banner_upload_limit" => _,
"background_image" => from_config_background,
"shout_limit" => _,
"description_limit" => _,
"rules" => _,
"pleroma" => %{

View file

@ -1,41 +0,0 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ShoutChannelTest do
use Pleroma.Web.ChannelCase
alias Pleroma.Web.ShoutChannel
alias Pleroma.Web.UserSocket
import Pleroma.Factory
setup do
user = insert(:user)
{:ok, _, socket} =
socket(UserSocket, "", %{user_name: user.nickname})
|> subscribe_and_join(ShoutChannel, "chat:public")
{:ok, socket: socket}
end
test "it broadcasts a message", %{socket: socket} do
push(socket, "new_msg", %{"text" => "why is tenshi eating a corndog so cute?"})
assert_broadcast("new_msg", %{text: "why is tenshi eating a corndog so cute?"})
end
describe "message lengths" do
setup do: clear_config([:shout, :limit])
test "it ignores messages of length zero", %{socket: socket} do
push(socket, "new_msg", %{"text" => ""})
refute_broadcast("new_msg", %{text: ""})
end
test "it ignores messages above a certain length", %{socket: socket} do
clear_config([:shout, :limit], 2)
push(socket, "new_msg", %{"text" => "123"})
refute_broadcast("new_msg", %{text: "123"})
end
end
end