2019-07-10 07:13:23 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 23:44:49 +01:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-07-10 07:13:23 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-02-16 16:42:34 +01:00
|
|
|
defmodule Pleroma.User.WelcomeMessage do
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
def post_welcome_message_to_user(user) do
|
|
|
|
with %User{} = sender_user <- welcome_user(),
|
|
|
|
message when is_binary(message) <- welcome_message() do
|
|
|
|
CommonAPI.post(sender_user, %{
|
2020-05-12 21:59:26 +02:00
|
|
|
visibility: "direct",
|
|
|
|
status: "@#{user.nickname}\n#{message}"
|
2019-02-16 16:42:34 +01:00
|
|
|
})
|
|
|
|
else
|
|
|
|
_ -> {:ok, nil}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-05 04:18:43 +01:00
|
|
|
defp welcome_user do
|
2019-02-16 17:24:48 +01:00
|
|
|
with nickname when is_binary(nickname) <-
|
|
|
|
Pleroma.Config.get([:instance, :welcome_user_nickname]),
|
|
|
|
%User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
|
|
|
user
|
2019-02-16 16:42:34 +01:00
|
|
|
else
|
2019-02-16 17:24:48 +01:00
|
|
|
_ -> nil
|
2019-02-16 16:42:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-05 04:18:43 +01:00
|
|
|
defp welcome_message do
|
2019-02-16 16:42:34 +01:00
|
|
|
Pleroma.Config.get([:instance, :welcome_message])
|
|
|
|
end
|
|
|
|
end
|