2020-10-12 17:00:50 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-10-30 19:59:04 +00:00
|
|
|
defmodule Mix.Tasks.Pleroma.NotificationSettings do
|
|
|
|
@shortdoc "Enable&Disable privacy option for push notifications"
|
|
|
|
@moduledoc """
|
|
|
|
Example:
|
|
|
|
|
2020-06-26 17:45:46 +00:00
|
|
|
> mix pleroma.notification_settings --hide-notification-contents=false --nickname-users="parallel588" # set false only for parallel588 user
|
|
|
|
> mix pleroma.notification_settings --hide-notification-contents=true # set true for all users
|
2019-10-30 19:59:04 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
use Mix.Task
|
|
|
|
import Mix.Pleroma
|
|
|
|
import Ecto.Query
|
|
|
|
|
|
|
|
def run(args) do
|
|
|
|
start_pleroma()
|
|
|
|
|
|
|
|
{options, _, _} =
|
|
|
|
OptionParser.parse(
|
|
|
|
args,
|
|
|
|
strict: [
|
2020-06-26 17:45:46 +00:00
|
|
|
hide_notification_contents: :boolean,
|
2019-10-30 19:59:04 +00:00
|
|
|
email_users: :string,
|
|
|
|
nickname_users: :string
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2020-06-26 17:45:46 +00:00
|
|
|
hide_notification_contents = Keyword.get(options, :hide_notification_contents)
|
2019-10-30 19:59:04 +00:00
|
|
|
|
2020-06-26 17:45:46 +00:00
|
|
|
if not is_nil(hide_notification_contents) do
|
|
|
|
hide_notification_contents
|
2019-10-30 19:59:04 +00:00
|
|
|
|> build_query(options)
|
|
|
|
|> Pleroma.Repo.update_all([])
|
|
|
|
end
|
|
|
|
|
|
|
|
shell_info("Done")
|
|
|
|
end
|
|
|
|
|
2020-06-26 17:45:46 +00:00
|
|
|
defp build_query(hide_notification_contents, options) do
|
2019-10-30 19:59:04 +00:00
|
|
|
query =
|
|
|
|
from(u in Pleroma.User,
|
|
|
|
update: [
|
|
|
|
set: [
|
|
|
|
notification_settings:
|
|
|
|
fragment(
|
2020-06-26 17:45:46 +00:00
|
|
|
"jsonb_set(notification_settings, '{hide_notification_contents}', ?)",
|
|
|
|
^hide_notification_contents
|
2019-10-30 19:59:04 +00:00
|
|
|
)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
user_emails =
|
|
|
|
options
|
|
|
|
|> Keyword.get(:email_users, "")
|
|
|
|
|> String.split(",")
|
|
|
|
|> Enum.map(&String.trim(&1))
|
|
|
|
|> Enum.reject(&(&1 == ""))
|
|
|
|
|
|
|
|
query =
|
|
|
|
if length(user_emails) > 0 do
|
|
|
|
where(query, [u], u.email in ^user_emails)
|
|
|
|
else
|
|
|
|
query
|
|
|
|
end
|
|
|
|
|
|
|
|
user_nicknames =
|
|
|
|
options
|
|
|
|
|> Keyword.get(:nickname_users, "")
|
|
|
|
|> String.split(",")
|
|
|
|
|> Enum.map(&String.trim(&1))
|
|
|
|
|> Enum.reject(&(&1 == ""))
|
|
|
|
|
|
|
|
query =
|
|
|
|
if length(user_nicknames) > 0 do
|
|
|
|
where(query, [u], u.nickname in ^user_nicknames)
|
|
|
|
else
|
|
|
|
query
|
|
|
|
end
|
|
|
|
|
|
|
|
query
|
|
|
|
end
|
|
|
|
end
|