Browse Source

Merge branch 'chore/rename-chat' into 'develop'

Rename the non-federating Chat feature to Shout

See merge request pleroma/pleroma!2842
cycles-validator
Haelwenn 2 years ago
parent
commit
a5dce42c85
15 changed files with 184 additions and 55 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +3
    -2
      config/config.exs
  3. +12
    -18
      config/description.exs
  4. +3
    -3
      docs/configuration/cheatsheet.md
  5. +5
    -5
      lib/pleroma/application.ex
  6. +1
    -1
      lib/pleroma/config/transfer_task.ex
  7. +2
    -2
      lib/pleroma/web/channels/user_socket.ex
  8. +6
    -2
      lib/pleroma/web/mastodon_api/views/instance_view.ex
  9. +6
    -6
      lib/pleroma/web/shout_channel.ex
  10. +77
    -0
      priv/repo/migrations/20200806175913_rename_instance_chat.exs
  11. +4
    -4
      test/pleroma/config/transfer_task_test.exs
  12. +52
    -0
      test/pleroma/repo/migrations/rename_instance_chat_test.exs
  13. +6
    -6
      test/pleroma/web/admin_api/controllers/config_controller_test.exs
  14. +1
    -1
      test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs
  15. +5
    -5
      test/pleroma/web/shout_channel_test.ex

+ 1
- 0
CHANGELOG.md View File

@@ -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 `: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.


+ 3
- 2
config/config.exs View File

@@ -190,7 +190,6 @@ config :pleroma, :instance,
instance_thumbnail: "/instance/thumbnail.jpeg",
limit: 5_000,
description_limit: 5_000,
chat_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, :chat, enabled: true
config :pleroma, :shout,
enabled: true,
limit: 5_000

config :phoenix, :format_encoders, json: Jason



+ 12
- 18
config/description.exs View File

@@ -545,14 +545,6 @@ config :pleroma, :config_description, [
]
},
%{
key: :chat_limit,
type: :integer,
description: "Character limit of the instance chat messages",
suggestions: [
5_000
]
},
%{
key: :remote_limit,
type: :integer,
description: "Hard character limit beyond which remote posts will be dropped",
@@ -1183,7 +1175,6 @@ config :pleroma, :config_description, [
alwaysShowSubjectInput: true,
background: "/static/aurora_borealis.jpg",
collapseMessageWithSubject: false,
disableChat: false,
greentext: false,
hideFilteredStatuses: false,
hideMutedPosts: false,
@@ -1231,12 +1222,6 @@ config :pleroma, :config_description, [
"When a message has a subject (aka Content Warning), collapse it by default"
},
%{
key: :disableChat,
label: "PleromaFE Chat",
type: :boolean,
description: "Disables PleromaFE Chat component"
},
%{
key: :greentext,
label: "Greentext",
type: :boolean,
@@ -2653,13 +2638,22 @@ config :pleroma, :config_description, [
},
%{
group: :pleroma,
key: :chat,
key: :shout,
type: :group,
description: "Pleroma chat settings",
description: "Pleroma shout settings",
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
]
}
]
},


+ 3
- 3
docs/configuration/cheatsheet.md View File

@@ -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.


+ 5
- 5
lib/pleroma/application.ex View File

@@ -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.ChatChannel.ChatChannelState,
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
[


+ 1
- 1
lib/pleroma/config/transfer_task.ex View File

@@ -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},


+ 2
- 2
lib/pleroma/web/channels/user_socket.ex View File

@@ -8,7 +8,7 @@ defmodule Pleroma.Web.UserSocket do

## Channels
# channel "room:*", Pleroma.Web.RoomChannel
channel("chat:*", Pleroma.Web.ChatChannel)
channel("chat:*", 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)}


+ 6
- 2
lib/pleroma/web/mastodon_api/views/instance_view.ex View File

@@ -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: Config.get([:shout, :limit]),
description_limit: Keyword.get(instance, :description_limit),
pleroma: %{
metadata: %{
@@ -69,9 +69,13 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
if Config.get([:gopher, :enabled]) do
"gopher"
end,
if Config.get([:chat, :enabled]) do
# 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,


lib/pleroma/web/chat_channel.ex → lib/pleroma/web/shout_channel.ex View File

@@ -2,12 +2,12 @@
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# 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
send(self(), :after_join)
@@ -15,18 +15,18 @@ defmodule Pleroma.Web.ChatChannel do
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([: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

+ 77
- 0
priv/repo/migrations/20200806175913_rename_instance_chat.exs View File

@@ -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

+ 4
- 4
test/pleroma/config/transfer_task_test.exs View File

@@ -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?(


+ 52
- 0
test/pleroma/repo/migrations/rename_instance_chat_test.exs View File

@@ -0,0 +1,52 @@
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

+ 6
- 6
test/pleroma/web/admin_api/controllers/config_controller_test.exs View File

@@ -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]}]
}
],


+ 1
- 1
test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs View File

@@ -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



test/pleroma/web/chat_channel_test.exs → test/pleroma/web/shout_channel_test.ex View File

@@ -2,9 +2,9 @@
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# 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([: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)
clear_config([:shout, :limit], 2)
push(socket, "new_msg", %{"text" => "123"})
refute_broadcast("new_msg", %{text: "123"})
end

Loading…
Cancel
Save