Merge branch 'safe-mentions' into 'develop'
authorkaniini <nenolod@gmail.com>
Fri, 22 Mar 2019 00:50:24 +0000 (00:50 +0000)
committerkaniini <nenolod@gmail.com>
Fri, 22 Mar 2019 00:50:24 +0000 (00:50 +0000)
Add safe dm mode option.

See merge request pleroma/pleroma!958

1  2 
config/config.exs
docs/config.md
lib/pleroma/web/common_api/utils.ex

diff --combined config/config.exs
index c20802faf67ba87834ea1abb05cafd5d4c1abe76,b01c097c5d014e256dc1eae3553837e564384430..bd8922b772355b5b0cf21ac651bd6486b1042d17
@@@ -8,6 -8,8 +8,6 @@@ use Mix.Confi
  # General application configuration
  config :pleroma, ecto_repos: [Pleroma.Repo]
  
 -config :pleroma, Pleroma.Repo, types: Pleroma.PostgresTypes
 -
  config :pleroma, Pleroma.Captcha,
    enabled: false,
    seconds_valid: 60,
@@@ -172,7 -174,8 +172,8 @@@ config :pleroma, :instance
    no_attachment_links: false,
    welcome_user_nickname: nil,
    welcome_message: nil,
-   max_report_comment_size: 1000
+   max_report_comment_size: 1000,
+   safe_dm_mentions: false
  
  config :pleroma, :markup,
    # XXX - unfortunately, inline images must be enabled by default right now, because
@@@ -271,6 -274,8 +272,6 @@@ config :pleroma, :media_proxy
  
  config :pleroma, :chat, enabled: true
  
 -config :ecto, json_library: Jason
 -
  config :phoenix, :format_encoders, json: Jason
  
  config :pleroma, :gopher,
diff --combined docs/config.md
index 4fa6bd62df3600f5211362f6f29f0a4571ca250a,78967204baa32dcfd715c88d3505a12d3321b789..c1246ee25760ef833ff2f4e5457ee41f69ab552c
@@@ -101,7 -101,8 +101,8 @@@ config :pleroma, Pleroma.Mailer
  * `no_attachment_links`: Set to true to disable automatically adding attachment link text to statuses
  * `welcome_message`: A message that will be send to a newly registered users as a direct message.
  * `welcome_user_nickname`: The nickname of the local user that sends the welcome message.
- * `max_report_size`: The maximum size of the report comment (Default: `1000`)
+ * `max_report_comment_size`: The maximum size of the report comment (Default: `1000`)
+ * `safe_dm_mentions`: If set to true, only mentions at the beginning of a post will be used to address people in direct messages. This is to prevent accidental mentioning of people when talking about them (e.g. "@friend hey i really don't like @enemy"). (Default: `false`)
  
  ## :logger
  * `backends`: `:console` is used to send logs to stdout, `{ExSyslogger, :ex_syslogger}` to log to syslog
@@@ -190,7 -191,6 +191,7 @@@ This section is used to configure Plero
  * `enabled`: Enables the gopher interface
  * `ip`: IP address to bind to
  * `port`: Port to bind to
 +* `dstport`: Port advertised in urls (optional, defaults to `port`)
  
  ## :activitypub
  * ``accept_blocks``: Whether to accept incoming block activities from other instances
index fcdfea8e1eb77f45c4f81d145190b5bdf01e479b,3689454182a37680738fd5d8a5c796046c77a085..3e807a5b74922c6de21b22038f4002671c354cad
@@@ -101,7 -101,8 +101,8 @@@ defmodule Pleroma.Web.CommonAPI.Utils d
    def make_content_html(
          status,
          attachments,
-         data
+         data,
+         visibility
        ) do
      no_attachment_links =
        data
  
      content_type = get_content_type(data["content_type"])
  
+     options =
+       if visibility == "direct" && Config.get([:instance, :safe_dm_mentions]) do
+         [safe_mention: true]
+       else
+         []
+       end
      status
-     |> format_input(content_type)
+     |> format_input(content_type, options)
      |> maybe_add_attachments(attachments, no_attachment_links)
      |> maybe_add_nsfw_tag(data)
    end
    end
  
    def get_report_statuses(_, _), do: {:ok, nil}
 +
 +  # DEPRECATED mostly, context objects are now created at insertion time.
 +  def context_to_conversation_id(context) do
 +    with %Object{id: id} <- Object.get_cached_by_ap_id(context) do
 +      id
 +    else
 +      _e ->
 +        changeset = Object.context_mapping(context)
 +
 +        case Repo.insert(changeset) do
 +          {:ok, %{id: id}} ->
 +            id
 +
 +          # This should be solved by an upsert, but it seems ecto
 +          # has problems accessing the constraint inside the jsonb.
 +          {:error, _} ->
 +            Object.get_cached_by_ap_id(context).id
 +        end
 +    end
 +  end
 +
 +  def conversation_id_to_context(id) do
 +    with %Object{data: %{"id" => context}} <- Repo.get(Object, id) do
 +      context
 +    else
 +      _e ->
 +        {:error, "No such conversation"}
 +    end
 +  end
  end