1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Repo.Migrations.RenameInstanceChat do
10 @instance_params %{group: :pleroma, key: :instance}
11 @shout_params %{group: :pleroma, key: :shout}
12 @chat_params %{group: :pleroma, key: :chat}
15 instance_updated? = maybe_update_instance_key(:up) != :noop
16 chat_updated? = maybe_update_chat_key(:up) != :noop
18 case Enum.any?([instance_updated?, chat_updated?]) do
25 instance_updated? = maybe_update_instance_key(:down) != :noop
26 chat_updated? = maybe_update_chat_key(:down) != :noop
28 case Enum.any?([instance_updated?, chat_updated?]) do
34 # pleroma.instance.chat_limit -> pleroma.shout.limit
35 defp maybe_update_instance_key(:up) do
36 with %ConfigDB{value: values} <- ConfigDB.get_by_params(@instance_params),
37 limit when is_integer(limit) <- values[:chat_limit] do
38 @shout_params |> Map.put(:value, limit: limit) |> ConfigDB.update_or_create()
39 @instance_params |> Map.put(:subkeys, [":chat_limit"]) |> ConfigDB.delete()
46 # pleroma.shout.limit -> pleroma.instance.chat_limit
47 defp maybe_update_instance_key(:down) do
48 with %ConfigDB{value: values} <- ConfigDB.get_by_params(@shout_params),
49 limit when is_integer(limit) <- values[:limit] do
50 @instance_params |> Map.put(:value, chat_limit: limit) |> ConfigDB.update_or_create()
51 @shout_params |> Map.put(:subkeys, [":limit"]) |> ConfigDB.delete()
58 # pleroma.chat.enabled -> pleroma.shout.enabled
59 defp maybe_update_chat_key(:up) do
60 with %ConfigDB{value: values} <- ConfigDB.get_by_params(@chat_params),
61 enabled? when is_boolean(enabled?) <- values[:enabled] do
62 @shout_params |> Map.put(:value, enabled: enabled?) |> ConfigDB.update_or_create()
63 @chat_params |> Map.put(:subkeys, [":enabled"]) |> ConfigDB.delete()
70 # pleroma.shout.enabled -> pleroma.chat.enabled
71 defp maybe_update_chat_key(:down) do
72 with %ConfigDB{value: values} <- ConfigDB.get_by_params(@shout_params),
73 enabled? when is_boolean(enabled?) <- values[:enabled] do
74 @chat_params |> Map.put(:value, enabled: enabled?) |> ConfigDB.update_or_create()
75 @shout_params |> Map.put(:subkeys, [":enabled"]) |> ConfigDB.delete()