f8f52028595b7128a864bc611b90454920782bb1
[akkoma] / lib / pleroma / user / welcome_message.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.User.WelcomeMessage do
6 alias Pleroma.User
7 alias Pleroma.Web.CommonAPI
8
9 def post_welcome_message_to_user(user) do
10 with %User{} = sender_user <- welcome_user(),
11 message when is_binary(message) <- welcome_message() do
12 CommonAPI.post(sender_user, %{
13 visibility: "direct",
14 status: "@#{user.nickname}\n#{message}"
15 })
16 else
17 _ -> {:ok, nil}
18 end
19 end
20
21 defp welcome_user do
22 with nickname when is_binary(nickname) <-
23 Pleroma.Config.get([:instance, :welcome_user_nickname]),
24 %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
25 user
26 else
27 _ -> nil
28 end
29 end
30
31 defp welcome_message do
32 Pleroma.Config.get([:instance, :welcome_message])
33 end
34 end