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.User.WelcomeMessage do
8 alias Pleroma.Web.CommonAPI
10 @spec enabled?() :: boolean()
11 def enabled?, do: Config.get([:welcome, :direct_message, :enabled], false)
13 @spec post_message(User.t()) :: {:ok, Pleroma.Activity.t() | nil}
14 def post_message(user) do
15 [:welcome, :direct_message, :sender_nickname]
18 |> do_post(user, welcome_message())
21 defp do_post(%User{} = sender, %User{nickname: nickname}, message)
22 when is_binary(message) do
27 status: "@#{nickname}\n#{message}"
32 defp do_post(_sender, _recipient, _message), do: {:ok, nil}
34 defp fetch_sender(nickname) when is_binary(nickname) do
35 with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
42 defp fetch_sender(_), do: nil
44 defp welcome_message do
45 Config.get([:welcome, :direct_message, :message], nil)