From ff00b354fa5067c898e860e275748dd757cb04cd Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 3 Aug 2020 17:08:35 -0500 Subject: [PATCH 01/16] Rename the non-federating Chat feature to Shout --- CHANGELOG.md | 1 + config/config.exs | 4 ++-- config/description.exs | 8 ++++---- lib/pleroma/config/transfer_task.ex | 2 +- lib/pleroma/web/channels/user_socket.ex | 4 ++-- lib/pleroma/web/mastodon_api/views/instance_view.ex | 6 +++--- lib/pleroma/web/{chat_channel.ex => shout_channel.ex} | 14 +++++++------- test/pleroma/config/transfer_task_test.exs | 8 ++++---- .../web/admin_api/controllers/config_controller_test.exs | 12 ++++++------ .../mastodon_api/controllers/instance_controller_test.exs | 2 +- .../web/{chat_channel_test.exs => shout_channel_test.ex} | 10 +++++----- 11 files changed, 36 insertions(+), 35 deletions(-) rename lib/pleroma/web/{chat_channel.ex => shout_channel.ex} (78%) rename test/pleroma/web/{chat_channel_test.exs => shout_channel_test.ex} (80%) diff --git a/CHANGELOG.md b/CHANGELOG.md index feac7b1c3..1c08710a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed +- **Breaking:** Configuration: `:chat, enabled` moved to `:shout, enabled` and `:instance, chat_limit` moved to `:instance, shout_limit` - The `application` metadata returned with statuses is no longer hardcoded. Apps that want to display these details will now have valid data for new posts after this change. - HTTPSecurityPlug now sends a response header to opt out of Google's FLoC (Federated Learning of Cohorts) targeted advertising. - Email address is now returned if requesting user is the owner of the user account so it can be exposed in client and FE user settings UIs. diff --git a/config/config.exs b/config/config.exs index d333c618e..8c8ed5224 100644 --- a/config/config.exs +++ b/config/config.exs @@ -190,7 +190,7 @@ config :pleroma, :instance, instance_thumbnail: "/instance/thumbnail.jpeg", limit: 5_000, description_limit: 5_000, - chat_limit: 5_000, + shout_limit: 5_000, remote_limit: 100_000, upload_limit: 16_000_000, avatar_upload_limit: 2_000_000, @@ -457,7 +457,7 @@ config :pleroma, :media_preview_proxy, image_quality: 85, min_content_length: 100 * 1024 -config :pleroma, :chat, enabled: true +config :pleroma, :shoutbox, enabled: true config :phoenix, :format_encoders, json: Jason diff --git a/config/description.exs b/config/description.exs index f00c53d28..040deab96 100644 --- a/config/description.exs +++ b/config/description.exs @@ -545,9 +545,9 @@ config :pleroma, :config_description, [ ] }, %{ - key: :chat_limit, + key: :shout_limit, type: :integer, - description: "Character limit of the instance chat messages", + description: "Character limit of the instance shout messages", suggestions: [ 5_000 ] @@ -2652,9 +2652,9 @@ config :pleroma, :config_description, [ }, %{ group: :pleroma, - key: :chat, + key: :shout, type: :group, - description: "Pleroma chat settings", + description: "Pleroma shout settings", children: [ %{ key: :enabled, diff --git a/lib/pleroma/config/transfer_task.ex b/lib/pleroma/config/transfer_task.ex index 1e3ae82d0..d5c6081a2 100644 --- a/lib/pleroma/config/transfer_task.ex +++ b/lib/pleroma/config/transfer_task.ex @@ -16,7 +16,7 @@ defmodule Pleroma.Config.TransferTask do defp reboot_time_keys, do: [ {:pleroma, :hackney_pools}, - {:pleroma, :chat}, + {:pleroma, :shout}, {:pleroma, Oban}, {:pleroma, :rate_limit}, {:pleroma, :markup}, diff --git a/lib/pleroma/web/channels/user_socket.ex b/lib/pleroma/web/channels/user_socket.ex index 1c09b6768..130809bb7 100644 --- a/lib/pleroma/web/channels/user_socket.ex +++ b/lib/pleroma/web/channels/user_socket.ex @@ -8,7 +8,7 @@ defmodule Pleroma.Web.UserSocket do ## Channels # channel "room:*", Pleroma.Web.RoomChannel - channel("chat:*", Pleroma.Web.ChatChannel) + channel("shout:*", Pleroma.Web.ShoutChannel) # Socket params are passed from the client and can # be used to verify and authenticate a user. After @@ -22,7 +22,7 @@ defmodule Pleroma.Web.UserSocket do # See `Phoenix.Token` documentation for examples in # performing token verification on connect. def connect(%{"token" => token}, socket) do - with true <- Pleroma.Config.get([:chat, :enabled]), + 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)} diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index 005705d97..75964f176 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -37,7 +37,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView 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), - chat_limit: Keyword.get(instance, :chat_limit), + shout_limit: Keyword.get(instance, :shout_limit), description_limit: Keyword.get(instance, :description_limit), pleroma: %{ metadata: %{ @@ -69,8 +69,8 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do if Config.get([:gopher, :enabled]) do "gopher" end, - if Config.get([:chat, :enabled]) do - "chat" + if Config.get([:shout, :enabled]) do + "shout" end, if Config.get([:instance, :allow_relay]) do "relay" diff --git a/lib/pleroma/web/chat_channel.ex b/lib/pleroma/web/shout_channel.ex similarity index 78% rename from lib/pleroma/web/chat_channel.ex rename to lib/pleroma/web/shout_channel.ex index 4008129e9..1d97858d6 100644 --- a/lib/pleroma/web/chat_channel.ex +++ b/lib/pleroma/web/shout_channel.ex @@ -2,31 +2,31 @@ # Copyright © 2017-2021 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Web.ChatChannel do +defmodule Pleroma.Web.ShoutChannel do use Phoenix.Channel alias Pleroma.User - alias Pleroma.Web.ChatChannel.ChatChannelState alias Pleroma.Web.MastodonAPI.AccountView + alias Pleroma.Web.ShoutChannel.ShoutChannelState - def join("chat:public", _message, socket) do + def join("shout:public", _message, socket) do send(self(), :after_join) {:ok, socket} end def handle_info(:after_join, socket) do - push(socket, "messages", %{messages: ChatChannelState.messages()}) + 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([:instance, :chat_limit]) do + if String.length(text) in 1..Pleroma.Config.get([:instance, :shout_limit]) do author = User.get_cached_by_nickname(user_name) author_json = AccountView.render("show.json", user: author, skip_visibility_check: true) - message = ChatChannelState.add_message(%{text: text, author: author_json}) + message = ShoutChannelState.add_message(%{text: text, author: author_json}) broadcast!(socket, "new_msg", message) end @@ -35,7 +35,7 @@ defmodule Pleroma.Web.ChatChannel do end end -defmodule Pleroma.Web.ChatChannel.ChatChannelState do +defmodule Pleroma.Web.ShoutChannel.ShoutChannelState do use Agent @max_messages 20 diff --git a/test/pleroma/config/transfer_task_test.exs b/test/pleroma/config/transfer_task_test.exs index 8ae5d3b81..7d51fd84c 100644 --- a/test/pleroma/config/transfer_task_test.exs +++ b/test/pleroma/config/transfer_task_test.exs @@ -93,8 +93,8 @@ defmodule Pleroma.Config.TransferTaskTest do end test "on reboot time key" do - clear_config(:chat) - insert(:config, key: :chat, value: [enabled: false]) + clear_config(:shout) + insert(:config, key: :shout, value: [enabled: false]) assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted" end @@ -105,10 +105,10 @@ defmodule Pleroma.Config.TransferTaskTest do end test "don't restart pleroma on reboot time key and subkey if there is false flag" do - clear_config(:chat) + clear_config(:shout) clear_config(Pleroma.Captcha) - insert(:config, key: :chat, value: [enabled: false]) + insert(:config, key: :shout, value: [enabled: false]) insert(:config, key: Pleroma.Captcha, value: [seconds_valid: 60]) refute String.contains?( diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs index c39c1b1e1..d8ca07cd3 100644 --- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs @@ -409,7 +409,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do end test "saving config which need pleroma reboot", %{conn: conn} do - clear_config([:chat, :enabled], true) + clear_config([:shout, :enabled], true) assert conn |> put_req_header("content-type", "application/json") @@ -417,7 +417,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do "/api/pleroma/admin/config", %{ configs: [ - %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]} + %{group: ":pleroma", key: ":shout", value: [%{"tuple" => [":enabled", true]}]} ] } ) @@ -426,7 +426,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do %{ "db" => [":enabled"], "group" => ":pleroma", - "key" => ":chat", + "key" => ":shout", "value" => [%{"tuple" => [":enabled", true]}] } ], @@ -454,7 +454,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do end test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do - clear_config([:chat, :enabled], true) + clear_config([:shout, :enabled], true) assert conn |> put_req_header("content-type", "application/json") @@ -462,7 +462,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do "/api/pleroma/admin/config", %{ configs: [ - %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]} + %{group: ":pleroma", key: ":shout", value: [%{"tuple" => [":enabled", true]}]} ] } ) @@ -471,7 +471,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do %{ "db" => [":enabled"], "group" => ":pleroma", - "key" => ":chat", + "key" => ":shout", "value" => [%{"tuple" => [":enabled", true]}] } ], diff --git a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs index f137743be..e76cbc75b 100644 --- a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs @@ -38,7 +38,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do "background_upload_limit" => _, "banner_upload_limit" => _, "background_image" => from_config_background, - "chat_limit" => _, + "shout_limit" => _, "description_limit" => _ } = result diff --git a/test/pleroma/web/chat_channel_test.exs b/test/pleroma/web/shout_channel_test.ex similarity index 80% rename from test/pleroma/web/chat_channel_test.exs rename to test/pleroma/web/shout_channel_test.ex index 29999701c..ba6730ceb 100644 --- a/test/pleroma/web/chat_channel_test.exs +++ b/test/pleroma/web/shout_channel_test.ex @@ -2,9 +2,9 @@ # Copyright © 2017-2021 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Web.ChatChannelTest do +defmodule Pleroma.Web.ShoutChannelTest do use Pleroma.Web.ChannelCase - alias Pleroma.Web.ChatChannel + alias Pleroma.Web.ShoutChannel alias Pleroma.Web.UserSocket import Pleroma.Factory @@ -14,7 +14,7 @@ defmodule Pleroma.Web.ChatChannelTest do {:ok, _, socket} = socket(UserSocket, "", %{user_name: user.nickname}) - |> subscribe_and_join(ChatChannel, "chat:public") + |> subscribe_and_join(ShoutChannel, "shout:public") {:ok, socket: socket} end @@ -25,7 +25,7 @@ defmodule Pleroma.Web.ChatChannelTest do end describe "message lengths" do - setup do: clear_config([:instance, :chat_limit]) + setup do: clear_config([:instance, :shout_limit]) test "it ignores messages of length zero", %{socket: socket} do push(socket, "new_msg", %{"text" => ""}) @@ -33,7 +33,7 @@ defmodule Pleroma.Web.ChatChannelTest do end test "it ignores messages above a certain length", %{socket: socket} do - clear_config([:instance, :chat_limit], 2) + Pleroma.Config.put([:instance, :shout_limit], 2) push(socket, "new_msg", %{"text" => "123"}) refute_broadcast("new_msg", %{text: "123"}) end From 68aa56b9e4fbf4697d5ff0c41cf2fe7230738fe6 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 3 Aug 2020 17:58:27 -0500 Subject: [PATCH 02/16] Just call it shout --- config/config.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index 8c8ed5224..e2bf0cfc1 100644 --- a/config/config.exs +++ b/config/config.exs @@ -457,7 +457,7 @@ config :pleroma, :media_preview_proxy, image_quality: 85, min_content_length: 100 * 1024 -config :pleroma, :shoutbox, enabled: true +config :pleroma, :shout, enabled: true config :phoenix, :format_encoders, json: Jason From 36fe8950f78b32e4ae8b845c099498a9acda7183 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 3 Aug 2020 18:00:16 -0500 Subject: [PATCH 03/16] Update PleromaFE settings for the old chat box --- config/description.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/description.exs b/config/description.exs index 040deab96..a17d222ce 100644 --- a/config/description.exs +++ b/config/description.exs @@ -1182,7 +1182,7 @@ config :pleroma, :config_description, [ alwaysShowSubjectInput: true, background: "/static/aurora_borealis.jpg", collapseMessageWithSubject: false, - disableChat: false, + disableShout: false, greentext: false, hideFilteredStatuses: false, hideMutedPosts: false, @@ -1230,10 +1230,10 @@ config :pleroma, :config_description, [ "When a message has a subject (aka Content Warning), collapse it by default" }, %{ - key: :disableChat, - label: "PleromaFE Chat", + key: :disableShout, + label: "PleromaFE Shout", type: :boolean, - description: "Disables PleromaFE Chat component" + description: "Disables PleromaFE Shout component" }, %{ key: :greentext, From a3cff596592ae70701afae2e293eab03fe5408df Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 3 Aug 2020 18:34:58 -0500 Subject: [PATCH 04/16] Ensure we actually start ShoutChannel --- lib/pleroma/application.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index f4d22373a..afb8cfb8a 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -239,7 +239,7 @@ defmodule Pleroma.Application do defp chat_child(true) do [ - Pleroma.Web.ChatChannel.ChatChannelState, + Pleroma.Web.ShoutChannel.ShoutChannelState, {Phoenix.PubSub, [name: Pleroma.PubSub, adapter: Phoenix.PubSub.PG2]} ] end From 4a181982c34c774c9ed4b76ce1d95f6c33fce9d5 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 3 Aug 2020 18:41:49 -0500 Subject: [PATCH 05/16] More confusingly named legacy chat code renamed to shout --- lib/pleroma/application.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index afb8cfb8a..9824e0a4a 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -102,7 +102,7 @@ defmodule Pleroma.Application do ] ++ task_children(@mix_env) ++ dont_run_in_test(@mix_env) ++ - chat_child(chat_enabled?()) ++ + shout_child(shout_enabled?()) ++ [Pleroma.Gopher.Server] # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html @@ -216,7 +216,7 @@ defmodule Pleroma.Application do type: :worker } - defp chat_enabled?, do: Config.get([:chat, :enabled]) + defp shout_enabled?, do: Config.get([:shout, :enabled]) defp dont_run_in_test(env) when env in [:test, :benchmark], do: [] @@ -237,14 +237,14 @@ defmodule Pleroma.Application do ] end - defp chat_child(true) do + defp shout_child(true) do [ Pleroma.Web.ShoutChannel.ShoutChannelState, {Phoenix.PubSub, [name: Pleroma.PubSub, adapter: Phoenix.PubSub.PG2]} ] end - defp chat_child(_), do: [] + defp shout_child(_), do: [] defp task_children(:test) do [ From d6432a65da7ad11f1383d465370c11de5a2d7ddc Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 4 Aug 2020 10:42:52 -0500 Subject: [PATCH 06/16] Move shout configuration from :instance, update docs and changelog --- CHANGELOG.md | 2 +- config/config.exs | 5 +++-- docs/configuration/cheatsheet.md | 6 +++--- lib/pleroma/web/mastodon_api/views/instance_view.ex | 2 +- lib/pleroma/web/shout_channel.ex | 2 +- test/pleroma/web/shout_channel_test.ex | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c08710a3..6e27c4561 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed -- **Breaking:** Configuration: `:chat, enabled` moved to `:shout, enabled` and `:instance, chat_limit` moved to `:instance, shout_limit` +- **Breaking:** Configuration: `:chat, enabled` moved to `:shout, enabled` and `:instance, chat_limit` moved to `:shout, limit` - The `application` metadata returned with statuses is no longer hardcoded. Apps that want to display these details will now have valid data for new posts after this change. - HTTPSecurityPlug now sends a response header to opt out of Google's FLoC (Federated Learning of Cohorts) targeted advertising. - Email address is now returned if requesting user is the owner of the user account so it can be exposed in client and FE user settings UIs. diff --git a/config/config.exs b/config/config.exs index e2bf0cfc1..2f8a18788 100644 --- a/config/config.exs +++ b/config/config.exs @@ -190,7 +190,6 @@ config :pleroma, :instance, instance_thumbnail: "/instance/thumbnail.jpeg", limit: 5_000, description_limit: 5_000, - shout_limit: 5_000, remote_limit: 100_000, upload_limit: 16_000_000, avatar_upload_limit: 2_000_000, @@ -457,7 +456,9 @@ config :pleroma, :media_preview_proxy, image_quality: 85, min_content_length: 100 * 1024 -config :pleroma, :shout, enabled: true +config :pleroma, :shout, + enabled: true, + limit: 5_000 config :phoenix, :format_encoders, json: Jason diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md index 069421722..4e20309a1 100644 --- a/docs/configuration/cheatsheet.md +++ b/docs/configuration/cheatsheet.md @@ -8,9 +8,10 @@ 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. -## :chat +## :shout -* `enabled` - Enables the backend chat. Defaults to `true`. +* `enabled` - Enables the backend Shoutbox chat feature. Defaults to `true`. +* `limit` - Shout character limit. Defaults to `5_000` ## :instance * `name`: The instance’s name. @@ -19,7 +20,6 @@ To add configuration to your config file, you can copy it from the base config. * `description`: The instance’s description, can be seen in nodeinfo and ``/api/v1/instance``. * `limit`: Posts character limit (CW/Subject included in the counter). * `description_limit`: The character limit for image descriptions. -* `chat_limit`: Character limit of the instance chat messages. * `remote_limit`: Hard character limit beyond which remote posts will be dropped. * `upload_limit`: File size limit of uploads (except for avatar, background, banner). * `avatar_upload_limit`: File size limit of user’s profile avatars. diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index 75964f176..fcb4e2466 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -37,7 +37,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView 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: Keyword.get(instance, :shout_limit), + shout_limit: Config.get([:shout, :limit]), description_limit: Keyword.get(instance, :description_limit), pleroma: %{ metadata: %{ diff --git a/lib/pleroma/web/shout_channel.ex b/lib/pleroma/web/shout_channel.ex index 1d97858d6..dc342fdfb 100644 --- a/lib/pleroma/web/shout_channel.ex +++ b/lib/pleroma/web/shout_channel.ex @@ -22,7 +22,7 @@ defmodule Pleroma.Web.ShoutChannel do 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([:instance, :shout_limit]) do + 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) diff --git a/test/pleroma/web/shout_channel_test.ex b/test/pleroma/web/shout_channel_test.ex index ba6730ceb..b4d661689 100644 --- a/test/pleroma/web/shout_channel_test.ex +++ b/test/pleroma/web/shout_channel_test.ex @@ -25,7 +25,7 @@ defmodule Pleroma.Web.ShoutChannelTest do end describe "message lengths" do - setup do: clear_config([:instance, :shout_limit]) + setup do: clear_config([:shout, :limit]) test "it ignores messages of length zero", %{socket: socket} do push(socket, "new_msg", %{"text" => ""}) @@ -33,7 +33,7 @@ defmodule Pleroma.Web.ShoutChannelTest do end test "it ignores messages above a certain length", %{socket: socket} do - Pleroma.Config.put([:instance, :shout_limit], 2) + Pleroma.Config.put([:shout, :limit], 2) push(socket, "new_msg", %{"text" => "123"}) refute_broadcast("new_msg", %{text: "123"}) end From 8ff2d8d17d057d5a2e0f5df603812155d6985df0 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 4 Aug 2020 10:45:28 -0500 Subject: [PATCH 07/16] Update description file for new shout config setting location --- config/description.exs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/config/description.exs b/config/description.exs index a17d222ce..7eecddaf5 100644 --- a/config/description.exs +++ b/config/description.exs @@ -545,14 +545,6 @@ config :pleroma, :config_description, [ ] }, %{ - key: :shout_limit, - type: :integer, - description: "Character limit of the instance shout messages", - suggestions: [ - 5_000 - ] - }, - %{ key: :remote_limit, type: :integer, description: "Hard character limit beyond which remote posts will be dropped", @@ -2658,7 +2650,16 @@ config :pleroma, :config_description, [ children: [ %{ key: :enabled, - type: :boolean + type: :boolean, + description: "Enables the backend Shoutbox chat feature." + }, + %{ + key: :limit, + type: :integer, + description: "Shout message character limit.", + suggestions: [ + 5_000 + ] } ] }, From 01f796f8bbe98b2f004941d0a449035be6555c26 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 6 Aug 2020 16:37:17 -0500 Subject: [PATCH 08/16] Add a test for the migration --- .../20200806175913_rename_instance_chat_test.exs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/migrations/20200806175913_rename_instance_chat_test.exs diff --git a/test/migrations/20200806175913_rename_instance_chat_test.exs b/test/migrations/20200806175913_rename_instance_chat_test.exs new file mode 100644 index 000000000..66341bd84 --- /dev/null +++ b/test/migrations/20200806175913_rename_instance_chat_test.exs @@ -0,0 +1,21 @@ +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") + + test "up/0 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"]) + + migration.up() + + assert nil == ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) + + assert %{value: [limit: 6000, enabled: true]} == ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) + end +end From e0bb6557739b9662bc7da785d060e302c4c61d61 Mon Sep 17 00:00:00 2001 From: Roman Chvanikov Date: Fri, 7 Aug 2020 12:18:36 +0300 Subject: [PATCH 09/16] Add RenameInstanceChat migration --- .../20200806175913_rename_instance_chat.exs | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 priv/repo/migrations/20200806175913_rename_instance_chat.exs diff --git a/priv/repo/migrations/20200806175913_rename_instance_chat.exs b/priv/repo/migrations/20200806175913_rename_instance_chat.exs new file mode 100644 index 000000000..31585efe8 --- /dev/null +++ b/priv/repo/migrations/20200806175913_rename_instance_chat.exs @@ -0,0 +1,77 @@ +defmodule Pleroma.Repo.Migrations.RenameInstanceChat do + use Ecto.Migration + + 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 +end From d7dfa6d27cf140b9d0faed32c3a7a659a0f2e20e Mon Sep 17 00:00:00 2001 From: Roman Chvanikov Date: Fri, 7 Aug 2020 12:18:55 +0300 Subject: [PATCH 10/16] Update test for RenameInstanceChat migration --- .../20200806175913_rename_instance_chat_test.exs | 43 +++++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/test/migrations/20200806175913_rename_instance_chat_test.exs b/test/migrations/20200806175913_rename_instance_chat_test.exs index 66341bd84..acd45600c 100644 --- a/test/migrations/20200806175913_rename_instance_chat_test.exs +++ b/test/migrations/20200806175913_rename_instance_chat_test.exs @@ -8,14 +8,45 @@ defmodule Pleroma.Repo.Migrations.RenameInstanceChatTest do setup do: clear_config([:chat]) setup_all do: require_migration("20200806175913_rename_instance_chat") - test "up/0 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"]) + 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]) - migration.up() + assert migration.up() == :ok - assert nil == ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) + assert ConfigDB.get_by_params(%{group: :pleroma, key: :chat}) == nil + assert ConfigDB.get_by_params(%{group: :pleroma, key: :instance}) == nil - assert %{value: [limit: 6000, enabled: true]} == ConfigDB.get_by_params(%{group: :pleroma, key: :shout}) + 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 From 9ce2c017c0782c9ea4a0ca6009e82d034ac7915c Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 20 May 2021 14:30:29 -0500 Subject: [PATCH 11/16] We want clear_config/2 in all tests now --- test/pleroma/web/shout_channel_test.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pleroma/web/shout_channel_test.ex b/test/pleroma/web/shout_channel_test.ex index b4d661689..a266543d2 100644 --- a/test/pleroma/web/shout_channel_test.ex +++ b/test/pleroma/web/shout_channel_test.ex @@ -33,7 +33,7 @@ defmodule Pleroma.Web.ShoutChannelTest do end test "it ignores messages above a certain length", %{socket: socket} do - Pleroma.Config.put([:shout, :limit], 2) + clear_config([:shout, :limit], 2) push(socket, "new_msg", %{"text" => "123"}) refute_broadcast("new_msg", %{text: "123"}) end From d9513b11d3c18c4d30cdcab700bb5ed39b3356ea Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 28 May 2021 14:10:37 -0500 Subject: [PATCH 12/16] Forgot to move migration test when rebasing --- .../repo/migrations/rename_instance_chat_test.exs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{migrations/20200806175913_rename_instance_chat_test.exs => pleroma/repo/migrations/rename_instance_chat_test.exs} (100%) diff --git a/test/migrations/20200806175913_rename_instance_chat_test.exs b/test/pleroma/repo/migrations/rename_instance_chat_test.exs similarity index 100% rename from test/migrations/20200806175913_rename_instance_chat_test.exs rename to test/pleroma/repo/migrations/rename_instance_chat_test.exs From 48a0ea2fc342c9a757222b0755a0cad9b725bdc7 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 1 Jun 2021 11:55:51 -0500 Subject: [PATCH 13/16] Wire up join requests to the old "chat:public" channel into the new "shout:public" channel --- lib/pleroma/web/shout_channel.ex | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/pleroma/web/shout_channel.ex b/lib/pleroma/web/shout_channel.ex index dc342fdfb..70d9cc1e1 100644 --- a/lib/pleroma/web/shout_channel.ex +++ b/lib/pleroma/web/shout_channel.ex @@ -9,6 +9,9 @@ defmodule Pleroma.Web.ShoutChannel do alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.ShoutChannel.ShoutChannelState + # Backwards compatibility + def join("chat:public", message, socket), do: join("shout:public", message, socket) + def join("shout:public", _message, socket) do send(self(), :after_join) {:ok, socket} From 2743c6669311ecb9a985a959dfd28b7aeed8783a Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 1 Jun 2021 12:57:18 -0500 Subject: [PATCH 14/16] Add "chat" back as a feature for backwards compat. Legacy PleromaFE uses this to identify if ShoutBox is available. --- lib/pleroma/web/mastodon_api/views/instance_view.ex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index fcb4e2466..3528185d5 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -69,6 +69,10 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView 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, From 0be7eada92d862277c3bf349ca5a3079ebacb700 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 1 Jun 2021 14:34:13 -0500 Subject: [PATCH 15/16] Keep original Shoutbox channel name as chat:public There is no sane / high level workaround for merging users who join shout:public and chat:public. --- lib/pleroma/web/channels/user_socket.ex | 2 +- lib/pleroma/web/shout_channel.ex | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/channels/user_socket.ex b/lib/pleroma/web/channels/user_socket.ex index 130809bb7..043206835 100644 --- a/lib/pleroma/web/channels/user_socket.ex +++ b/lib/pleroma/web/channels/user_socket.ex @@ -8,7 +8,7 @@ defmodule Pleroma.Web.UserSocket do ## Channels # channel "room:*", Pleroma.Web.RoomChannel - channel("shout:*", Pleroma.Web.ShoutChannel) + channel("chat:*", Pleroma.Web.ShoutChannel) # Socket params are passed from the client and can # be used to verify and authenticate a user. After diff --git a/lib/pleroma/web/shout_channel.ex b/lib/pleroma/web/shout_channel.ex index 70d9cc1e1..17caecb1a 100644 --- a/lib/pleroma/web/shout_channel.ex +++ b/lib/pleroma/web/shout_channel.ex @@ -9,10 +9,7 @@ defmodule Pleroma.Web.ShoutChannel do alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.ShoutChannel.ShoutChannelState - # Backwards compatibility - def join("chat:public", message, socket), do: join("shout:public", message, socket) - - def join("shout:public", _message, socket) do + def join("chat:public", _message, socket) do send(self(), :after_join) {:ok, socket} end From dcf84ac12e830ebc17f63e2fea0bd47c75e9f981 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 1 Jun 2021 16:53:32 -0500 Subject: [PATCH 16/16] disableChat / disableShout didn't actually do anything for PleromaFE --- config/description.exs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/config/description.exs b/config/description.exs index 7eecddaf5..c93a00782 100644 --- a/config/description.exs +++ b/config/description.exs @@ -1174,7 +1174,6 @@ config :pleroma, :config_description, [ alwaysShowSubjectInput: true, background: "/static/aurora_borealis.jpg", collapseMessageWithSubject: false, - disableShout: false, greentext: false, hideFilteredStatuses: false, hideMutedPosts: false, @@ -1222,12 +1221,6 @@ config :pleroma, :config_description, [ "When a message has a subject (aka Content Warning), collapse it by default" }, %{ - key: :disableShout, - label: "PleromaFE Shout", - type: :boolean, - description: "Disables PleromaFE Shout component" - }, - %{ key: :greentext, label: "Greentext", type: :boolean,